From c9e6b81b4b505e59b24a6286323573c426bc3010 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Tue, 21 Feb 2023 11:06:30 +0000 Subject: [PATCH] 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. --- Library/Homebrew/utils/github.rb | 2 +- Library/Homebrew/utils/github/api.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 373632a42d..9c31adfbd9 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -704,7 +704,7 @@ module GitHub # rubocop:disable Metrics/ModuleLength return if Homebrew::EnvConfig.no_github_api? 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 end commits diff --git a/Library/Homebrew/utils/github/api.rb b/Library/Homebrew/utils/github/api.rb index a9019480ab..2dd8bfe408 100644 --- a/Library/Homebrew/utils/github/api.rb +++ b/Library/Homebrew/utils/github/api.rb @@ -253,9 +253,9 @@ module GitHub 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| - 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) end end