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
|
# frozen_string_literal: true
module IncidentManagement
module Incidents
class CreateService < ::BaseProjectService
ISSUE_TYPE = 'incident'
def initialize(project, current_user, title:, description:, severity: IssuableSeverity::DEFAULT, alert: nil)
super(project: project, current_user: current_user)
@title = title
@description = description
@severity = severity
@alert = alert
end
def execute
create_result = Issues::CreateService.new(
container: project,
current_user: current_user,
params: {
title: title,
description: description,
issue_type: ISSUE_TYPE,
severity: severity,
alert_management_alerts: [alert].compact
},
spam_params: nil
).execute
if alert
return error(alert.errors.full_messages, create_result[:issue]) unless alert.valid?
end
create_result
end
private
attr_reader :title, :description, :severity, :alert
def error(message, issue = nil)
ServiceResponse.error(payload: { issue: issue }, message: message)
end
end
end
end
|