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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 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
2022-04-04 11:22:00 +05:30
class CreateService < ::BaseProjectService
2020-10-24 23:57:45 +05:30
ISSUE_TYPE = 'incident'
2022-04-04 11:22:00 +05:30
def initialize(project, current_user, title:, description:, severity: IssuableSeverity::DEFAULT, alert: nil)
super(project: project, current_user: current_user)
2020-10-24 23:57:45 +05:30
@title = title
@description = description
2020-11-24 15:15:51 +05:30
@severity = severity
2022-04-04 11:22:00 +05:30
@alert = alert
2020-10-24 23:57:45 +05:30
end
def execute
2022-11-25 23:54:43 +05:30
create_result = 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,
2022-04-04 11:22:00 +05:30
severity: severity,
alert_management_alert: alert
2021-09-30 23:02:18 +05:30
},
spam_params: nil
2020-10-24 23:57:45 +05:30
).execute
2022-04-04 11:22:00 +05:30
if alert
2022-11-25 23:54:43 +05:30
return error(alert.errors.full_messages, create_result[:issue]) unless alert.valid?
2022-04-04 11:22:00 +05:30
end
2022-11-25 23:54:43 +05:30
create_result
2020-10-24 23:57:45 +05:30
end
private
2022-04-04 11:22:00 +05:30
attr_reader :title, :description, :severity, :alert
2020-10-24 23:57:45 +05:30
def error(message, issue = nil)
ServiceResponse.error(payload: { issue: issue }, message: message)
end
end
end
end