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(
|
|
|
|
project,
|
|
|
|
current_user,
|
|
|
|
title: title,
|
|
|
|
description: description,
|
|
|
|
issue_type: ISSUE_TYPE
|
|
|
|
).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
|