Skip to content
Snippets Groups Projects
Commit 7b1ad08c authored by Andrew Fontaine's avatar Andrew Fontaine
Browse files

Merge branch 'afontaine/make-discussions-from-emails' into 'master'

Allow Email Replies to Notes to Create Discussions

See merge request !56711
parents 06094f7a 0a4d6455
No related branches found
No related tags found
No related merge requests found
Pipeline #287276367 passed
......@@ -178,7 +178,7 @@ def mail_answer_note_thread(model, note, headers = {})
headers['In-Reply-To'] = message_id(note.references.last)
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]
......
......@@ -48,7 +48,7 @@ def record(noteable, recipient_id, reply_key = self.reply_key, attrs = {})
end
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)
end
......
---
title: Allow Email Replies to Notes to Create Discussions
merge_request: 56711
author:
type: changed
......@@ -23,9 +23,8 @@
context "when the note could not be saved" do
before do
allow_next_instance_of(Note) do |instance|
allow(instance).to receive(:persisted?).and_return(false)
end
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56711#note_551958817
allow_any_instance_of(Note).to receive(:persisted?).and_return(false) # rubocop:disable RSpec/AnyInstanceOf
end
it "raises an InvalidNoteError" do
......
......@@ -59,7 +59,7 @@
end
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)
new_note = noteable.notes.last
......@@ -68,11 +68,7 @@
expect(new_note.note).to include('I could not disagree more.')
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)
else
expect(new_note.discussion_id).not_to eq(note.discussion_id)
end
expect(new_note.discussion_id).to eq(note.discussion_id)
end
end
......
......@@ -72,8 +72,8 @@
it_behaves_like 'a successful sent notification'
it 'does not set in_reply_to_discussion_id' do
expect(subject.in_reply_to_discussion_id).to be_nil
it 'sets in_reply_to_discussion_id' do
expect(subject.in_reply_to_discussion_id).to eq(note.discussion_id)
end
end
end
......@@ -212,10 +212,10 @@
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')
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
......@@ -247,10 +247,10 @@
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')
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
......
......@@ -185,6 +185,7 @@ def setup_attachment
let(:email_raw) { with_quick_actions }
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)
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment