Skip to content

Commit

Permalink
utils/github: paginate artifact API result
Browse files Browse the repository at this point in the history
There can be too many artifacts in a workflow run to fit in a single API
response, so we need to paginate the result.
  • Loading branch information
ZhongRuoyu committed Apr 23, 2024
1 parent f4f8a12 commit 84abc62
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Library/Homebrew/utils/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,17 @@ def self.get_artifact_urls(workflow_array)
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",

Check warning on line 360 in Library/Homebrew/utils/github.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/github.rb#L358-L360

Added lines #L358 - L360 were not covered by tests
per_page:, scopes:) do |result|
result = result["artifacts"]
artifacts.concat(result)

Check warning on line 363 in Library/Homebrew/utils/github.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/github.rb#L362-L363

Added lines #L362 - L363 were not covered by tests
break if result.length < per_page
end

matching_artifacts =
artifacts["artifacts"]
artifacts

Check warning on line 368 in Library/Homebrew/utils/github.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/github.rb#L368

Added line #L368 was not covered by tests
.group_by { |art| art["name"] }
.select { |name| File.fnmatch?(artifact_pattern, name, File::FNM_EXTGLOB) }
.map { |_, arts| arts.last }
Expand Down

0 comments on commit 84abc62

Please sign in to comment.