Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/incident_management/incidents/create_service.rb')
-rw-r--r--app/services/incident_management/incidents/create_service.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/app/services/incident_management/incidents/create_service.rb b/app/services/incident_management/incidents/create_service.rb
new file mode 100644
index 00000000000..7206eaf51b2
--- /dev/null
+++ b/app/services/incident_management/incidents/create_service.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+module IncidentManagement
+ module Incidents
+ class CreateService < BaseService
+ ISSUE_TYPE = 'incident'
+
+ def initialize(project, current_user, title:, description:)
+ super(project, current_user)
+
+ @title = title
+ @description = description
+ end
+
+ def execute
+ issue = Issues::CreateService.new(
+ project,
+ current_user,
+ title: title,
+ description: description,
+ label_ids: [find_or_create_incident_label.id],
+ issue_type: ISSUE_TYPE
+ ).execute
+
+ return error(issue.errors.full_messages.to_sentence, issue) unless issue.valid?
+
+ success(issue)
+ end
+
+ private
+
+ attr_reader :title, :description
+
+ def find_or_create_incident_label
+ IncidentManagement::CreateIncidentLabelService
+ .new(project, current_user)
+ .execute
+ .payload[:label]
+ end
+
+ def success(issue)
+ ServiceResponse.success(payload: { issue: issue })
+ end
+
+ def error(message, issue = nil)
+ ServiceResponse.error(payload: { issue: issue }, message: message)
+ end
+ end
+ end
+end