Commit cd584108 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Remove support for branch-less builds in MWBS

See !6675#note_16580143
parent 9824a69c
...@@ -42,20 +42,19 @@ module MergeRequests ...@@ -42,20 +42,19 @@ module MergeRequests
super(:merge_request) super(:merge_request)
end end
def merge_requests_for(branches, sha) def merge_requests_for(branch)
# This is for ref-less builds origin_merge_requests = @project.origin_merge_requests
branches ||= @project.repository.branch_names_contains(sha) .opened.where(source_branch: branch).to_a
return [] if branches.blank? fork_merge_requests = @project.fork_merge_requests
.opened.where(source_branch: branch).to_a
merge_requests = @project.origin_merge_requests.opened.where(source_branch: branches).to_a (origin_merge_requests + fork_merge_requests)
merge_requests += @project.fork_merge_requests.opened.where(source_branch: branches).to_a .uniq.select(&:source_project)
merge_requests.uniq.select(&:source_project)
end end
def pipeline_merge_requests(pipeline) def pipeline_merge_requests(pipeline)
merge_requests_for(pipeline.ref, pipeline.sha).each do |merge_request| merge_requests_for(pipeline.ref).each do |merge_request|
next unless pipeline == merge_request.pipeline next unless pipeline == merge_request.pipeline
yield merge_request yield merge_request
...@@ -63,8 +62,9 @@ module MergeRequests ...@@ -63,8 +62,9 @@ module MergeRequests
end end
def commit_status_merge_requests(commit_status) def commit_status_merge_requests(commit_status)
merge_requests_for(commit_status.ref, commit_status.sha).each do |merge_request| merge_requests_for(commit_status.ref).each do |merge_request|
pipeline = merge_request.pipeline pipeline = merge_request.pipeline
next unless pipeline next unless pipeline
next unless pipeline.sha == commit_status.sha next unless pipeline.sha == commit_status.sha
......
...@@ -97,20 +97,9 @@ describe MergeRequests::MergeWhenBuildSucceedsService do ...@@ -97,20 +97,9 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
expect(MergeWorker).not_to receive(:perform_async) expect(MergeWorker).not_to receive(:perform_async)
service.trigger(unrelated_pipeline) service.trigger(unrelated_pipeline)
end end
it 'discovers branches and merges all merge requests when status is success' do
allow(project.repository).to receive(:branch_names_contains).
with(commit_status.sha).and_return([mr_merge_if_green_enabled.source_branch])
allow(pipeline).to receive(:success?).and_return(true)
allow_any_instance_of(MergeRequest).to receive(:pipeline).and_return(pipeline)
allow(pipeline).to receive(:success?).and_return(true)
expect(MergeWorker).to receive(:perform_async)
service.trigger(commit_status)
end
end end
context 'properly handles multiple stages' do context 'when there are multiple stages in the pipeline' do
let(:ref) { mr_merge_if_green_enabled.source_branch } let(:ref) { mr_merge_if_green_enabled.source_branch }
let!(:build) { create(:ci_build, :created, pipeline: pipeline, ref: ref, name: 'build', stage: 'build') } let!(:build) { create(:ci_build, :created, pipeline: pipeline, ref: ref, name: 'build', stage: 'build') }
let!(:test) { create(:ci_build, :created, pipeline: pipeline, ref: ref, name: 'test', stage: 'test') } let!(:test) { create(:ci_build, :created, pipeline: pipeline, ref: ref, name: 'test', stage: 'test') }
......
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