Commit 5818cf063bda5f6a96ccefe086b64a3699dd2c67

Authored by Pierre de La Morinerie
1 parent aff7ac37

Don't send an email for "mentioned in" notes

Currently, an email is sent every time a mentionable is referenced
by an issue, a commit or a merge request: if I comment "This MR is
related to #5", watchers get one email for the comment, and another
one stating "Issue #5 was mentioned by issue #13".

This is annoying — but the biggest issue is when pushing an existing
branch. Every issue referenced by commit messages in this branch will
get a new mention (which is fine), and dozens of emails will be sent
for all these new mentions (which is not).

This commit fixes the spam by avoiding to send an email when a new
mention is created. In most cases the email notification for the
mentioner is enough.
app/services/notification_service.rb
... ... @@ -111,6 +111,7 @@ class NotificationService
111 111  
112 112 # ignore gitlab service messages
113 113 return true if note.note =~ /\A_Status changed to closed_/
  114 + return true if note.note =~ /\A_mentioned in / && note.system == true
114 115  
115 116 opts = { noteable_type: note.noteable_type, project_id: note.project_id }
116 117  
... ...
spec/services/notification_service_spec.rb
... ... @@ -32,6 +32,7 @@ describe NotificationService do
32 32 describe 'Notes' do
33 33 context 'issue note' do
34 34 let(:issue) { create(:issue, assignee: create(:user)) }
  35 + let(:mentioned_issue) { create(:issue, assignee: issue.assignee) }
35 36 let(:note) { create(:note_on_issue, noteable: issue, project_id: issue.project_id, note: '@mention referenced') }
36 37  
37 38 before do
... ... @@ -50,6 +51,13 @@ describe NotificationService do
50 51 notification.new_note(note)
51 52 end
52 53  
  54 + it 'filters out "mentioned in" notes' do
  55 + mentioned_note = Note.create_cross_reference_note(mentioned_issue, issue, issue.author, issue.project)
  56 +
  57 + Notify.should_not_receive(:note_issue_email)
  58 + notification.new_note(mentioned_note)
  59 + end
  60 +
53 61 def should_email(user_id)
54 62 Notify.should_receive(:note_issue_email).with(user_id, note.id)
55 63 end
... ...