summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/alert_management/create_alert_issue.rb
blob: 7c8de6365e7a882c2d60b19ec243d1e7e2f96b51 (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
# frozen_string_literal: true

module Mutations
  module AlertManagement
    class CreateAlertIssue < Base
      graphql_name 'CreateAlertIssue'

      def resolve(args)
        alert = authorized_find!(project_path: args[:project_path], iid: args[:iid])
        result = create_alert_issue(alert, current_user)

        track_alert_events('incident_management_incident_created', alert)
        track_usage_event(:incident_management_alert_create_incident, current_user.id)

        prepare_response(alert, result)
      end

      private

      def create_alert_issue(alert, user)
        ::AlertManagement::CreateAlertIssueService.new(alert, user).execute
      end

      def prepare_response(alert, result)
        {
          alert: alert,
          issue: result[:issue],
          errors: result.errors
        }
      end
    end
  end
end