diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /qa/qa/support/api.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) | |
download | gitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'qa/qa/support/api.rb')
-rw-r--r-- | qa/qa/support/api.rb | 24 |
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 |