Commit bcf9daa8 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Add a system note on resolve an incident

Create a system note when manually created incident is closed
parent cc875bcf
......@@ -96,7 +96,8 @@ module Issues
return unless issue.incident?
status = issue.incident_management_issuable_escalation_status || issue.build_incident_management_issuable_escalation_status
status.resolve
SystemNoteService.resolve_incident_status(issue, current_user) if status.resolve
end
def store_first_mentioned_in_commit_at(issue, merge_request, max_commit_lookup: 100)
......
......@@ -327,6 +327,10 @@ module SystemNoteService
::SystemNotes::IncidentService.new(noteable: incident, project: incident.project, author: author).change_incident_severity
end
def resolve_incident_status(incident, author)
::SystemNotes::IncidentService.new(noteable: incident, project: incident.project, author: author).resolve_incident_status
end
def log_resolving_alert(alert, monitoring_tool)
::SystemNotes::AlertManagementService.new(noteable: alert, project: alert.project).log_resolving_alert(monitoring_tool)
end
......
......@@ -25,5 +25,11 @@ module SystemNotes
)
end
end
def resolve_incident_status
body = 'changed the status to **Resolved** by closing the incident'
create_note(NoteSummary.new(noteable, project, author, body, action: 'status'))
end
end
end
......@@ -84,7 +84,11 @@ RSpec.describe Issues::CloseService do
end
it 'does not change escalation status' do
expect { service.execute(issue) }.not_to change { IncidentManagement::IssuableEscalationStatus.where(issue: issue).count }
resolved = IncidentManagement::Escalatable::STATUSES[:resolved]
expect { service.execute(issue) }
.to not_change { IncidentManagement::IssuableEscalationStatus.where(issue: issue).count }
.and not_change { IncidentManagement::IssuableEscalationStatus.where(status: resolved).count }
end
context 'issue is incident type' do
......@@ -96,7 +100,7 @@ RSpec.describe Issues::CloseService do
it_behaves_like 'an incident management tracked event', :incident_management_incident_closed
it 'creates a new escalation resolved escalation status', :aggregate_failures do
expect { service.execute(issue) }.to change { IncidentManagement::IssuableEscalationStatus.where(issue: issue).count }.to(1)
expect { service.execute(issue) }.to change { IncidentManagement::IssuableEscalationStatus.where(issue: issue).count }.by(1)
expect(issue.incident_management_issuable_escalation_status).to be_resolved
end
......@@ -109,6 +113,24 @@ RSpec.describe Issues::CloseService do
it 'changes escalations status to resolved' do
expect { service.execute(issue) }.to change { issue.incident_management_issuable_escalation_status.reload.resolved? }.to(true)
end
it 'adds a system note', :aggregate_failures do
expect { service.execute(issue) }.to change { issue.notes.count }.by(1)
new_note = issue.notes.last
expect(new_note.note).to eq('changed the status to **Resolved** by closing the incident')
expect(new_note.author).to eq(user)
end
context 'when the escalation status did not change to resolved' do
let(:escalation_status) { instance_double('IncidentManagement::IssuableEscalationStatus', resolve: false) }
it 'does not create a system note' do
allow(issue).to receive(:incident_management_issuable_escalation_status).and_return(escalation_status)
expect { service.execute(issue) }.not_to change { issue.notes.count }
end
end
end
end
end
......
......@@ -781,6 +781,18 @@ RSpec.describe SystemNoteService do
end
end
describe '.resolve_incident_status' do
let(:incident) { build(:incident, :closed) }
it 'calls IncidentService' do
expect_next_instance_of(SystemNotes::IncidentService) do |service|
expect(service).to receive(:resolve_incident_status)
end
described_class.resolve_incident_status(incident, author)
end
end
describe '.log_resolving_alert' do
let(:alert) { build(:alert_management_alert) }
let(:monitoring_tool) { 'Prometheus' }
......
......@@ -56,4 +56,14 @@ RSpec.describe ::SystemNotes::IncidentService do
end
end
end
describe '#resolve_incident_status' do
subject(:resolve_incident_status) { described_class.new(noteable: noteable, project: project, author: author).resolve_incident_status }
it 'creates a new note about resolved incident', :aggregate_failures do
expect { resolve_incident_status }.to change { noteable.notes.count }.by(1)
expect(noteable.notes.last.note).to eq('changed the status to **Resolved** by closing the incident')
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