diff options
author | Reuben Pereira <rpereira@gitlab.com> | 2019-01-31 10:05:29 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-01-31 10:05:29 +0000 |
commit | 5841a7d5efe772a9a8f09144b84fcb9aee906c4c (patch) | |
tree | e966d385aea7c9a669ef7cd6d77a8874c14bb5de /lib/sentry | |
parent | ab8b77a87c99a5b83050e2e9d588d4940288d754 (diff) | |
download | gitlab-ce-5841a7d5efe772a9a8f09144b84fcb9aee906c4c.tar.gz |
Update Sentry client to get project list
Diffstat (limited to 'lib/sentry')
-rw-r--r-- | lib/sentry/client.rb | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/lib/sentry/client.rb b/lib/sentry/client.rb index 343f2c49a7f..4187014d49e 100644 --- a/lib/sentry/client.rb +++ b/lib/sentry/client.rb @@ -3,6 +3,7 @@ module Sentry class Client Error = Class.new(StandardError) + SentryError = Class.new(StandardError) attr_accessor :url, :token @@ -16,6 +17,13 @@ module Sentry map_to_errors(issues) end + def list_projects + projects = get_projects + map_to_projects(projects) + rescue KeyError => e + raise Client::SentryError, "Sentry API response is missing keys. #{e.message}" + end + private def request_params @@ -27,18 +35,23 @@ module Sentry } end - def get_issues(issue_status:, limit:) - resp = Gitlab::HTTP.get( - issues_api_url, - **request_params.merge(query: { - query: "is:#{issue_status}", - limit: limit - }) - ) + def http_get(url, params = {}) + resp = Gitlab::HTTP.get(url, **request_params.merge(params)) handle_response(resp) end + def get_issues(issue_status:, limit:) + http_get(issues_api_url, query: { + query: "is:#{issue_status}", + limit: limit + }) + end + + def get_projects + http_get(projects_api_url) + end + def handle_response(response) unless response.code == 200 raise Client::Error, "Sentry response error: #{response.code}" @@ -47,6 +60,13 @@ module Sentry response.as_json end + def projects_api_url + projects_url = URI(@url) + projects_url.path = '/api/0/projects/' + + projects_url + end + def issues_api_url issues_url = URI(@url + '/issues/') issues_url.path.squeeze!('/') @@ -55,9 +75,11 @@ module Sentry end def map_to_errors(issues) - issues.map do |issue| - map_to_error(issue) - end + issues.map(&method(:map_to_error)) + end + + def map_to_projects(projects) + projects.map(&method(:map_to_project)) end def issue_url(id) @@ -100,5 +122,19 @@ module Sentry project_slug: project.fetch('slug', nil) ) end + + def map_to_project(project) + organization = project.fetch('organization') + + Gitlab::ErrorTracking::Project.new( + id: project.fetch('id'), + name: project.fetch('name'), + slug: project.fetch('slug'), + status: project.dig('status'), + organization_name: organization.fetch('name'), + organization_id: organization.fetch('id'), + organization_slug: organization.fetch('slug') + ) + end end end |