Commit 7fbb8e8d authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab-ce master

parents a72e3410 0b864208
......@@ -166,6 +166,16 @@ module Ci
end
end
after_transition any => ::Ci::Pipeline.completed_statuses do |pipeline|
pipeline.run_after_commit do
pipeline.all_merge_requests.each do |merge_request|
next unless merge_request.auto_merge_enabled?
AutoMergeProcessWorker.perform_async(merge_request.id)
end
end
end
after_transition any => [:success, :failed] do |pipeline|
pipeline.run_after_commit do
PipelineNotificationWorker.perform_async(pipeline.id)
......
---
- auto_devops:auto_devops_disable
- auto_merge:auto_merge_process
- cronjob:admin_email
- cronjob:expire_build_artifacts
- cronjob:gitlab_usage_ping
......
# frozen_string_literal: true
class AutoMergeProcessWorker
include ApplicationWorker
queue_namespace :auto_merge
def perform(merge_request_id)
MergeRequest.find_by_id(merge_request_id).try do |merge_request|
AutoMergeService.new(merge_request.project, merge_request.merge_user)
.process(merge_request)
end
end
end
......@@ -6,14 +6,7 @@ class PipelineSuccessWorker
queue_namespace :pipeline_processing
# rubocop: disable CodeReuse/ActiveRecord
def perform(pipeline_id)
Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline|
pipeline.all_merge_requests.preload(:merge_user).each do |merge_request|
AutoMergeService.new(pipeline.project, merge_request.merge_user)
.process(merge_request)
end
end
# no-op
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -30,6 +30,7 @@
- [pipeline_default, 3]
- [pipeline_cache, 3]
- [deployment, 3]
- [auto_merge, 3]
- [pipeline_hooks, 2]
- [gitlab_shell, 2]
- [email_receiver, 2]
......
......@@ -1381,6 +1381,40 @@ describe Ci::Pipeline, :mailer do
end
end
describe 'auto merge' do
let(:merge_request) { create(:merge_request, :merge_when_pipeline_succeeds) }
let(:pipeline) do
create(:ci_pipeline, :running, project: merge_request.source_project,
ref: merge_request.source_branch,
sha: merge_request.diff_head_sha)
end
before do
merge_request.update_head_pipeline
end
%w[succeed! drop! cancel! skip!].each do |action|
context "when the pipeline recieved #{action} event" do
it 'performs AutoMergeProcessWorker' do
expect(AutoMergeProcessWorker).to receive(:perform_async).with(merge_request.id)
pipeline.public_send(action)
end
end
end
context 'when auto merge is not enabled in the merge request' do
let(:merge_request) { create(:merge_request) }
it 'performs AutoMergeProcessWorker' do
expect(AutoMergeProcessWorker).not_to receive(:perform_async)
pipeline.succeed!
end
end
end
def create_build(name, *traits, queued_at: current, started_from: 0, **opts)
create(:ci_build, *traits,
name: name,
......
......@@ -2,25 +2,29 @@
require 'spec_helper'
describe PipelineSuccessWorker do
describe AutoMergeProcessWorker do
describe '#perform' do
context 'when pipeline exists' do
let(:pipeline) { create(:ci_pipeline, status: 'success', ref: merge_request.source_branch, project: merge_request.source_project) }
subject { described_class.new.perform(merge_request&.id) }
context 'when merge request is found' do
let(:merge_request) { create(:merge_request) }
it 'performs "merge when pipeline succeeds"' do
it 'executes AutoMergeService' do
expect_next_instance_of(AutoMergeService) do |auto_merge|
expect(auto_merge).to receive(:process)
end
described_class.new.perform(pipeline.id)
subject
end
end
context 'when pipeline does not exist' do
it 'does not raise exception' do
expect { described_class.new.perform(123) }
.not_to raise_error
context 'when merge request is not found' do
let(:merge_request) { nil }
it 'does not execute AutoMergeService' do
expect(AutoMergeService).not_to receive(:new)
subject
end
end
end
......
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