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, #params

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from BaseContainerService

#group_container?, #namespace_container?, #project_container?

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
37
38
# File 'app/services/incident_management/incidents/create_service.rb', line 17

def execute
  issue = Issues::CreateService.new(
    project: project,
    current_user: current_user,
    params: {
      title: title,
      description: description,
      issue_type: ISSUE_TYPE,
      severity: severity,
      alert_management_alert: alert
    },
    spam_params: nil
  ).execute

  if alert
    return error(alert.errors.full_messages.to_sentence, issue) unless alert.valid?
  end

  return error(issue.errors.full_messages.to_sentence, issue) unless issue.valid?

  success(issue)
end