Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'qa/qa/support/api.rb')
-rw-r--r--qa/qa/support/api.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/qa/qa/support/api.rb b/qa/qa/support/api.rb
index 3c46c039eae..08faacb6db3 100644
--- a/qa/qa/support/api.rb
+++ b/qa/qa/support/api.rb
@@ -77,6 +77,30 @@ module QA
error.response
end
+
+ def with_paginated_response_body(url)
+ loop do
+ response = get(url)
+
+ QA::Runtime::Logger.debug("Fetching page #{response.headers[:x_page]} of #{response.headers[:x_total_pages]}...")
+
+ yield parse_body(response)
+
+ next_link = pagination_links(response).find { |link| link[:rel] == 'next' }
+ break unless next_link
+
+ url = next_link[:url]
+ end
+ end
+
+ def pagination_links(response)
+ response.headers[:link].split(',').map do |link|
+ match = link.match(/\<(?<url>.*)\>\; rel=\"(?<rel>\w+)\"/)
+ break nil unless match
+
+ { url: match[:url], rel: match[:rel] }
+ end.compact
+ end
end
end
end