Class: IncidentManagement::Incidents::CreateService

Inherits:
BaseProjectService show all
Defined in:
app/services/incident_management/incidents/create_service.rb

Constant Summary collapse

ISSUE_TYPE =
'incident'

Instance Attribute Summary

Attributes inherited from BaseProjectService

#project

Attributes inherited from BaseContainerService

#container, #current_user, #group, #params, #project

Instance Method Summary collapse

Methods inherited from BaseContainerService

#group_container?, #namespace_container?, #project_container?, #project_group

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(project, current_user, title:, description:, severity: IssuableSeverity::DEFAULT, alert: nil) ⇒ CreateService

Returns a new instance of CreateService.



8
9
10
11
12
13
14
15
# File 'app/services/incident_management/incidents/create_service.rb', line 8

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

Instance Method Details

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/incident_management/incidents/create_service.rb', line 17

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
    },
    perform_spam_check: false
  ).execute

  if alert
    return error(alert.errors.full_messages, create_result[:issue]) unless alert.valid?
  end

  create_result
end