summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOswaldo Ferreira <oswaldo@gitlab.com>2019-06-21 11:30:09 -0300
committerOswaldo Ferreira <oswaldo@gitlab.com>2019-06-21 11:30:09 -0300
commit74a3e6b71254409d423077987f6961ea17ba00d9 (patch)
tree363623559c3f289ce55beec3a6f5b2c363a563f8
parent710a660ec3a76d34b9bf69e2a8c9afd51454efa7 (diff)
downloadgitlab-ce-74a3e6b71254409d423077987f6961ea17ba00d9.tar.gz
Avoid touching the MR status if MR is not opened
-rw-r--r--app/models/merge_request.rb4
-rw-r--r--app/services/merge_requests/mergeability_check_service.rb11
-rw-r--r--spec/services/merge_requests/mergeability_check_service_spec.rb24
3 files changed, 34 insertions, 5 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index f12b44ec0c9..df2dc9c49eb 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -231,10 +231,6 @@ class MergeRequest < ApplicationRecord
end
end
- def merge_ref_auto_sync_enabled?
- Feature.enabled?(:merge_ref_auto_sync, project, default_enabled: true)
- end
-
# 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
diff --git a/app/services/merge_requests/mergeability_check_service.rb b/app/services/merge_requests/mergeability_check_service.rb
index faa38eda61e..9fa50c9448f 100644
--- a/app/services/merge_requests/mergeability_check_service.rb
+++ b/app/services/merge_requests/mergeability_check_service.rb
@@ -4,7 +4,7 @@ module MergeRequests
class MergeabilityCheckService < ::BaseService
include Gitlab::Utils::StrongMemoize
- delegate :project, :merge_ref_auto_sync_enabled?, to: :@merge_request
+ delegate :project, to: :@merge_request
delegate :repository, to: :project
def initialize(merge_request)
@@ -39,6 +39,10 @@ module MergeRequests
return ServiceResponse.error(message: 'Merge ref is outdated due to disabled feature')
end
+ unless payload.fetch(:merge_ref_head)
+ return ServiceResponse.error(message: 'Merge ref cannot be updated')
+ end
+
ServiceResponse.success(payload: payload)
end
@@ -89,6 +93,7 @@ module MergeRequests
# Returns true if the merge-ref does not exists or is out of sync.
def outdated_merge_ref?
return false unless merge_ref_auto_sync_enabled?
+ return false unless merge_request.open?
return true unless ref_head = merge_request.merge_ref_head
return true unless target_sha = merge_request.target_branch_sha
@@ -107,5 +112,9 @@ module MergeRequests
result = MergeRequests::MergeToRefService.new(project, merge_request.author).execute(merge_request)
result[:status] == :success
end
+
+ def merge_ref_auto_sync_enabled?
+ Feature.enabled?(:merge_ref_auto_sync, project, default_enabled: true)
+ end
end
end
diff --git a/spec/services/merge_requests/mergeability_check_service_spec.rb b/spec/services/merge_requests/mergeability_check_service_spec.rb
index 6c04e816b91..6efece64092 100644
--- a/spec/services/merge_requests/mergeability_check_service_spec.rb
+++ b/spec/services/merge_requests/mergeability_check_service_spec.rb
@@ -228,6 +228,30 @@ describe MergeRequests::MergeabilityCheckService do
end
end
+ context 'when MR is marked as mergeable, but repo is not mergeable and MR is not opened' do
+ before do
+ # Making sure that we don't touch the merge-status after
+ # the MR is not opened any longer. Source branch might
+ # have been removed, etc.
+ allow(merge_request).to receive(:broken?) { true }
+ merge_request.mark_as_mergeable!
+ merge_request.close!
+ end
+
+ it 'returns ServiceResponse.error' do
+ result = subject
+
+ expect(result).to be_a(ServiceResponse)
+ expect(result.error?).to be(true)
+ expect(result.message).to eq('Merge ref cannot be updated')
+ expect(result.payload).to be_empty
+ end
+
+ it 'does not change the merge status' do
+ expect { subject }.not_to change(merge_request, :merge_status).from('can_be_merged')
+ end
+ end
+
context 'when MR is mergeable but merge-ref does not exists' do
before do
merge_request.mark_as_mergeable!