Commit 403afa0c authored by Andrew Fontaine's avatar Andrew Fontaine Committed by Heinrich Lee Yu

Allow Email Replies to Notes to Create Discussions

parent 06094f7a
...@@ -178,7 +178,7 @@ class Notify < ApplicationMailer ...@@ -178,7 +178,7 @@ class Notify < ApplicationMailer
headers['In-Reply-To'] = message_id(note.references.last) headers['In-Reply-To'] = message_id(note.references.last)
headers['References'] = note.references.map { |ref| message_id(ref) } headers['References'] = note.references.map { |ref| message_id(ref) }
headers['X-GitLab-Discussion-ID'] = note.discussion.id if note.part_of_discussion? headers['X-GitLab-Discussion-ID'] = note.discussion.id if note.part_of_discussion? || note.can_be_discussion_note?
headers[:subject] = "Re: #{headers[:subject]}" if headers[:subject] headers[:subject] = "Re: #{headers[:subject]}" if headers[:subject]
......
...@@ -48,7 +48,7 @@ class SentNotification < ApplicationRecord ...@@ -48,7 +48,7 @@ class SentNotification < ApplicationRecord
end end
def record_note(note, recipient_id, reply_key = self.reply_key, attrs = {}) def record_note(note, recipient_id, reply_key = self.reply_key, attrs = {})
attrs[:in_reply_to_discussion_id] = note.discussion_id if note.part_of_discussion? attrs[:in_reply_to_discussion_id] = note.discussion_id if note.part_of_discussion? || note.can_be_discussion_note?
record(note.noteable, recipient_id, reply_key, attrs) record(note.noteable, recipient_id, reply_key, attrs)
end end
......
---
title: Allow Email Replies to Notes to Create Discussions
merge_request: 56711
author:
type: changed
...@@ -23,9 +23,8 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do ...@@ -23,9 +23,8 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do
context "when the note could not be saved" do context "when the note could not be saved" do
before do before do
allow_next_instance_of(Note) do |instance| # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56711#note_551958817
allow(instance).to receive(:persisted?).and_return(false) allow_any_instance_of(Note).to receive(:persisted?).and_return(false) # rubocop:disable RSpec/AnyInstanceOf
end
end end
it "raises an InvalidNoteError" do it "raises an InvalidNoteError" do
......
...@@ -59,7 +59,7 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do ...@@ -59,7 +59,7 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do
end end
shared_examples 'a reply to existing comment' do shared_examples 'a reply to existing comment' do
it 'creates a comment' do it 'creates a discussion' do
expect { receiver.execute }.to change { noteable.notes.count }.by(1) expect { receiver.execute }.to change { noteable.notes.count }.by(1)
new_note = noteable.notes.last new_note = noteable.notes.last
...@@ -68,11 +68,7 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do ...@@ -68,11 +68,7 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do
expect(new_note.note).to include('I could not disagree more.') expect(new_note.note).to include('I could not disagree more.')
expect(new_note.in_reply_to?(note)).to be_truthy expect(new_note.in_reply_to?(note)).to be_truthy
if note.part_of_discussion?
expect(new_note.discussion_id).to eq(note.discussion_id) expect(new_note.discussion_id).to eq(note.discussion_id)
else
expect(new_note.discussion_id).not_to eq(note.discussion_id)
end
end end
end end
......
...@@ -72,8 +72,8 @@ RSpec.describe SentNotification do ...@@ -72,8 +72,8 @@ RSpec.describe SentNotification do
it_behaves_like 'a successful sent notification' it_behaves_like 'a successful sent notification'
it 'does not set in_reply_to_discussion_id' do it 'sets in_reply_to_discussion_id' do
expect(subject.in_reply_to_discussion_id).to be_nil expect(subject.in_reply_to_discussion_id).to eq(note.discussion_id)
end end
end end
end end
...@@ -212,10 +212,10 @@ RSpec.describe SentNotification do ...@@ -212,10 +212,10 @@ RSpec.describe SentNotification do
subject { described_class.record_note(note, note.author.id) } subject { described_class.record_note(note, note.author.id) }
it 'creates a comment on the issue' do it 'converts the comment to a discussion on the issue' do
new_note = subject.create_reply('Test') new_note = subject.create_reply('Test')
expect(new_note.in_reply_to?(note)).to be_truthy expect(new_note.in_reply_to?(note)).to be_truthy
expect(new_note.discussion_id).not_to eq(note.discussion_id) expect(new_note.discussion_id).to eq(note.discussion_id)
end end
end end
...@@ -247,10 +247,10 @@ RSpec.describe SentNotification do ...@@ -247,10 +247,10 @@ RSpec.describe SentNotification do
subject { described_class.record_note(note, note.author.id) } subject { described_class.record_note(note, note.author.id) }
it 'creates a comment on the merge request' do it 'converts the comment to a discussion on the merge request' do
new_note = subject.create_reply('Test') new_note = subject.create_reply('Test')
expect(new_note.in_reply_to?(note)).to be_truthy expect(new_note.in_reply_to?(note)).to be_truthy
expect(new_note.discussion_id).not_to eq(note.discussion_id) expect(new_note.discussion_id).to eq(note.discussion_id)
end end
end end
......
...@@ -185,6 +185,7 @@ RSpec.shared_examples :note_handler_shared_examples do |forwardable| ...@@ -185,6 +185,7 @@ RSpec.shared_examples :note_handler_shared_examples do |forwardable|
let(:email_raw) { with_quick_actions } let(:email_raw) { with_quick_actions }
let!(:sent_notification) do let!(:sent_notification) do
allow(Gitlab::ServiceDesk).to receive(:enabled?).with(project: project).and_return(true)
SentNotification.record_note(note, support_bot.id, mail_key) SentNotification.record_note(note, support_bot.id, mail_key)
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