Commit 1ebbf2cb authored by Vitali Tatarintev's avatar Vitali Tatarintev

Add IID to a generic alert issue title

https://gitlab.com/gitlab-org/gitlab/issues/34687
parent 7f936a16
...@@ -33,6 +33,8 @@ module EE ...@@ -33,6 +33,8 @@ module EE
has_many :prometheus_alerts, through: :prometheus_alert_events has_many :prometheus_alerts, through: :prometheus_alert_events
validates :weight, allow_nil: true, numericality: { greater_than_or_equal_to: 0 } validates :weight, allow_nil: true, numericality: { greater_than_or_equal_to: 0 }
after_create :update_generic_alert_issue_if_applicable
end end
class_methods do class_methods do
...@@ -129,5 +131,26 @@ module EE ...@@ -129,5 +131,26 @@ module EE
[WEIGHT_NONE] + WEIGHT_RANGE.to_a [WEIGHT_NONE] + WEIGHT_RANGE.to_a
end end
end end
private
def update_generic_alert_issue_if_applicable
return unless has_default_generic_alert_title? && alerts_service_activated?
update_column(:title, "#{title} #{id}")
end
def has_default_generic_alert_title?
title == ::Gitlab::Alerting::NotificationPayloadParser::DEFAULT_TITLE
end
def incident_management_available?
project.feature_available?(:incident_management)
end
def alerts_service_activated?
incident_management_available? &&
project.alerts_service.try(:active?)
end
end end
end end
...@@ -7,6 +7,56 @@ describe Issue do ...@@ -7,6 +7,56 @@ describe Issue do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
context 'callbacks' do
describe '.after_create' do
set(:project) { create(:project) }
context 'when issue title is "New: Incident"' do
let(:issue) { build(:issue, project: project, title: 'New: Incident') }
context 'when incident management available' do
before do
stub_licensed_features(incident_management: true)
end
context 'when alerts service is active' do
let!(:alerts_service) { create(:alerts_service, project: project) }
it 'updates issue title with the IID' do
issue.save
expect(issue.reload.title).to eq("New: Incident #{issue.id}")
end
end
context 'when alerts service is not active' do
it 'does not change issue title' do
expect { issue.save }.not_to change { issue.title }
end
end
end
context 'when incident management is not available' do
before do
stub_licensed_features(incident_management: false)
end
it 'does not change issue title' do
expect { issue.save }.not_to change { issue.title }
end
end
end
context 'when issue title is not "New: Incident"' do
let(:issue) { build(:issue, project: project, title: 'Not New: Incident') }
it 'does not change issue title' do
expect { issue.save }.not_to change { issue.title }
end
end
end
end
context 'scopes' do context 'scopes' do
describe '.service_desk' do describe '.service_desk' do
it 'returns the service desk issue' do it 'returns the service desk issue' do
......
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