utils/github: paginate artifact API result

There can be too many artifacts in a workflow run to fit in a single API
response, so we need to paginate the result.
This commit is contained in:
Ruoyu Zhong 2024-04-24 04:07:25 +08:00
parent f4f8a12509
commit 84abc628aa
No known key found for this signature in database

View File

@ -355,10 +355,17 @@ module GitHub
end
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 =
artifacts["artifacts"]
artifacts
.group_by { |art| art["name"] }
.select { |name| File.fnmatch?(artifact_pattern, name, File::FNM_EXTGLOB) }
.map { |_, arts| arts.last }