summaryrefslogtreecommitdiff
path: root/lib/api/error_tracking.rb
blob: 3abf2831bd38658a61548bdd3975313fb1361afc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true

module API
  class ErrorTracking < ::API::Base
    before { authenticate! }

    feature_category :error_tracking

    params do
      requires :id, type: String, desc: 'The ID of a project'
    end

    resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
      desc 'Get error tracking settings for the project' do
        detail 'This feature was introduced in GitLab 12.7.'
        success Entities::ErrorTracking::ProjectSetting
      end

      get ':id/error_tracking/settings' do
        authorize! :admin_operations, user_project

        setting = user_project.error_tracking_setting

        not_found!('Error Tracking Setting') unless setting

        present setting, with: Entities::ErrorTracking::ProjectSetting
      end

      desc 'Enable or disable error tracking settings for the project' do
        detail 'This feature was introduced in GitLab 12.8.'
        success Entities::ErrorTracking::ProjectSetting
      end
      params do
        requires :active, type: Boolean, desc: 'Specifying whether to enable or disable error tracking settings', allow_blank: false
        optional :integrated, type: Boolean, desc: 'Specifying whether to enable or disable integrated error tracking'
      end

      patch ':id/error_tracking/settings/' do
        authorize! :admin_operations, user_project

        setting = user_project.error_tracking_setting

        not_found!('Error Tracking Setting') unless setting

        update_params = {
          error_tracking_setting_attributes: { enabled: params[:active] }
        }

        unless params[:integrated].nil?
          update_params[:error_tracking_setting_attributes][:integrated] = params[:integrated]
        end

        result = ::Projects::Operations::UpdateService.new(user_project, current_user, update_params).execute

        if result[:status] == :success
          present setting, with: Entities::ErrorTracking::ProjectSetting
        else
          result
        end
      end
    end
  end
end