utils/github: API.paginate_rest handles extra query params

- Functionally it doesn't matter that the URL will have an `&` at the
  end if `additional_query_params` is `nil`, because it doesn't affect
  the URL at all.
This commit is contained in:
Issy Long 2023-02-21 11:06:30 +00:00
parent 0a6c59c0b3
commit c9e6b81b4b
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
2 changed files with 3 additions and 3 deletions

View File

@ -704,7 +704,7 @@ module GitHub # rubocop:disable Metrics/ModuleLength
return if Homebrew::EnvConfig.no_github_api? return if Homebrew::EnvConfig.no_github_api?
commits = 0 commits = 0
API.paginate_rest("#{API_URL}/repos/#{nwo}/commits", query: "&author=#{user}") do |result| API.paginate_rest("#{API_URL}/repos/#{nwo}/commits", additional_query_params: "author=#{user}") do |result|
commits += result.length commits += result.length
end end
commits commits

View File

@ -253,9 +253,9 @@ module GitHub
end end
end end
def paginate_rest(url, query: nil, per_page: 100) def paginate_rest(url, additional_query_params: nil, per_page: 100)
(1..API_MAX_PAGES).each do |page| (1..API_MAX_PAGES).each do |page|
result = API.open_rest("#{url}?per_page=#{per_page}&page=#{page}#{query}") result = API.open_rest("#{url}?per_page=#{per_page}&page=#{page}&#{additional_query_params}")
yield(result, page) yield(result, page)
end end
end end