Commit e3b1f510 authored by drew's avatar drew Committed by Mayra Cabrera

Moving EE Pipeline code into EE::Ci::Pipeline

- Moved the :merge_train logic branch of
  Ci::Pipeline#merge_request_event_type into EE
- Added specs for EE::Ci::Pipeline to include base and EE cases
parent 941a10e4
...@@ -772,18 +772,10 @@ module Ci ...@@ -772,18 +772,10 @@ module Ci
triggered_by_merge_request? && target_sha.present? triggered_by_merge_request? && target_sha.present?
end end
def merge_train_pipeline?
merge_request_pipeline? && merge_train_ref?
end
def merge_request_ref? def merge_request_ref?
MergeRequest.merge_request_ref?(ref) MergeRequest.merge_request_ref?(ref)
end end
def merge_train_ref?
MergeRequest.merge_train_ref?(ref)
end
def matches_sha_or_source_sha?(sha) def matches_sha_or_source_sha?(sha)
self.sha == sha || self.source_sha == sha self.sha == sha || self.source_sha == sha
end end
...@@ -816,9 +808,7 @@ module Ci ...@@ -816,9 +808,7 @@ module Ci
return unless merge_request_event? return unless merge_request_event?
strong_memoize(:merge_request_event_type) do strong_memoize(:merge_request_event_type) do
if merge_train_pipeline? if merge_request_pipeline?
:merge_train
elsif merge_request_pipeline?
:merged_result :merged_result
elsif detached_merge_request_pipeline? elsif detached_merge_request_pipeline?
:detached :detached
......
...@@ -4,6 +4,7 @@ module EE ...@@ -4,6 +4,7 @@ module EE
module Ci module Ci
module Pipeline module Pipeline
extend ActiveSupport::Concern extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
BridgeStatusError = Class.new(StandardError) BridgeStatusError = Class.new(StandardError)
...@@ -167,8 +168,25 @@ module EE ...@@ -167,8 +168,25 @@ module EE
target_sha == merge_request.target_branch_sha target_sha == merge_request.target_branch_sha
end end
override :merge_request_event_type
def merge_request_event_type
return unless merge_request_event?
strong_memoize(:merge_request_event_type) do
merge_train_pipeline? ? :merge_train : super
end
end
def merge_train_pipeline?
merge_request_pipeline? && merge_train_ref?
end
private private
def merge_train_ref?
::MergeRequest.merge_train_ref?(ref)
end
# This batch loads the latest reports for each CI job artifact # This batch loads the latest reports for each CI job artifact
# type (e.g. sast, dast, etc.) in a single SQL query to eliminate # type (e.g. sast, dast, etc.) in a single SQL query to eliminate
# the need to do N different `job_artifacts.where(file_type: # the need to do N different `job_artifacts.where(file_type:
......
...@@ -521,4 +521,47 @@ describe Ci::Pipeline do ...@@ -521,4 +521,47 @@ describe Ci::Pipeline do
it { is_expected.to be false } it { is_expected.to be false }
end end
end end
describe '#merge_train_pipeline?' do
subject { pipeline.merge_train_pipeline? }
let!(:pipeline) do
create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, ref: ref, target_sha: 'xxx')
end
let(:merge_request) { create(:merge_request) }
let(:ref) { 'refs/merge-requests/1/train' }
it { is_expected.to be_truthy }
context 'when ref is merge ref' do
let(:ref) { 'refs/merge-requests/1/merge' }
it { is_expected.to be_falsy }
end
end
describe '#merge_request_event_type' do
subject { pipeline.merge_request_event_type }
let(:pipeline) { merge_request.all_pipelines.last }
context 'when pipeline is merge train pipeline' do
let(:merge_request) { create(:merge_request, :with_merge_train_pipeline) }
it { is_expected.to eq(:merge_train) }
end
context 'when pipeline is merge request pipeline' do
let(:merge_request) { create(:merge_request, :with_merge_request_pipeline) }
it { is_expected.to eq(:merged_result) }
end
context 'when pipeline is detached merge request pipeline' do
let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) }
it { is_expected.to eq(:detached) }
end
end
end end
...@@ -199,25 +199,6 @@ describe Ci::Pipeline, :mailer do ...@@ -199,25 +199,6 @@ describe Ci::Pipeline, :mailer do
end end
end end
describe '#merge_train_pipeline?' do
subject { pipeline.merge_train_pipeline? }
let!(:pipeline) do
create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, ref: ref, target_sha: 'xxx')
end
let(:merge_request) { create(:merge_request) }
let(:ref) { 'refs/merge-requests/1/train' }
it { is_expected.to be_truthy }
context 'when ref is merge ref' do
let(:ref) { 'refs/merge-requests/1/merge' }
it { is_expected.to be_falsy }
end
end
describe '#merge_request_ref?' do describe '#merge_request_ref?' do
subject { pipeline.merge_request_ref? } subject { pipeline.merge_request_ref? }
...@@ -228,43 +209,19 @@ describe Ci::Pipeline, :mailer do ...@@ -228,43 +209,19 @@ describe Ci::Pipeline, :mailer do
end end
end end
describe '#merge_train_ref?' do
subject { pipeline.merge_train_ref? }
it 'calls Mergetrain#merge_train_ref?' do
expect(MergeRequest).to receive(:merge_train_ref?).with(pipeline.ref)
subject
end
end
describe '#merge_request_event_type' do describe '#merge_request_event_type' do
subject { pipeline.merge_request_event_type } subject { pipeline.merge_request_event_type }
before do let(:pipeline) { merge_request.all_pipelines.last }
allow(pipeline).to receive(:merge_request_event?) { true }
end
context 'when pipeline is merge train pipeline' do
before do
allow(pipeline).to receive(:merge_train_pipeline?) { true }
end
it { is_expected.to eq(:merge_train) }
end
context 'when pipeline is merge request pipeline' do context 'when pipeline is merge request pipeline' do
before do let(:merge_request) { create(:merge_request, :with_merge_request_pipeline) }
allow(pipeline).to receive(:merge_request_pipeline?) { true }
end
it { is_expected.to eq(:merged_result) } it { is_expected.to eq(:merged_result) }
end end
context 'when pipeline is detached merge request pipeline' do context 'when pipeline is detached merge request pipeline' do
before do let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) }
allow(pipeline).to receive(:detached_merge_request_pipeline?) { true }
end
it { is_expected.to eq(:detached) } it { is_expected.to eq(:detached) }
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