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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
6642ae45
Commit
6642ae45
authored
Aug 15, 2016
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add notifications for new user mentions in merge requests
parent
b450aab8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
107 additions
and
1 deletion
+107
-1
app/mailers/emails/merge_requests.rb
app/mailers/emails/merge_requests.rb
+5
-0
app/services/merge_requests/update_service.rb
app/services/merge_requests/update_service.rb
+8
-1
app/services/notification_service.rb
app/services/notification_service.rb
+14
-0
app/views/notify/new_mention_in_merge_request_email.html.haml
...views/notify/new_mention_in_merge_request_email.html.haml
+12
-0
app/views/notify/new_mention_in_merge_request_email.text.erb
app/views/notify/new_mention_in_merge_request_email.text.erb
+9
-0
spec/services/merge_requests/update_service_spec.rb
spec/services/merge_requests/update_service_spec.rb
+33
-0
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+26
-0
No files found.
app/mailers/emails/merge_requests.rb
View file @
6642ae45
...
...
@@ -6,6 +6,11 @@ module Emails
mail_new_thread
(
@merge_request
,
merge_request_thread_options
(
@merge_request
.
author_id
,
recipient_id
))
end
def
new_mention_in_merge_request_email
(
recipient_id
,
merge_request_id
,
updated_by_user_id
)
setup_merge_request_mail
(
merge_request_id
,
recipient_id
)
mail_answer_thread
(
@merge_request
,
merge_request_thread_options
(
updated_by_user_id
,
recipient_id
))
end
def
reassigned_merge_request_email
(
recipient_id
,
merge_request_id
,
previous_assignee_id
,
updated_by_user_id
)
setup_merge_request_mail
(
merge_request_id
,
recipient_id
)
...
...
app/services/merge_requests/update_service.rb
View file @
6642ae45
...
...
@@ -56,7 +56,14 @@ module MergeRequests
)
end
# TODO(nick): use old_mentioned_users to send notify for changed mentions
added_mentions
=
merge_request
.
mentioned_users
-
old_mentioned_users
if
added_mentions
.
present?
notification_service
.
new_mentions_in_merge_request
(
merge_request
,
added_mentions
,
current_user
)
end
end
def
reopen_service
...
...
app/services/notification_service.rb
View file @
6642ae45
...
...
@@ -89,6 +89,20 @@ class NotificationService
new_resource_email
(
merge_request
,
merge_request
.
target_project
,
:new_merge_request_email
)
end
# When merge request text is updated, we should send an email to:
#
# * newly mentioned project team members with notification level higher than Participating
#
def
new_mentions_in_merge_request
(
merge_request
,
new_mentioned_users
,
current_user
)
new_mentions_in_resource_email
(
merge_request
,
merge_request
.
target_project
,
new_mentioned_users
,
current_user
,
:new_mention_in_merge_request_email
)
end
# When we reassign a merge_request we should send an email to:
#
# * merge_request old assignee if their notification level is not Disabled
...
...
app/views/notify/new_mention_in_merge_request_email.html.haml
0 → 100644
View file @
6642ae45
-
if
current_application_settings
.
email_author_in_body
%div
#{
link_to
@merge_request
.
author_name
,
user_url
(
@merge_request
.
author
)
}
wrote:
%p
.details
!=
merge_path_description
(
@merge_request
,
'→'
)
-
if
@merge_request
.
assignee_id
.
present?
%p
Assignee:
#{
@merge_request
.
author_name
}
→
#{
@merge_request
.
assignee_name
}
-
if
@merge_request
.
description
=
markdown
(
@merge_request
.
description
,
pipeline: :email
,
author:
@merge_request
.
author
)
app/views/notify/new_mention_in_merge_request_email.text.erb
0 → 100644
View file @
6642ae45
You have been mentioned in Merge Request
<%=
@merge_request
.
to_reference
%>
<%=
url_for
(
namespace_project_merge_request_url
(
@merge_request
.
target_project
.
namespace
,
@merge_request
.
target_project
,
@merge_request
))
%>
<%=
merge_path_description
(
@merge_request
,
'to'
)
%>
Author:
<%=
@merge_request
.
author_name
%>
Assignee:
<%=
@merge_request
.
assignee_name
%>
<%=
@merge_request
.
description
%>
spec/services/merge_requests/update_service_spec.rb
View file @
6642ae45
...
...
@@ -226,6 +226,39 @@ describe MergeRequests::UpdateService, services: true do
end
end
context
'updated user mentions'
do
let
(
:user4
)
{
create
(
:user
)
}
before
do
project
.
team
<<
[
user4
,
:developer
]
end
context
"in title"
do
before
do
perform_enqueued_jobs
{
update_merge_request
(
title:
user4
.
to_reference
)
}
end
it
"should email only the newly-mentioned user"
do
should_not_email
(
user
)
should_not_email
(
user2
)
should_not_email
(
user3
)
should_email
(
user4
)
end
end
context
"in description"
do
before
do
perform_enqueued_jobs
{
update_merge_request
(
description:
user4
.
to_reference
)
}
end
it
"should email only the newly-mentioned user"
do
should_not_email
(
user
)
should_not_email
(
user2
)
should_not_email
(
user3
)
should_email
(
user4
)
end
end
end
context
'when MergeRequest has tasks'
do
before
{
update_merge_request
({
description:
"- [ ] Task 1
\n
- [ ] Task 2"
})
}
...
...
spec/services/notification_service_spec.rb
View file @
6642ae45
...
...
@@ -789,6 +789,32 @@ describe NotificationService, services: true do
end
end
describe
'#new_mentions_in_merge_request'
do
def
send_notifications
(
*
new_mentions
)
ActionMailer
::
Base
.
deliveries
.
clear
notification
.
new_mentions_in_merge_request
(
merge_request
,
new_mentions
,
@u_disabled
)
end
it
"should not email anyone unless they are newly mentioned"
do
send_notifications
expect
(
ActionMailer
::
Base
.
deliveries
).
to
eq
[]
end
it
"should email new mentions with a watch level higher than participant"
do
send_notifications
(
@u_watcher
,
@u_participant_mentioned
)
should_email
(
@u_watcher
)
should_email
(
@u_participant_mentioned
)
expect
(
ActionMailer
::
Base
.
deliveries
.
count
).
to
eq
2
end
it
"should not email new mentions with a watch level equal to or less than participant"
do
send_notifications
(
@u_participating
,
@u_mentioned
)
expect
(
ActionMailer
::
Base
.
deliveries
).
to
eq
[]
end
end
describe
'#reassigned_merge_request'
do
before
do
update_custom_notification
(
:reassign_merge_request
,
@u_guest_custom
,
project
)
...
...
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