summaryrefslogtreecommitdiff
path: root/app/models/merge_request.rb
diff options
context:
space:
mode:
authorMark Chao <mchao@gitlab.com>2018-06-07 23:56:59 +0900
committerMark Chao <mchao@gitlab.com>2018-06-20 23:27:17 +0800
commit5b994b8199a3679b6f5ef0d00edce22ea9662664 (patch)
tree6574c99eb3b963d0518e079f041552bb10367756 /app/models/merge_request.rb
parent222284a6bf9348b30b5ce2b1b04370163e2120e5 (diff)
downloadgitlab-ce-5b994b8199a3679b6f5ef0d00edce22ea9662664.tar.gz
Notify only when unmergeable due to conflict
There is still the edge case when 'no commits' changes to 'conflict' would not trigger notification, which we ignore for now. Calling can_be_merged? can cause exception (e.g. non-UTF8) Ignore those by rescueing. Remove unmergeable_reason as now only conflict is notified Update spec
Diffstat (limited to 'app/models/merge_request.rb')
-rw-r--r--app/models/merge_request.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 324065c1162..4b78ba1029f 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -128,8 +128,17 @@ class MergeRequest < ActiveRecord::Base
end
after_transition unchecked: :cannot_be_merged do |merge_request, transition|
- NotificationService.new.merge_request_unmergeable(merge_request)
- TodoService.new.merge_request_became_unmergeable(merge_request)
+ begin
+ # Merge request can become unmergeable due to many reasons.
+ # We only notify if it is due to conflict.
+ unless merge_request.project.repository.can_be_merged?(merge_request.diff_head_sha, merge_request.target_branch)
+ NotificationService.new.merge_request_unmergeable(merge_request)
+ TodoService.new.merge_request_became_unmergeable(merge_request)
+ end
+ rescue Gitlab::Git::CommandError
+ # Checking mergeability can trigger exception, e.g. non-utf8
+ # We ignore this type of errors.
+ end
end
def check_state?(merge_status)