Commit aca610b8 authored by Sean Arnold's avatar Sean Arnold

Fallback to using schedule in text

- Rename method to notify_via_escalation
parent 6bd709f4
......@@ -28,7 +28,7 @@ module IncidentManagement
validates :rule_id, presence: true, uniqueness: { scope: [:alert_id] }
delegate :project, to: :alert
delegate :policy, to: :rule
delegate :policy, to: :rule, allow_nil: true
end
end
end
......@@ -112,8 +112,8 @@ module EE
issuables_service(noteable, project, author).publish_issue_to_status_page
end
def alert_via_escalation(noteable, project, recipients, escalation_policy)
escalations_service(noteable, project).alert_via_escalation(recipients, escalation_policy)
def notify_via_escalation(noteable, project, recipients, escalation_policy, oncall_schedule)
escalations_service(noteable, project).notify_via_escalation(recipients, escalation_policy, oncall_schedule)
end
private
......
......@@ -49,7 +49,7 @@ module IncidentManagement
end
def create_system_notes
SystemNoteService.alert_via_escalation(target, project, oncall_notification_recipients, escalation.policy)
SystemNoteService.notify_via_escalation(target, project, oncall_notification_recipients, escalation.policy, oncall_schedule)
end
def oncall_notification_recipients
......
......@@ -8,8 +8,12 @@ module SystemNotes
@author = User.alert_bot
end
def alert_via_escalation(recipients, escalation_policy)
body = "notified #{recipients.map(&:to_reference).to_sentence} of this alert via escalation policy **#{escalation_policy.name}**"
def notify_via_escalation(recipients, escalation_policy, oncall_schedule)
body = if escalation_policy
"notified #{recipients.map(&:to_reference).to_sentence} of this alert via escalation policy **#{escalation_policy.name}**"
else
"notified #{recipients.map(&:to_reference).to_sentence} of this alert via schedule **#{oncall_schedule.name}**, per an escalation rule which no longer exists"
end
create_note(NoteSummary.new(noteable, project, author, body, action: 'new_alert_added'))
end
......
......@@ -11,6 +11,7 @@ RSpec.describe IncidentManagement::PendingEscalations::Alert do
it { is_expected.to validate_presence_of(:process_at) }
it { is_expected.to validate_presence_of(:status) }
it { is_expected.to delegate_method(:project).to(:alert) }
it { is_expected.to delegate_method(:policy).to(:rule).allow_nil }
it { is_expected.to validate_uniqueness_of(:rule_id).scoped_to([:alert_id]) }
end
......
......@@ -51,7 +51,7 @@ RSpec.describe IncidentManagement::PendingEscalations::ProcessService do
it 'creates a system note' do
expect(SystemNoteService)
.to receive(:alert_via_escalation).with(alert, project, [a_kind_of(User)], escalation_policy)
.to receive(:notify_via_escalation).with(alert, project, [a_kind_of(User)], escalation_policy, schedule_1)
.and_call_original
expect { execute }.to change(Note, :count).by(1)
......
......@@ -8,10 +8,11 @@ RSpec.describe SystemNotes::EscalationsService do
let_it_be(:user_2) { create(:user) }
let_it_be(:author) { User.alert_bot }
describe '#alert_via_escalation' do
subject { described_class.new(noteable: noteable, project: project).alert_via_escalation([user, user_2], escalation_policy) }
describe '#notify_via_escalation' do
subject { described_class.new(noteable: noteable, project: project).notify_via_escalation([user, user_2], escalation_policy, oncall_schedule) }
let_it_be(:escalation_policy) { create(:incident_management_escalation_policy, project: project) }
let_it_be(:oncall_schedule) { create(:incident_management_oncall_schedule, project: project) }
let_it_be(:noteable) { create(:alert_management_alert, project: project) }
it_behaves_like 'a system note' do
......@@ -21,5 +22,13 @@ RSpec.describe SystemNotes::EscalationsService do
it 'posts the correct text to the system note' do
expect(subject.note).to match("notified #{user.to_reference} and #{user_2.to_reference} of this alert via escalation policy **#{escalation_policy.name}**")
end
context 'when policy is missing' do
let_it_be(:escalation_policy) { nil }
it 'posts the correct text to the system note' do
expect(subject.note).to match("notified #{user.to_reference} and #{user_2.to_reference} of this alert via schedule **#{oncall_schedule.name}**, per an escalation rule which no longer exists")
end
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