summaryrefslogtreecommitdiff
path: root/app/models/merge_request.rb
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2017-11-30 16:00:09 -0200
committerFelipe Artur <felipefac@gmail.com>2017-12-05 12:54:10 -0200
commitf586dc0735545d96d73dd26ff182ddf2d50dd715 (patch)
treeaf3c7a732cf23b94033e071edcd73fe689714238 /app/models/merge_request.rb
parent8f78ba554d8cc7ff90a0f1c98b6f641afbc5b4ae (diff)
downloadgitlab-ce-f586dc0735545d96d73dd26ff182ddf2d50dd715.tar.gz
Check if head_pipeline is correct before merging
Diffstat (limited to 'app/models/merge_request.rb')
-rw-r--r--app/models/merge_request.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index b9158d3c863..536ad05a43d 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -145,8 +145,11 @@ class MergeRequest < ActiveRecord::Base
'!'
end
- def head_pipeline
- super&.sha == diff_head_sha ? super : nil
+ # Use this method whenever you need to make sure the head_pipeline is synced with the
+ # branch head commit, for example checking if a merge request can be merged.
+ # For more information check: https://gitlab.com/gitlab-org/gitlab-ce/issues/40004
+ def current_head_pipeline
+ head_pipeline&.sha == diff_head_sha ? head_pipeline : nil
end
# Pattern used to extract `!123` merge request references from text
@@ -826,8 +829,9 @@ class MergeRequest < ActiveRecord::Base
def mergeable_ci_state?
return true unless project.only_allow_merge_if_pipeline_succeeds?
+ return true unless head_pipeline
- !head_pipeline || head_pipeline.success? || head_pipeline.skipped?
+ current_head_pipeline&.success? || current_head_pipeline&.skipped?
end
def environments_for(current_user)
@@ -1001,7 +1005,7 @@ class MergeRequest < ActiveRecord::Base
return true if autocomplete_precheck
return false unless mergeable?(skip_ci_check: true)
- return false if head_pipeline && !(head_pipeline.success? || head_pipeline.active?)
+ return false if current_head_pipeline && !(current_head_pipeline.success? || current_head_pipeline.active?)
return false if last_diff_sha != diff_head_sha
true