Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
403afa0c
Commit
403afa0c
authored
Apr 16, 2021
by
Andrew Fontaine
Committed by
Heinrich Lee Yu
Apr 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow Email Replies to Notes to Create Discussions
parent
06094f7a
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
18 additions
and
17 deletions
+18
-17
app/mailers/notify.rb
app/mailers/notify.rb
+1
-1
app/models/sent_notification.rb
app/models/sent_notification.rb
+1
-1
changelogs/unreleased/afontaine-make-discussions-from-emails.yml
...ogs/unreleased/afontaine-make-discussions-from-emails.yml
+5
-0
ee/spec/lib/gitlab/email/handler/create_note_handler_spec.rb
ee/spec/lib/gitlab/email/handler/create_note_handler_spec.rb
+2
-3
spec/lib/gitlab/email/handler/create_note_handler_spec.rb
spec/lib/gitlab/email/handler/create_note_handler_spec.rb
+2
-6
spec/models/sent_notification_spec.rb
spec/models/sent_notification_spec.rb
+6
-6
spec/support/shared_contexts/email_shared_context.rb
spec/support/shared_contexts/email_shared_context.rb
+1
-0
No files found.
app/mailers/notify.rb
View file @
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
]
...
...
app/models/sent_notification.rb
View file @
403afa0c
...
...
@@ -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
...
...
changelogs/unreleased/afontaine-make-discussions-from-emails.yml
0 → 100644
View file @
403afa0c
---
title
:
Allow Email Replies to Notes to Create Discussions
merge_request
:
56711
author
:
type
:
changed
ee/spec/lib/gitlab/email/handler/create_note_handler_spec.rb
View file @
403afa0c
...
...
@@ -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
...
...
spec/lib/gitlab/email/handler/create_note_handler_spec.rb
View file @
403afa0c
...
...
@@ -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
...
...
spec/models/sent_notification_spec.rb
View file @
403afa0c
...
...
@@ -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
'c
reates a comment
on the issue'
do
it
'c
onverts 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
'c
reates a comment
on the merge request'
do
it
'c
onverts 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
...
...
spec/support/shared_contexts/email_shared_context.rb
View file @
403afa0c
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment