Commit 919608cd authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'id-conditional-check-mergeability' into 'master'

Run check_mergeability only if merge status requires it

See merge request gitlab-org/gitlab!19364
parents 45b407a3 a15f05cf
......@@ -796,6 +796,8 @@ class MergeRequest < ApplicationRecord
end
def check_mergeability
return if Feature.enabled?(:merge_requests_conditional_mergeability_check, default_enabled: true) && !recheck_merge_status?
MergeRequests::MergeabilityCheckService.new(self).execute(retry_lease: false)
end
# rubocop: enable CodeReuse/ServiceClass
......
---
title: Run check_mergeability only if merge status requires it
merge_request: 19364
author:
type: performance
......@@ -2177,6 +2177,50 @@ describe MergeRequest do
end
end
describe '#check_mergeability' do
let(:mergeability_service) { double }
before do
allow(MergeRequests::MergeabilityCheckService).to receive(:new) do
mergeability_service
end
end
context 'if the merge status is unchecked' do
before do
subject.mark_as_unchecked!
end
it 'executes MergeabilityCheckService' do
expect(mergeability_service).to receive(:execute)
subject.check_mergeability
end
end
context 'if the merge status is checked' do
context 'and feature flag is enabled' do
it 'executes MergeabilityCheckService' do
expect(mergeability_service).not_to receive(:execute)
subject.check_mergeability
end
end
context 'and feature flag is disabled' do
before do
stub_feature_flags(merge_requests_conditional_mergeability_check: false)
end
it 'does not execute MergeabilityCheckService' do
expect(mergeability_service).to receive(:execute)
subject.check_mergeability
end
end
end
end
describe '#mergeable_state?' do
let(:project) { create(:project, :repository) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment