Commit 509fadc5 authored by Marc Shaw's avatar Marc Shaw

Merge branch '340852-populate-incident-metric-images-from-alert' into 'master'

Copy metric images from alert to new incident

See merge request gitlab-org/gitlab!79703
parents 5d76d004 972338b2
......@@ -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.find_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_with_reload(:alert) { create(:alert_management_alert, project: project) }
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)
image_2 = create(:alert_metric_image, alert: alert)
incident = execute.payload[:issue]
expect(incident.metric_images.count).to eq(2)
first_metric_image, second_metric_image = incident.metric_images.order(:created_at)
expect_image_matches(first_metric_image, image)
expect_image_matches(second_metric_image, image_2)
end
context 'when there are no metric images to copy' do
it 'has no images' do
incident = execute.payload[:issue]
expect(incident.metric_images.count).to eq(0)
end
end
private
def expect_image_matches(image, image_expectation)
expect(image.url).to eq(image_expectation.url)
expect(image.url_text).to eq(image_expectation.url_text)
expect(image.filename).to eq(image_expectation.filename)
expect(image.file).not_to eq(image_expectation.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