diff options
author | Douwe Maan <douwe@gitlab.com> | 2019-06-03 19:29:41 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2019-06-03 19:29:41 +0300 |
commit | 96ff9c6bd82a6eb60b9f2d1c20fca0105ed4160d (patch) | |
tree | 7e6025b6d502befb5bc973a42ae02519f5c523aa /app/models/merge_request.rb | |
parent | a9589cdf28bc789e0b4902e3d45acfc9a6b69217 (diff) | |
parent | 4246a62118d919e62b94d75eba641ed374c3f241 (diff) |
Merge branch 'osw-sync-merge-ref-upon-mergeability-check' into 'master'
Automatically update MR merge-ref along merge status
Closes #58495
See merge request gitlab-org/gitlab-ce!28513
Diffstat (limited to 'app/models/merge_request.rb')
-rw-r--r-- | app/models/merge_request.rb | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index ab914e84650..59416fb4b51 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -725,19 +725,16 @@ class MergeRequest < ApplicationRecord MergeRequests::ReloadDiffsService.new(self, current_user).execute end - # rubocop: enable CodeReuse/ServiceClass - - def check_if_can_be_merged - return unless self.class.state_machines[:merge_status].check_state?(merge_status) && Gitlab::Database.read_write? - can_be_merged = - !broken? && project.repository.can_be_merged?(diff_head_sha, target_branch) + def check_mergeability + MergeRequests::MergeabilityCheckService.new(self).execute + end + # rubocop: enable CodeReuse/ServiceClass - if can_be_merged - mark_as_mergeable - else - mark_as_unmergeable - end + # Returns boolean indicating the merge_status should be rechecked in order to + # switch to either can_be_merged or cannot_be_merged. + def recheck_merge_status? + self.class.state_machines[:merge_status].check_state?(merge_status) end def merge_event @@ -763,7 +760,7 @@ class MergeRequest < ApplicationRecord def mergeable?(skip_ci_check: false) return false unless mergeable_state?(skip_ci_check: skip_ci_check) - check_if_can_be_merged + check_mergeability can_be_merged? && !should_be_rebased? end @@ -778,15 +775,6 @@ class MergeRequest < ApplicationRecord true end - def mergeable_to_ref? - return false unless mergeable_state?(skip_ci_check: true, skip_discussions_check: true) - - # Given the `merge_ref_path` will have the same - # state the `target_branch` would have. Ideally - # we need to check if it can be merged to it. - project.repository.can_be_merged?(diff_head_sha, target_branch) - end - def ff_merge_possible? project.repository.ancestor?(target_branch_sha, diff_head_sha) end @@ -1114,6 +1102,12 @@ class MergeRequest < ApplicationRecord target_project.repository.fetch_source_branch!(source_project.repository, source_branch, ref_path) end + # Returns the current merge-ref HEAD commit. + # + def merge_ref_head + project.repository.commit(merge_ref_path) + end + def ref_path "refs/#{Repository::REF_MERGE_REQUEST}/#{iid}/head" end |