Commit 5f62b91f authored by Sean Arnold's avatar Sean Arnold

Copy metric images from alert to new incident

When an incident is created from an alert, any metric images already on the
alert will be duplicated and saved against the incident.

Changelog: added
EE: true
parent d60b02c8
......@@ -22,9 +22,7 @@ module AlertManagement
return result unless result.success?
issue = result.payload[:issue]
update_title_for(issue)
SystemNoteService.new_alert_issue(alert, issue, user)
perform_after_create_tasks(issue)
result
end
......@@ -56,6 +54,12 @@ module AlertManagement
issue.update!(title: "#{DEFAULT_INCIDENT_TITLE} #{issue.iid}")
end
def perform_after_create_tasks(issue)
update_title_for(issue)
SystemNoteService.new_alert_issue(alert, issue, user)
end
def error(message, issue = nil)
ServiceResponse.error(payload: { issue: issue }, message: message)
end
......@@ -75,3 +79,5 @@ module AlertManagement
end
end
end
AlertManagement::CreateAlertIssueService.prepend_mod
# frozen_string_literal: true
module EE
module AlertManagement
module CreateAlertIssueService
extend ::Gitlab::Utils::Override
override :perform_after_create_tasks
def perform_after_create_tasks(issue)
super
copy_metric_images_to(issue)
end
private
def copy_metric_images_to(issue)
alert.metric_images.each do |img|
::IncidentManagement::Incidents::UploadMetricService
.new(issue, user, { file: img.file, url: img.url, url_text: img.url_text })
.execute
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe AlertManagement::CreateAlertIssueService do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:alert) { create(:alert_management_alert, project: project) }
let(:created_issue) { Issue.last! }
describe '#execute' do
subject(:execute) { described_class.new(alert, user).execute }
before do
project.add_developer(user)
stub_licensed_features(incident_metric_upload: true)
end
it 'copies any metric images' do
image = create(:alert_metric_image, alert: alert)
execute
incident = Issue.incident.last
expect(incident.metric_images.count).to eq(1)
metric_image = incident.metric_images.first
expect(metric_image.url).to eq(image.url)
expect(metric_image.url_text).to eq(image.url_text)
expect(metric_image.filename).to eq(image.filename)
expect(metric_image.file).not_to eq(image.file)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment