Skip to content
Snippets Groups Projects
Commit 07a5f7bd authored by drew's avatar drew Committed by drew stachon
Browse files

Move pipeline-success MergeRequest querying into AutoMergeProcessWorker

parent ee242e73
No related branches found
No related tags found
1 merge request!167095Move completed pipeline merge request querying into AutoMergeProcessWorker
......@@ -324,9 +324,7 @@ class Pipeline < Ci::ApplicationRecord
after_transition any => ::Ci::Pipeline.completed_statuses do |pipeline|
pipeline.run_after_commit do
pipeline.all_merge_requests.with_auto_merge_enabled.each do |merge_request|
AutoMergeProcessWorker.perform_async(merge_request.id)
end
AutoMergeProcessWorker.perform_async({ 'pipeline_id' => self.id })
if pipeline.auto_devops_source?
self.class.auto_devops_pipelines_completed_total.increment(status: pipeline.status)
......
......@@ -12,7 +12,7 @@ def execute(merge_request)
end
notify(merge_request)
AutoMergeProcessWorker.perform_async(merge_request.id)
AutoMergeProcessWorker.perform_async({ 'merge_request_id' => merge_request.id })
strategy.to_sym
rescue StandardError => e
......
......@@ -90,7 +90,7 @@ def process_auto_merge
)
)
else
AutoMergeProcessWorker.perform_async(merge_request.id)
AutoMergeProcessWorker.perform_async({ 'merge_request_id' => merge_request.id })
end
end
......
......@@ -1830,7 +1830,7 @@ def create_build(name, status)
%w[succeed! drop! cancel! skip!].each do |action|
context "when the pipeline received #{action} event" do
it 'performs AutoMergeProcessWorker' do
expect(AutoMergeProcessWorker).to receive(:perform_async).with(merge_request.id)
expect(AutoMergeProcessWorker).to receive(:perform_async).with({ 'pipeline_id' => pipeline.id })
pipeline.public_send(action)
end
......@@ -1841,8 +1841,11 @@ def create_build(name, status)
context 'when auto merge is not enabled in the merge request' do
let(:merge_request) { create(:merge_request) }
# We enqueue the job here because the check for whether or not to
# automatically merge happens in the worker itself.
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/167095
it 'performs AutoMergeProcessWorker' do
expect(AutoMergeProcessWorker).not_to receive(:perform_async)
expect(AutoMergeProcessWorker).to receive(:perform_async).with({ 'pipeline_id' => pipeline.id })
pipeline.succeed!
end
......
......@@ -76,7 +76,7 @@
end
it 'calls AutoMergeProcessWorker' do
expect(AutoMergeProcessWorker).to receive(:perform_async).with(merge_request.id).once
expect(AutoMergeProcessWorker).to receive(:perform_async).with({ 'merge_request_id' => merge_request.id }).once
subject
end
......
......@@ -20,7 +20,17 @@
end
end
context 'when a pipeline is passed with auto mergeable MRs' do
context 'when merge request is not found' do
let(:args) { { 'merge_request_id' => -1 } }
it 'does not execute AutoMergeService' do
expect(AutoMergeService).not_to receive(:new)
subject
end
end
context 'when a pipeline is passed with auto mergeable MRs', :aggregate_failures do
let(:merge_service) { instance_double(AutoMergeService, process: true) }
let(:mwps_merge_request) { create(:merge_request, :with_head_pipeline, :merge_when_pipeline_succeeds) }
let(:mwcp_merge_request) { create(:merge_request, :with_head_pipeline, :merge_when_checks_pass) }
......@@ -43,8 +53,8 @@
end
end
context 'when merge request is not found' do
let(:args) { { 'merge_request_id' => -1 } }
context 'when pipeline is not found' do
let(:args) { { 'pipeline_id' => -1 } }
it 'does not execute AutoMergeService' do
expect(AutoMergeService).not_to receive(:new)
......@@ -65,6 +75,7 @@
# Integer args are deprecated as of 17.5. IDs should be passed
# as a hash with merge_request_id and pipeline_id keys.
# https://gitlab.com/gitlab-org/gitlab/-/issues/497247
context 'with integer args' do
let(:args) { merge_request.id }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment