Commit b8881bd7 authored by Sean Arnold's avatar Sean Arnold Committed by Michael Kozono

Add system note for issue type changes

Changelog: added
parent e66837f0
......@@ -39,7 +39,8 @@ module SystemNoteHelper
'alert_issue_added' => 'issues',
'new_alert_added' => 'warning',
'severity' => 'information-o',
'cloned' => 'documents'
'cloned' => 'documents',
'issue_type' => 'pencil-square'
}.freeze
def system_note_icon_name(note)
......
......@@ -77,6 +77,7 @@ module Issues
end
handle_severity_change(issue, old_severity)
handle_issue_type_change(issue)
end
def handle_assignee_changes(issue, old_assignees)
......@@ -218,6 +219,16 @@ module Issues
def remove_incident_label?(issue)
issue.issue_type != params[:issue_type] && issue.incident?
end
def handle_issue_type_change(issue)
return unless issue.previous_changes.include?('issue_type')
do_handle_issue_type_change(issue)
end
def do_handle_issue_type_change(issue)
SystemNoteService.change_issue_type(issue, current_user)
end
end
end
......
......@@ -331,6 +331,10 @@ module SystemNoteService
::SystemNotes::AlertManagementService.new(noteable: alert, project: alert.project).log_resolving_alert(monitoring_tool)
end
def change_issue_type(issue, author)
::SystemNotes::IssuablesService.new(noteable: issue, project: issue.project, author: author).change_issue_type
end
private
def merge_requests_service(noteable, project, author)
......
......@@ -380,6 +380,12 @@ module SystemNotes
create_resource_state_event(status: 'closed', close_auto_resolve_prometheus_alert: true)
end
def change_issue_type
body = "changed issue type to #{noteable.issue_type.humanize(capitalize: false)}"
create_note(NoteSummary.new(noteable, project, author, body, action: 'issue_type'))
end
private
def cross_reference_note_content(gfm_reference)
......
......@@ -36,7 +36,6 @@ module EE
super
handle_iteration_change(issue)
handle_issue_type_change(issue)
end
private
......@@ -55,8 +54,9 @@ module EE
end
end
def handle_issue_type_change(issue)
return unless issue.previous_changes.include?('issue_type')
override :do_handle_issue_type_change
def do_handle_issue_type_change(issue)
super
::IncidentManagement::Incidents::CreateSlaService.new(issue, current_user).execute
end
......
......@@ -179,10 +179,24 @@ RSpec.describe Issues::UpdateService do
end
context 'from issue to incident' do
it 'creates an SLA' do
expect { update_issue(issue_type: 'incident') }.to change(IssuableSla, :count).by(1)
expect(issue.reload).to be_incident
expect(issue.reload.issuable_sla).to be_present
shared_examples 'creates an SLA' do
it do
expect { update_issue(issue_type: 'incident') }.to change(IssuableSla, :count).by(1)
expect(issue.reload).to be_incident
expect(issue.reload.issuable_sla).to be_present
end
end
it_behaves_like 'creates an SLA'
context 'system note fails to be created' do
before do
expect_next_instance_of(Note) do |note|
expect(note).to receive(:valid?).and_return(false)
end
end
it_behaves_like 'creates an SLA'
end
end
......
......@@ -189,6 +189,14 @@ RSpec.describe Issues::UpdateService, :mailer do
expect(issue.labels.pluck(:title)).to eq(['incident'])
end
it 'creates system note about issue type' do
update_issue(issue_type: 'incident')
note = find_note('changed issue type to incident')
expect(note).not_to eq(nil)
end
context 'for an issue with multiple labels' do
let(:issue) { create(:incident, project: project, labels: [label_1]) }
......
......@@ -793,4 +793,16 @@ RSpec.describe SystemNoteService do
described_class.log_resolving_alert(alert, monitoring_tool)
end
end
describe '.change_issue_type' do
let(:incident) { build(:incident) }
it 'calls IssuableService' do
expect_next_instance_of(::SystemNotes::IssuablesService) do |service|
expect(service).to receive(:change_issue_type)
end
described_class.change_issue_type(incident, author)
end
end
end
......@@ -773,4 +773,16 @@ RSpec.describe ::SystemNotes::IssuablesService do
expect(event.state).to eq('closed')
end
end
describe '#change_issue_type' do
let(:noteable) { create(:incident, project: project) }
subject { service.change_issue_type }
it_behaves_like 'a system note' do
let(:action) { 'issue_type' }
end
it { expect(subject.note).to eq "changed issue type to incident" }
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