Commit ddfc8244 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'add-issue-id-to-generic-alert-title' into 'master'

Add issue IID to generic alert title

Closes #34687

See merge request gitlab-org/gitlab!19086
parents 8b8c5984 ff85a006
......@@ -33,6 +33,8 @@ module EE
has_many :prometheus_alerts, through: :prometheus_alert_events
validates :weight, allow_nil: true, numericality: { greater_than_or_equal_to: 0 }
after_create :update_generic_alert_title, if: :generic_alert_with_default_title?
end
class_methods do
......@@ -129,5 +131,17 @@ module EE
[WEIGHT_NONE] + WEIGHT_RANGE.to_a
end
end
private
def update_generic_alert_title
update(title: "#{title} #{iid}")
end
def generic_alert_with_default_title?
title == ::Gitlab::Alerting::NotificationPayloadParser::DEFAULT_TITLE &&
project.alerts_service_activated? &&
author == ::User.alert_bot
end
end
end
......@@ -643,6 +643,10 @@ module EE
feature_available?(:incident_management)
end
def alerts_service_activated?
alerts_service_available? && alerts_service&.active?
end
def package_already_taken?(package_name)
namespace.root_ancestor.all_projects
.joins(:packages)
......
......@@ -18,16 +18,7 @@ module Projects
private
delegate :alerts_service, to: :project
def incident_management_available?
project.feature_available?(:incident_management)
end
def alerts_service_activated?
incident_management_available? &&
alerts_service.try(:active?)
end
delegate :alerts_service, :alerts_service_activated?, to: :project
def process_incident_issues
IncidentManagement::ProcessAlertWorker
......
---
title: Add issue IID to a title of generic alerts with a default title
merge_request: 19086
author:
type: added
......@@ -7,6 +7,55 @@ describe Issue do
using RSpec::Parameterized::TableSyntax
context 'callbacks' do
describe '.after_create' do
set(:project) { create(:project) }
let(:author) { User.alert_bot }
context 'when issue title is "New: Incident"' do
let(:issue) { build(:issue, project: project, author: author, title: 'New: Incident', iid: 503503) }
context 'when alerts service is active' do
before do
allow(project).to receive(:alerts_service_activated?).and_return(true)
end
context 'when the author is Alert Bot' do
it 'updates issue title with the IID' do
expect { issue.save }.to change { issue.title }.to("New: Incident 503503")
end
end
context 'when the author is not an Alert Bot' do
let(:author) { create(:user) }
it 'does not change issue title' do
expect { issue.save }.not_to change { issue.title }
end
end
end
context 'when alerts service is not active' do
before do
allow(project).to receive(:alerts_service_activated?).and_return(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
describe '.service_desk' do
it 'returns the service desk issue' do
......
......@@ -1107,6 +1107,42 @@ describe Project do
end
end
describe '#alerts_service_activated?' do
let!(:project) { create(:project) }
subject { project.alerts_service_activated? }
context 'when incident management feature available' do
before do
stub_licensed_features(incident_management: true)
end
context 'when project has an activated alerts service' do
before do
create(:alerts_service, project: project)
end
it { is_expected.to be_truthy }
end
context 'when project has an inactive alerts service' do
before do
create(:alerts_service, :inactive, project: project)
end
it { is_expected.to be_falsey }
end
end
context 'when incident feature is not available' do
before do
stub_licensed_features(incident_management: false)
end
it { is_expected.to be_falsey }
end
end
describe '#disabled_services' do
let(:project) { build(:project) }
......
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