diff options
Diffstat (limited to 'lib/bulk_imports/clients')
-rw-r--r-- | lib/bulk_imports/clients/http.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/bulk_imports/clients/http.rb b/lib/bulk_imports/clients/http.rb index 39f56fcc114..2e81863e53a 100644 --- a/lib/bulk_imports/clients/http.rb +++ b/lib/bulk_imports/clients/http.rb @@ -18,7 +18,7 @@ module BulkImports end def get(resource, query = {}) - response = with_error_handling do + with_error_handling do Gitlab::HTTP.get( resource_url(resource), headers: request_headers, @@ -26,8 +26,22 @@ module BulkImports query: query.merge(request_query) ) end + end + + def each_page(method, resource, query = {}, &block) + return to_enum(__method__, method, resource, query) unless block_given? + + next_page = @page - response.parsed_response + while next_page + @page = next_page.to_i + + response = self.public_send(method, resource, query) # rubocop: disable GitlabSecurity/PublicSend + collection = response.parsed_response + next_page = response.headers['x-next-page'].presence + + yield collection + end end private |