diff options
author | Reuben Pereira <rpereira@gitlab.com> | 2019-02-06 18:07:26 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-02-06 18:07:26 +0300 |
commit | ef807a2ecaa6841baa3b38d48f09df59823582f0 (patch) | |
tree | f0f44241f29a25b953d3ea91042916bbe905126f /app/services/error_tracking | |
parent | c1758be160084c5277e6057896ac9aad2811edec (diff) |
Add service to get sentry projects list
Diffstat (limited to 'app/services/error_tracking')
-rw-r--r-- | app/services/error_tracking/list_projects_service.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/app/services/error_tracking/list_projects_service.rb b/app/services/error_tracking/list_projects_service.rb new file mode 100644 index 00000000000..c6e8be0f2be --- /dev/null +++ b/app/services/error_tracking/list_projects_service.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +module ErrorTracking + class ListProjectsService < ::BaseService + def execute + return error('access denied') unless can_read? + + setting = project_error_tracking_setting + + unless setting.valid? + return error(setting.errors.full_messages.join(', '), :bad_request) + end + + begin + result = setting.list_sentry_projects + rescue Sentry::Client::Error => e + return error(e.message, :bad_request) + rescue Sentry::Client::SentryError => e + return error(e.message, :unprocessable_entity) + end + + success(projects: result[:projects]) + end + + private + + def project_error_tracking_setting + (project.error_tracking_setting || project.build_error_tracking_setting).tap do |setting| + setting.api_url = ErrorTracking::ProjectErrorTrackingSetting.build_api_url_from( + api_host: params[:api_host], + organization_slug: nil, + project_slug: nil + ) + + setting.token = params[:token] + setting.enabled = true + end + end + + def can_read? + can?(current_user, :read_sentry_issue, project) + end + end +end |