Commit 52c98060 authored by Sarah Yasonik's avatar Sarah Yasonik Committed by Pavel Shutsin

Add system note for when paging starts on a manually created incident

Indicates the escalation policy which is being notified of the incident.
Behind feature flag :incident_escalations.
parent e9155538
...@@ -22,7 +22,8 @@ module EE ...@@ -22,7 +22,8 @@ module EE
'vulnerability_confirmed' => 'shield', 'vulnerability_confirmed' => 'shield',
'vulnerability_dismissed' => 'cancel', 'vulnerability_dismissed' => 'cancel',
'vulnerability_resolved' => 'status_closed', 'vulnerability_resolved' => 'status_closed',
'published' => 'bullhorn' 'published' => 'bullhorn',
'paging_started' => 'mobile'
}.freeze }.freeze
override :system_note_icon_name override :system_note_icon_name
......
...@@ -9,7 +9,7 @@ module EE ...@@ -9,7 +9,7 @@ module EE
epic_issue_added issue_added_to_epic epic_issue_removed issue_removed_from_epic epic_issue_added issue_added_to_epic epic_issue_removed issue_removed_from_epic
epic_issue_moved issue_changed_epic epic_date_changed relate_epic unrelate_epic epic_issue_moved issue_changed_epic epic_date_changed relate_epic unrelate_epic
vulnerability_confirmed vulnerability_dismissed vulnerability_resolved vulnerability_detected vulnerability_confirmed vulnerability_dismissed vulnerability_resolved vulnerability_detected
iteration iteration paging_started
].freeze ].freeze
EE_TYPES_WITH_CROSS_REFERENCES = %w[ EE_TYPES_WITH_CROSS_REFERENCES = %w[
......
...@@ -56,6 +56,7 @@ module EE ...@@ -56,6 +56,7 @@ module EE
def create_escalations def create_escalations
::IncidentManagement::PendingEscalations::IssueCreateWorker.perform_async(issuable.id) ::IncidentManagement::PendingEscalations::IssueCreateWorker.perform_async(issuable.id)
::SystemNoteService.start_escalation(issuable, escalation_status.policy, current_user)
end end
end end
end end
......
...@@ -116,6 +116,10 @@ module EE ...@@ -116,6 +116,10 @@ module EE
escalations_service(noteable, project).notify_via_escalation(recipients, escalation_policy: escalation_policy, type: type) escalations_service(noteable, project).notify_via_escalation(recipients, escalation_policy: escalation_policy, type: type)
end end
def start_escalation(noteable, escalation_policy, author)
escalations_service(noteable, noteable.project).start_escalation(escalation_policy, author)
end
private private
def issuables_service(noteable, project, author) def issuables_service(noteable, project, author)
......
...@@ -13,5 +13,12 @@ module SystemNotes ...@@ -13,5 +13,12 @@ module SystemNotes
create_note(NoteSummary.new(noteable, project, author, body, action: 'new_alert_added')) create_note(NoteSummary.new(noteable, project, author, body, action: 'new_alert_added'))
end end
def start_escalation(escalation_policy, author)
path = url_helpers.project_incident_management_escalation_policies_path(project)
body = "paged escalation policy [#{escalation_policy.name}](#{path})"
create_note(NoteSummary.new(noteable, project, author, body, action: 'paging_started'))
end
end end
end end
...@@ -95,6 +95,7 @@ RSpec.describe IncidentManagement::IssuableEscalationStatuses::AfterUpdateServic ...@@ -95,6 +95,7 @@ RSpec.describe IncidentManagement::IssuableEscalationStatuses::AfterUpdateServic
if should_create if should_create
expect(::IncidentManagement::PendingEscalations::IssueCreateWorker).to receive(:perform_async).with(issue.id) expect(::IncidentManagement::PendingEscalations::IssueCreateWorker).to receive(:perform_async).with(issue.id)
expect(::SystemNoteService).to receive(:start_escalation).with(issue, escalation_policy, current_user)
else else
expect(::IncidentManagement::PendingEscalations::IssueCreateWorker).not_to receive(:perform_async) expect(::IncidentManagement::PendingEscalations::IssueCreateWorker).not_to receive(:perform_async)
end end
......
...@@ -161,4 +161,16 @@ RSpec.describe SystemNoteService do ...@@ -161,4 +161,16 @@ RSpec.describe SystemNoteService do
described_class.publish_issue_to_status_page(noteable, project, author) described_class.publish_issue_to_status_page(noteable, project, author)
end end
end end
describe '.start_escalation' do
let(:policy) { double(project: project) }
it 'calls EscalationsService' do
expect_next_instance_of(::SystemNotes::EscalationsService) do |service|
expect(service).to receive(:start_escalation).with(policy, author)
end
described_class.start_escalation(noteable, policy, author)
end
end
end end
...@@ -3,15 +3,17 @@ ...@@ -3,15 +3,17 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe SystemNotes::EscalationsService do RSpec.describe SystemNotes::EscalationsService do
include Gitlab::Routing
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:user_2) { create(:user) } let_it_be(:user_2) { create(:user) }
let_it_be(:author) { User.alert_bot } let_it_be(:author) { User.alert_bot }
let_it_be(:escalation_policy) { create(:incident_management_escalation_policy, project: project) }
describe '#notify_via_escalation' do describe '#notify_via_escalation' do
subject { described_class.new(noteable: noteable, project: project).notify_via_escalation([user, user_2], escalation_policy: escalation_policy, type: type) } subject { described_class.new(noteable: noteable, project: project).notify_via_escalation([user, user_2], escalation_policy: escalation_policy, type: type) }
let_it_be(:escalation_policy) { create(:incident_management_escalation_policy, project: project) }
let_it_be(:noteable) { create(:alert_management_alert, project: project) } let_it_be(:noteable) { create(:alert_management_alert, project: project) }
let_it_be(:type) { :alert } let_it_be(:type) { :alert }
...@@ -23,4 +25,23 @@ RSpec.describe SystemNotes::EscalationsService do ...@@ -23,4 +25,23 @@ RSpec.describe SystemNotes::EscalationsService do
expect(subject.note).to match("notified #{user.to_reference} and #{user_2.to_reference} of this #{type} via escalation policy **#{escalation_policy.name}**") expect(subject.note).to match("notified #{user.to_reference} and #{user_2.to_reference} of this #{type} via escalation policy **#{escalation_policy.name}**")
end end
end end
describe '#start_escalation' do
let_it_be(:noteable) { create(:issue, project: project) }
let_it_be(:author) { user }
subject do
described_class
.new(noteable: noteable, project: project)
.start_escalation(escalation_policy, user)
end
it_behaves_like 'a system note' do
let(:action) { 'paging_started' }
end
it 'posts the correct text to the system note' do
expect(subject.note).to match("paged escalation policy [#{escalation_policy.name}](#{project_incident_management_escalation_policies_path(project)})")
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