diff options
author | Robert Speicher <rspeicher@gmail.com> | 2016-10-02 14:55:21 +0200 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-10-02 14:55:21 +0200 |
commit | 9dd50b57ecb11b05db752c95a62d08f837ce46fd (patch) | |
tree | 501e0281e3cc097c8bd701a608810ce659969933 | |
parent | e64594ac4419a42b84f3ee36388f832e74361c8c (diff) | |
parent | 6e6f34bffb641ae698177055b8f3528ec41fb7c8 (diff) | |
download | gitlab-ce-9dd50b57ecb11b05db752c95a62d08f837ce46fd.tar.gz |
Merge branch 'jimmykarily/gitlab-ce-notify_current_user_when_merging_an_mr_after_build_succeeds' into 'master'
Notify current_user about automatic merge after successful build
It enables notifications to the initiator of a merge when the MR is flagged as "Merge when build succeeds".
Because when running Builds, quite some time passes between the user's
action and the actual Merge so it is a good thing to notify the
initiator of the Merge when it actually happens.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/14409
See merge request !6534
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/services/notification_service.rb | 14 | ||||
-rw-r--r-- | spec/services/notification_service_spec.rb | 14 |
3 files changed, 24 insertions, 5 deletions
diff --git a/CHANGELOG b/CHANGELOG index 54d6d8179c0..92de32d3f71 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -30,6 +30,7 @@ v 8.13.0 (unreleased) - Fix resolved discussion display in side-by-side diff view !6575 - Optimize GitHub importing for speed and memory - API: expose pipeline data in builds API (!6502, Guilherme Salazar) + - Notify the Merger about merge after successful build (Dimitris Karakasilis) - Fix broken repository 500 errors in project list - Close todos when accepting merge requests via the API !6486 (tonygambone) diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 6139ed56e25..2cc0c31d77d 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -134,7 +134,8 @@ class NotificationService merge_request, merge_request.target_project, current_user, - :merged_merge_request_email + :merged_merge_request_email, + skip_current_user: !merge_request.merge_when_build_succeeds? ) end @@ -514,9 +515,11 @@ class NotificationService end end - def close_resource_email(target, project, current_user, method) + def close_resource_email(target, project, current_user, method, skip_current_user: true) action = method == :merged_merge_request_email ? "merge" : "close" - recipients = build_recipients(target, project, current_user, action: action) + + recipients = build_recipients(target, project, current_user, action: action, + skip_current_user: skip_current_user) recipients.each do |recipient| mailer.send(method, recipient.id, target.id, current_user.id).deliver_later @@ -557,7 +560,7 @@ class NotificationService end end - def build_recipients(target, project, current_user, action: nil, previous_assignee: nil) + def build_recipients(target, project, current_user, action: nil, previous_assignee: nil, skip_current_user: true) custom_action = build_custom_key(action, target) recipients = target.participants(current_user) @@ -586,7 +589,8 @@ class NotificationService recipients = reject_unsubscribed_users(recipients, target) recipients = reject_users_without_access(recipients, target) - recipients.delete(current_user) + recipients.delete(current_user) if skip_current_user + recipients.uniq end diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 0d152534c38..d820646ebdf 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -962,6 +962,20 @@ describe NotificationService, services: true do should_not_email(@u_lazy_participant) end + it "notifies the merger when merge_when_build_succeeds is true" do + merge_request.merge_when_build_succeeds = true + notification.merge_mr(merge_request, @u_watcher) + + should_email(@u_watcher) + end + + it "does not notify the merger when merge_when_build_succeeds is false" do + merge_request.merge_when_build_succeeds = false + notification.merge_mr(merge_request, @u_watcher) + + should_not_email(@u_watcher) + end + context 'participating' do context 'by assignee' do before do |