From 2c8510703cd0e99b4e1adc7740a124e7a2157def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Mon, 1 Apr 2019 20:44:58 +0200 Subject: Backport changes from EE This backports CE changes from https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/10521 --- app/models/ci/bridge.rb | 4 ++++ app/models/commit_status.rb | 2 +- lib/gitlab/ci/pipeline/seed/build.rb | 2 +- spec/factories/ci/bridge.rb | 10 +--------- spec/features/projects/pipelines/pipeline_spec.rb | 3 +-- spec/lib/gitlab/ci/pipeline/seed/build_spec.rb | 16 ++++++++-------- 6 files changed, 16 insertions(+), 21 deletions(-) diff --git a/app/models/ci/bridge.rb b/app/models/ci/bridge.rb index 0d8d7d95791..dac203b6f30 100644 --- a/app/models/ci/bridge.rb +++ b/app/models/ci/bridge.rb @@ -15,6 +15,10 @@ module Ci delegate :merge_request_event?, to: :pipeline + def self.fabricate(attributes) + ::Ci::Bridge.new(attributes) + end + def self.retry(bridge, current_user) raise NotImplementedError end diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index f97dc38dab7..48214c076d9 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -41,7 +41,7 @@ class CommitStatus < ApplicationRecord scope :latest_ordered, -> { latest.ordered.includes(project: :namespace) } scope :retried_ordered, -> { retried.ordered.includes(project: :namespace) } scope :after_stage, -> (index) { where('stage_idx > ?', index) } - scope :processables, -> { where(type: %w[Ci::Build Ci::Bridge]) } + scope :processables, -> { where(type: %w[Ci::Build Ci::Bridge Ci::Bridges::Downstream]) } # We use `CommitStatusEnums.failure_reasons` here so that EE can more easily # extend this `Hash` with new values. diff --git a/lib/gitlab/ci/pipeline/seed/build.rb b/lib/gitlab/ci/pipeline/seed/build.rb index d8296940a04..cefb1cc1182 100644 --- a/lib/gitlab/ci/pipeline/seed/build.rb +++ b/lib/gitlab/ci/pipeline/seed/build.rb @@ -45,7 +45,7 @@ module Gitlab def to_resource strong_memoize(:resource) do if bridge? - ::Ci::Bridge.new(attributes) + ::Ci::Bridge.fabricate(attributes) else ::Ci::Build.new(attributes) end diff --git a/spec/factories/ci/bridge.rb b/spec/factories/ci/bridge.rb index b1d82b98411..183f2399ba5 100644 --- a/spec/factories/ci/bridge.rb +++ b/spec/factories/ci/bridge.rb @@ -14,16 +14,8 @@ FactoryBot.define do yaml_variables [{ key: 'BRIDGE', value: 'cross', public: true }] end - transient { downstream nil } - - after(:build) do |bridge, evaluator| + after(:build) do |bridge, _| bridge.project ||= bridge.pipeline.project - - if evaluator.downstream.present? - bridge.options = bridge.options.to_h.merge( - trigger: { project: evaluator.downstream.full_path } - ) - end end end end diff --git a/spec/features/projects/pipelines/pipeline_spec.rb b/spec/features/projects/pipelines/pipeline_spec.rb index b197557039d..0de5d50df59 100644 --- a/spec/features/projects/pipelines/pipeline_spec.rb +++ b/spec/features/projects/pipelines/pipeline_spec.rb @@ -476,8 +476,7 @@ describe 'Pipeline', :js do let!(:bridge) do create(:ci_bridge, pipeline: pipeline, name: 'cross-build', - user: user, - downstream: downstream) + user: user) end describe 'GET /:project/pipelines/:id' do diff --git a/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb index fae8add6453..d2f53780344 100644 --- a/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb @@ -21,20 +21,20 @@ describe Gitlab::Ci::Pipeline::Seed::Build do end describe '#bridge?' do - context 'when job is a bridge' do + context 'when job is a downstream bridge' do let(:attributes) do { name: 'rspec', ref: 'master', options: { trigger: 'my/project' } } end it { is_expected.to be_bridge } - end - context 'when trigger definition is empty' do - let(:attributes) do - { name: 'rspec', ref: 'master', options: { trigger: '' } } - end + context 'when trigger definition is empty' do + let(:attributes) do + { name: 'rspec', ref: 'master', options: { trigger: '' } } + end - it { is_expected.not_to be_bridge } + it { is_expected.not_to be_bridge } + end end context 'when job is not a bridge' do @@ -50,7 +50,7 @@ describe Gitlab::Ci::Pipeline::Seed::Build do end end - context 'when job is a bridge' do + context 'when job is a downstream bridge' do let(:attributes) do { name: 'rspec', ref: 'master', options: { trigger: 'my/project' } } end -- cgit v1.2.1