Commit c5256d3c authored by Sean Arnold's avatar Sean Arnold

Merge branch '345109-timeline-event-system-note-on-create' into 'master'

Add system note when timeline event created

See merge request gitlab-org/gitlab!82596
parents 50e842fa 27568155
...@@ -23,7 +23,8 @@ module EE ...@@ -23,7 +23,8 @@ module EE
'vulnerability_dismissed' => 'cancel', 'vulnerability_dismissed' => 'cancel',
'vulnerability_resolved' => 'status_closed', 'vulnerability_resolved' => 'status_closed',
'published' => 'bullhorn', 'published' => 'bullhorn',
'paging_started' => 'mobile' 'paging_started' => 'mobile',
'timeline_event' => 'clock'
}.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 paging_started iteration paging_started timeline_event
].freeze ].freeze
EE_TYPES_WITH_CROSS_REFERENCES = %w[ EE_TYPES_WITH_CROSS_REFERENCES = %w[
......
...@@ -120,6 +120,10 @@ module EE ...@@ -120,6 +120,10 @@ module EE
escalations_service(noteable, noteable.project).start_escalation(escalation_policy, author) escalations_service(noteable, noteable.project).start_escalation(escalation_policy, author)
end end
def add_timeline_event(timeline_event)
incidents_service(timeline_event.incident).add_timeline_event(timeline_event)
end
private private
def issuables_service(noteable, project, author) def issuables_service(noteable, project, author)
...@@ -141,5 +145,9 @@ module EE ...@@ -141,5 +145,9 @@ module EE
def escalations_service(noteable, project) def escalations_service(noteable, project)
::SystemNotes::EscalationsService.new(noteable: noteable, project: project) ::SystemNotes::EscalationsService.new(noteable: noteable, project: project)
end end
def incidents_service(incident)
::SystemNotes::IncidentsService.new(noteable: incident)
end
end end
end end
...@@ -29,6 +29,8 @@ module IncidentManagement ...@@ -29,6 +29,8 @@ module IncidentManagement
timeline_event = IncidentManagement::TimelineEvent.new(timeline_event_params) timeline_event = IncidentManagement::TimelineEvent.new(timeline_event_params)
if timeline_event.save if timeline_event.save
add_system_note(timeline_event)
success(timeline_event) success(timeline_event)
else else
error_in_save(timeline_event) error_in_save(timeline_event)
...@@ -38,6 +40,12 @@ module IncidentManagement ...@@ -38,6 +40,12 @@ module IncidentManagement
private private
attr_reader :project, :user, :incident, :params attr_reader :project, :user, :incident, :params
def add_system_note(timeline_event)
return unless Feature.enabled?(:incident_timeline, project, default_enabled: :yaml)
SystemNoteService.add_timeline_event(timeline_event)
end
end end
end end
end end
# frozen_string_literal: true
module SystemNotes
class IncidentsService < ::SystemNotes::BaseService
def initialize(noteable:)
@noteable = noteable
@project = noteable.project
end
def add_timeline_event(timeline_event)
author = timeline_event.author
anchor = "timeline_event_#{timeline_event.id}"
path = url_helpers.project_issues_incident_path(project, noteable, anchor: anchor)
body = "added an [incident timeline event](#{path})"
create_note(NoteSummary.new(noteable, project, author, body, action: 'timeline_event'))
end
end
end
...@@ -5,6 +5,7 @@ require 'spec_helper' ...@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe EE::SystemNoteMetadata do RSpec.describe EE::SystemNoteMetadata do
%i[ %i[
vulnerability_confirmed vulnerability_dismissed vulnerability_resolved vulnerability_detected vulnerability_confirmed vulnerability_dismissed vulnerability_resolved vulnerability_detected
timeline_event
].each do |action| ].each do |action|
context 'when action type is valid' do context 'when action type is valid' do
subject do subject do
......
...@@ -105,5 +105,25 @@ RSpec.describe IncidentManagement::TimelineEvents::CreateService do ...@@ -105,5 +105,25 @@ RSpec.describe IncidentManagement::TimelineEvents::CreateService do
it 'successfully creates a database record', :aggregate_failures do it 'successfully creates a database record', :aggregate_failures do
expect { execute }.to change { ::IncidentManagement::TimelineEvent.count }.by(1) expect { execute }.to change { ::IncidentManagement::TimelineEvent.count }.by(1)
end end
context 'when incident_timeline feature flag is enabled' do
before do
stub_feature_flags(incident_timeline: project)
end
it 'creates a system note' do
expect { execute }.to change { incident.notes.reload.count }.by(1)
end
end
context 'when incident_timeline feature flag is disabled' do
before do
stub_feature_flags(incident_timeline: false)
end
it 'does not create a system note' do
expect { execute }.not_to change { incident.notes.reload.count }
end
end
end end
end end
...@@ -173,4 +173,16 @@ RSpec.describe SystemNoteService do ...@@ -173,4 +173,16 @@ RSpec.describe SystemNoteService do
described_class.start_escalation(noteable, policy, author) described_class.start_escalation(noteable, policy, author)
end end
end end
describe '.add_timeline_event' do
let(:timeline_event) { instance_double('IncidentManagement::TimelineEvent', incident: noteable, project: project) }
it 'calls IncidentsService' do
expect_next_instance_of(::SystemNotes::IncidentsService) do |service|
expect(service).to receive(:add_timeline_event).with(timeline_event)
end
described_class.add_timeline_event(timeline_event)
end
end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe SystemNotes::IncidentsService do
include Gitlab::Routing
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:author) { create(:user) }
let_it_be(:incident) { create(:incident, project: project, author: user) }
let_it_be(:timeline_event) { create(:incident_management_timeline_event, project: project, incident: incident, author: author) }
describe "#add_timeline_event" do
subject { described_class.new(noteable: incident).add_timeline_event(timeline_event) }
it_behaves_like 'a system note' do
let(:noteable) { incident }
let(:action) { 'timeline_event' }
end
it 'poses the correct text to the system note' do
path = project_issues_incident_path(project, incident, anchor: "timeline_event_#{timeline_event.id}")
expect(subject.note).to match("added an [incident timeline event](#{path})")
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