Merge pull request #17138 from Homebrew/artifacts-pagination
utils/github: paginate artifact API result
This commit is contained in:
commit
04fc95bfdb
@ -355,10 +355,17 @@ module GitHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
run_id = check_suite.last["workflowRun"]["databaseId"]
|
run_id = check_suite.last["workflowRun"]["databaseId"]
|
||||||
artifacts = API.open_rest("#{API_URL}/repos/#{user}/#{repo}/actions/runs/#{run_id}/artifacts", scopes:)
|
artifacts = []
|
||||||
|
per_page = 50
|
||||||
|
API.paginate_rest("#{API_URL}/repos/#{user}/#{repo}/actions/runs/#{run_id}/artifacts",
|
||||||
|
per_page:, scopes:) do |result|
|
||||||
|
result = result["artifacts"]
|
||||||
|
artifacts.concat(result)
|
||||||
|
break if result.length < per_page
|
||||||
|
end
|
||||||
|
|
||||||
matching_artifacts =
|
matching_artifacts =
|
||||||
artifacts["artifacts"]
|
artifacts
|
||||||
.group_by { |art| art["name"] }
|
.group_by { |art| art["name"] }
|
||||||
.select { |name| File.fnmatch?(artifact_pattern, name, File::FNM_EXTGLOB) }
|
.select { |name| File.fnmatch?(artifact_pattern, name, File::FNM_EXTGLOB) }
|
||||||
.map { |_, arts| arts.last }
|
.map { |_, arts| arts.last }
|
||||||
|
|||||||
@ -284,11 +284,11 @@ module GitHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.paginate_rest(url, additional_query_params: nil, per_page: 100)
|
def self.paginate_rest(url, additional_query_params: nil, per_page: 100, scopes: [].freeze)
|
||||||
(1..API_MAX_PAGES).each do |page|
|
(1..API_MAX_PAGES).each do |page|
|
||||||
retry_count = 1
|
retry_count = 1
|
||||||
result = begin
|
result = begin
|
||||||
API.open_rest("#{url}?per_page=#{per_page}&page=#{page}&#{additional_query_params}")
|
API.open_rest("#{url}?per_page=#{per_page}&page=#{page}&#{additional_query_params}", scopes:)
|
||||||
rescue Error
|
rescue Error
|
||||||
if retry_count < PAGINATE_RETRY_COUNT
|
if retry_count < PAGINATE_RETRY_COUNT
|
||||||
retry_count += 1
|
retry_count += 1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user