diff --git a/app/services/notes/update_service.rb b/app/services/notes/update_service.rb index 529402810182d2fc3a1bbbe3611bd6503e3aa71d..3924ccc4745f9b9daeda96a67f6b402243f65bee 100644 --- a/app/services/notes/update_service.rb +++ b/app/services/notes/update_service.rb @@ -34,6 +34,8 @@ def execute(note) update_todos(note, old_mentioned_users) update_suggestions(note) + + execute_note_webhook(note) end if quick_actions_service.commands_executed_count.to_i > 0 @@ -97,6 +99,16 @@ def track_note_edit_usage_for_issues(note) ) end + def execute_note_webhook(note) + return unless note.project && note.previous_changes.include?('note') + + note_data = Gitlab::DataBuilder::Note.build(note, note.author) + is_confidential = note.confidential?(include_noteable: true) + hooks_scope = is_confidential ? :confidential_note_hooks : :note_hooks + + note.project.execute_hooks(note_data, hooks_scope) + end + def track_note_edit_usage_for_merge_requests(note) Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter.track_edit_comment_action(note: note) end diff --git a/spec/services/notes/update_service_spec.rb b/spec/services/notes/update_service_spec.rb index 28ab98cd59261dc810071538a12c971c0449435a..5eaf27651740b87284235fbb7c1c079e109ccfd4 100644 --- a/spec/services/notes/update_service_spec.rb +++ b/spec/services/notes/update_service_spec.rb @@ -115,6 +115,11 @@ def update_note(opts) edit_note_text end + it 'creates a webhook event' do + expect(project).to receive(:execute_hooks) + edit_note_text + end + context 'when quick action only update' do it "delete note and return commands_only error" do updated_note = described_class.new(project, user, { note: "/close\n" }).execute(note) @@ -130,7 +135,7 @@ def update_note(opts) context 'when note text was not changed' do let!(:note) { create(:note, project: project, noteable: issue, author: user2, note: "Old note #{user3.to_reference}") } - let(:does_not_edit_note_text) { update_note({}) } + let(:does_not_edit_note_text) { update_note({ note: note.note }) } it 'does not update last_edited_at' do travel_to(1.day.from_now) do @@ -148,6 +153,11 @@ def update_note(opts) expect(note).not_to receive(:check_for_spam) does_not_edit_note_text end + + it 'does not create a webhook event' do + expect(project).not_to receive(:execute_hooks) + does_not_edit_note_text + end end context 'when the notable is a merge request' do @@ -308,6 +318,12 @@ def update_note(opts) update_note(note: 'new text') end + + it 'does not create a webhook event' do + expect(project).not_to receive(:execute_hooks) + + update_note(note: 'new text') + end end end end