Commit 0dc65764 authored by Michael Kozono's avatar Michael Kozono

Merge branch '330281-add-escalation-status-on-issue-type-change' into 'master'

Handle escalation changes issue type change

See merge request gitlab-org/gitlab!75706
parents 1f424855 badcfcd2
......@@ -259,6 +259,8 @@ module Issues
def do_handle_issue_type_change(issue)
SystemNoteService.change_issue_type(issue, current_user)
::IncidentManagement::IssuableEscalationStatuses::CreateService.new(issue).execute if issue.supports_escalation?
end
end
end
......
......@@ -73,6 +73,8 @@ module EE
super
::IncidentManagement::Incidents::CreateSlaService.new(issue, current_user).execute
issue.pending_escalations.delete_all(:delete_all) unless issue.supports_escalation?
end
def handle_promotion(issue)
......
......@@ -59,6 +59,26 @@ RSpec.describe IncidentManagement::IssuableEscalationStatuses::CreateService do
it_behaves_like 'creates an escalation status for the incident with no policy set'
end
context 'when alert pending escalations exist' do
let!(:first_pending_escalation) { create(:incident_management_pending_alert_escalation, alert: alert) }
let!(:second_pending_escalation) { create(:incident_management_pending_alert_escalation, alert: alert) }
it 'creates an escalation status with the pending escalation start time' do
execute
status = incident.incident_management_issuable_escalation_status
expect(status.escalations_started_at).to be_like_time(second_pending_escalation.created_at)
end
end
context 'when feature flag is disabled' do
before do
stub_feature_flags(incident_escalations: false)
end
it_behaves_like 'creates an escalation status for the incident with no policy set'
end
end
end
end
......@@ -201,14 +201,24 @@ RSpec.describe Issues::UpdateService do
end
context 'from incident to issue' do
let_it_be(:issue) { create(:incident, project: project) }
let_it_be(:sla) { create(:issuable_sla, issue: issue) }
let!(:issue) { create(:incident, project: project) }
let!(:sla) { create(:issuable_sla, issue: issue) }
it 'does not remove the SLA or create a new one' do
expect { update_issue(issue_type: 'issue') }.not_to change(IssuableSla, :count)
expect(issue.reload.issue_type).to eq('issue')
expect(issue.reload.issuable_sla).to be_present
end
it 'destroys any pending escalations' do
pending = create(:incident_management_pending_issue_escalation, issue: issue)
pending_2 = create(:incident_management_pending_issue_escalation, issue: issue)
update_issue(issue_type: 'issue')
expect { pending.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { pending_2.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'from issue to restricted issue types' do
......
......@@ -204,6 +204,13 @@ RSpec.describe Issues::UpdateService, :mailer do
expect(note).not_to eq(nil)
end
it 'creates an escalation status' do
expect { update_issue(issue_type: 'incident') }
.to change { issue.reload.incident_management_issuable_escalation_status }
.from(nil)
.to(a_kind_of(IncidentManagement::IssuableEscalationStatus))
end
context 'for an issue with multiple labels' do
let(:issue) { create(:incident, project: project, labels: [label_1]) }
......
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