Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils/github: paginate artifact API result #17138

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@
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
4 changes: 2 additions & 2 deletions Library/Homebrew/utils/github/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@
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|
retry_count = 1
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:)

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

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/github/api.rb#L291

Added line #L291 was not covered by tests
rescue Error
if retry_count < PAGINATE_RETRY_COUNT
retry_count += 1
Expand Down