Commit b17c41f4 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

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

Allow Email Replies to Notes to Create Discussions

See merge request gitlab-org/gitlab!56711
parents b83bee17 403afa0c
......@@ -178,7 +178,7 @@ class Notify < ApplicationMailer
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 @@ class SentNotification < ApplicationRecord
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 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do
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 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do
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 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do
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
end
end
......
......@@ -72,8 +72,8 @@ RSpec.describe SentNotification do
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 @@ RSpec.describe SentNotification do
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 @@ RSpec.describe SentNotification do
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 @@ RSpec.shared_examples :note_handler_shared_examples do |forwardable|
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
......
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