diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /app/services/incident_management/incidents/create_service.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'app/services/incident_management/incidents/create_service.rb')
-rw-r--r-- | app/services/incident_management/incidents/create_service.rb | 50 |
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 |