diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-02 15:06:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-02 15:06:45 +0300 |
commit | bffcdf9bca11a4d43cc40e3f382f03088d36f7c6 (patch) | |
tree | c773436393b7a59b5f6b14388b9fa6402a9bd198 /lib/sentry | |
parent | 259c0cc0c4f8a49001b33d1bee577f4422e16d62 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/sentry')
-rw-r--r-- | lib/sentry/client.rb | 36 | ||||
-rw-r--r-- | lib/sentry/pagination_parser.rb | 23 |
2 files changed, 46 insertions, 13 deletions
diff --git a/lib/sentry/client.rb b/lib/sentry/client.rb index 3aa3eb45d85..708ace53f5b 100644 --- a/lib/sentry/client.rb +++ b/lib/sentry/client.rb @@ -34,12 +34,18 @@ module Sentry end def list_issues(**keyword_args) - issues = get_issues(keyword_args) + response = get_issues(keyword_args) + + issues = response[:issues] + pagination = response[:pagination] validate_size(issues) handle_mapping_exceptions do - map_to_errors(issues) + { + issues: map_to_errors(issues), + pagination: pagination + } end end @@ -83,36 +89,40 @@ module Sentry end def get_issues(**keyword_args) - http_get( + response = http_get( issues_api_url, query: list_issue_sentry_query(keyword_args) ) + + { + issues: response[:body], + pagination: Sentry::PaginationParser.parse(response[:headers]) + } end - def list_issue_sentry_query(issue_status:, limit:, sort: nil, search_term: '') + def list_issue_sentry_query(issue_status:, limit:, sort: nil, search_term: '', cursor: nil) unless SENTRY_API_SORT_VALUE_MAP.key?(sort) raise BadRequestError, 'Invalid value for sort param' end - query_params = { + { query: "is:#{issue_status} #{search_term}".strip, limit: limit, - sort: SENTRY_API_SORT_VALUE_MAP[sort] - } - - query_params.compact + sort: SENTRY_API_SORT_VALUE_MAP[sort], + cursor: cursor + }.compact end def get_issue(issue_id:) - http_get(issue_api_url(issue_id)) + http_get(issue_api_url(issue_id))[:body] end def get_issue_latest_event(issue_id:) - http_get(issue_latest_event_api_url(issue_id)) + http_get(issue_latest_event_api_url(issue_id))[:body] end def get_projects - http_get(projects_api_url) + http_get(projects_api_url)[:body] end def handle_request_exceptions @@ -138,7 +148,7 @@ module Sentry raise_error "Sentry response status code: #{response.code}" end - response.parsed_response + { body: response.parsed_response, headers: response.headers } end def raise_error(message) diff --git a/lib/sentry/pagination_parser.rb b/lib/sentry/pagination_parser.rb new file mode 100644 index 00000000000..fa9c1dd8694 --- /dev/null +++ b/lib/sentry/pagination_parser.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Sentry + module PaginationParser + PATTERN = /rel=\"(?<direction>\w+)\";\sresults=\"(?<results>\w+)\";\scursor=\"(?<cursor>.+)\"/.freeze + + def self.parse(headers) + links = headers['link'].to_s.split(',') + + links.map { |link| parse_link(link) }.compact.to_h + end + + def self.parse_link(link) + match = link.match(PATTERN) + + return unless match + return if match['results'] != "true" + + [match['direction'], { 'cursor' => match['cursor'] }] + end + private_class_method :parse_link + end +end |