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

48 lines
1.1 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,
2021-09-30 23:02:18 +05:30
issue_type: ISSUE_TYPE,
severity: severity
},
spam_params: nil
2020-10-24 23:57:45 +05:30
).execute
return error(issue.errors.full_messages.to_sentence, issue) unless issue.valid?
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
end
end
end