Commit 8ecd9fa8 authored by Michael Kozono's avatar Michael Kozono

Merge branch 'sarnold-system-note-for-issuable-type-change' into 'master'

Add system note for issue type changes

See merge request gitlab-org/gitlab!68239
parents 3e4b6020 b8881bd7
...@@ -39,7 +39,8 @@ module SystemNoteHelper ...@@ -39,7 +39,8 @@ module SystemNoteHelper
'alert_issue_added' => 'issues', 'alert_issue_added' => 'issues',
'new_alert_added' => 'warning', 'new_alert_added' => 'warning',
'severity' => 'information-o', 'severity' => 'information-o',
'cloned' => 'documents' 'cloned' => 'documents',
'issue_type' => 'pencil-square'
}.freeze }.freeze
def system_note_icon_name(note) def system_note_icon_name(note)
......
...@@ -77,6 +77,7 @@ module Issues ...@@ -77,6 +77,7 @@ module Issues
end end
handle_severity_change(issue, old_severity) handle_severity_change(issue, old_severity)
handle_issue_type_change(issue)
end end
def handle_assignee_changes(issue, old_assignees) def handle_assignee_changes(issue, old_assignees)
...@@ -218,6 +219,16 @@ module Issues ...@@ -218,6 +219,16 @@ module Issues
def remove_incident_label?(issue) def remove_incident_label?(issue)
issue.issue_type != params[:issue_type] && issue.incident? issue.issue_type != params[:issue_type] && issue.incident?
end 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
end end
......
...@@ -331,6 +331,10 @@ module SystemNoteService ...@@ -331,6 +331,10 @@ module SystemNoteService
::SystemNotes::AlertManagementService.new(noteable: alert, project: alert.project).log_resolving_alert(monitoring_tool) ::SystemNotes::AlertManagementService.new(noteable: alert, project: alert.project).log_resolving_alert(monitoring_tool)
end end
def change_issue_type(issue, author)
::SystemNotes::IssuablesService.new(noteable: issue, project: issue.project, author: author).change_issue_type
end
private private
def merge_requests_service(noteable, project, author) def merge_requests_service(noteable, project, author)
......
...@@ -380,6 +380,12 @@ module SystemNotes ...@@ -380,6 +380,12 @@ module SystemNotes
create_resource_state_event(status: 'closed', close_auto_resolve_prometheus_alert: true) create_resource_state_event(status: 'closed', close_auto_resolve_prometheus_alert: true)
end 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 private
def cross_reference_note_content(gfm_reference) def cross_reference_note_content(gfm_reference)
......
...@@ -36,7 +36,6 @@ module EE ...@@ -36,7 +36,6 @@ module EE
super super
handle_iteration_change(issue) handle_iteration_change(issue)
handle_issue_type_change(issue)
end end
private private
...@@ -55,8 +54,9 @@ module EE ...@@ -55,8 +54,9 @@ module EE
end end
end end
def handle_issue_type_change(issue) override :do_handle_issue_type_change
return unless issue.previous_changes.include?('issue_type') def do_handle_issue_type_change(issue)
super
::IncidentManagement::Incidents::CreateSlaService.new(issue, current_user).execute ::IncidentManagement::Incidents::CreateSlaService.new(issue, current_user).execute
end end
......
...@@ -179,10 +179,24 @@ RSpec.describe Issues::UpdateService do ...@@ -179,10 +179,24 @@ RSpec.describe Issues::UpdateService do
end end
context 'from issue to incident' do context 'from issue to incident' do
it 'creates an SLA' do shared_examples 'creates an SLA' do
expect { update_issue(issue_type: 'incident') }.to change(IssuableSla, :count).by(1) it do
expect(issue.reload).to be_incident expect { update_issue(issue_type: 'incident') }.to change(IssuableSla, :count).by(1)
expect(issue.reload.issuable_sla).to be_present 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
end end
......
...@@ -189,6 +189,14 @@ RSpec.describe Issues::UpdateService, :mailer do ...@@ -189,6 +189,14 @@ RSpec.describe Issues::UpdateService, :mailer do
expect(issue.labels.pluck(:title)).to eq(['incident']) expect(issue.labels.pluck(:title)).to eq(['incident'])
end 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 context 'for an issue with multiple labels' do
let(:issue) { create(:incident, project: project, labels: [label_1]) } let(:issue) { create(:incident, project: project, labels: [label_1]) }
......
...@@ -793,4 +793,16 @@ RSpec.describe SystemNoteService do ...@@ -793,4 +793,16 @@ RSpec.describe SystemNoteService do
described_class.log_resolving_alert(alert, monitoring_tool) described_class.log_resolving_alert(alert, monitoring_tool)
end end
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 end
...@@ -773,4 +773,16 @@ RSpec.describe ::SystemNotes::IssuablesService do ...@@ -773,4 +773,16 @@ RSpec.describe ::SystemNotes::IssuablesService do
expect(event.state).to eq('closed') expect(event.state).to eq('closed')
end end
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 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