debian-mirror-gitlab/app/services/incident_management/incidents/create_service.rb

52 lines
1.2 KiB
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
module IncidentManagement
module Incidents
class CreateService < BaseService
ISSUE_TYPE = 'incident'
2020-11-24 15:15:51 +05:30
def initialize(project, current_user, title:, description:, severity: IssuableSeverity::DEFAULT)
2020-10-24 23:57:45 +05:30
super(project, current_user)
@title = title
@description = description
2020-11-24 15:15:51 +05:30
@severity = severity
2020-10-24 23:57:45 +05:30
end
def execute
issue = Issues::CreateService.new(
2021-06-08 01:23:25 +05:30
project: project,
current_user: current_user,
params: {
title: title,
description: description,
issue_type: ISSUE_TYPE
}
2020-10-24 23:57:45 +05:30
).execute
return error(issue.errors.full_messages.to_sentence, issue) unless issue.valid?
2021-01-03 14:25:43 +05:30
update_severity_for(issue)
2020-11-24 15:15:51 +05:30
2020-10-24 23:57:45 +05:30
success(issue)
end
private
2020-11-24 15:15:51 +05:30
attr_reader :title, :description, :severity
2020-10-24 23:57:45 +05:30
def success(issue)
ServiceResponse.success(payload: { issue: issue })
end
def error(message, issue = nil)
ServiceResponse.error(payload: { issue: issue }, message: message)
end
2021-01-03 14:25:43 +05:30
def update_severity_for(issue)
::IncidentManagement::Incidents::UpdateSeverityService.new(issue, current_user, severity).execute
end
2020-10-24 23:57:45 +05:30
end
end
end