diff options
author | Matija Čupić <matteeyah@gmail.com> | 2019-03-25 00:49:33 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2019-03-25 03:05:53 +0100 |
commit | 4c90f97f72a6934315575ef97d3c17752cbb8342 (patch) | |
tree | c6bef462a3d96f2082d2e5886c8111740ffea20d | |
parent | 83153e65a5249fc16c07a54b9db906a4301c76cd (diff) | |
download | gitlab-ce-9045-cross-project-triggered-by-mvc-2-ce.tar.gz |
Backport EE changes9045-cross-project-triggered-by-mvc-2-ce
This backports the CE changes from https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/9805
-rw-r--r-- | app/models/ci/bridge.rb | 4 | ||||
-rw-r--r-- | app/models/commit_status.rb | 6 | ||||
-rw-r--r-- | app/services/ci/create_pipeline_service.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/chain/populate_source_project.rb | 19 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/seed/build.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/ci/yaml_processor.rb | 3 | ||||
-rw-r--r-- | spec/factories/ci/bridge.rb | 10 | ||||
-rw-r--r-- | spec/features/projects/pipelines/pipeline_spec.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/pipeline/seed/build_spec.rb | 47 |
9 files changed, 76 insertions, 23 deletions
diff --git a/app/models/ci/bridge.rb b/app/models/ci/bridge.rb index 0d8d7d95791..e382ea323a8 100644 --- a/app/models/ci/bridge.rb +++ b/app/models/ci/bridge.rb @@ -19,6 +19,10 @@ module Ci raise NotImplementedError end + def self.fabricate(attributes) + ::Ci::Bridge.new(attributes) + end + def tags [:bridge] end diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 5f66a661324..c4b0136785b 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -41,7 +41,7 @@ class CommitStatus < ActiveRecord::Base 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: processable_types) } # We use `CommitStatusEnums.failure_reasons` here so that EE can more easily # extend this `Hash` with new values. @@ -139,6 +139,10 @@ class CommitStatus < ActiveRecord::Base end end + def self.processable_types + %w[Ci::Build Ci::Bridge] + end + def locking_enabled? status_changed? end diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index 8973c5ffc9e..c154aad3c72 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -14,6 +14,7 @@ module Ci Gitlab::Ci::Pipeline::Chain::Skip, Gitlab::Ci::Pipeline::Chain::Limit::Size, Gitlab::Ci::Pipeline::Chain::Populate, + Gitlab::Ci::Pipeline::Chain::PopulateSourceProject, Gitlab::Ci::Pipeline::Chain::Create, Gitlab::Ci::Pipeline::Chain::Limit::Activity].freeze diff --git a/lib/gitlab/ci/pipeline/chain/populate_source_project.rb b/lib/gitlab/ci/pipeline/chain/populate_source_project.rb new file mode 100644 index 00000000000..887211ed8eb --- /dev/null +++ b/lib/gitlab/ci/pipeline/chain/populate_source_project.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Gitlab + module Ci + module Pipeline + module Chain + class PopulateSourceProject < Chain::Base + def perform! + # to be overriden in EE + end + + def break? + false # to be overriden in EE + end + end + end + end + end +end diff --git a/lib/gitlab/ci/pipeline/seed/build.rb b/lib/gitlab/ci/pipeline/seed/build.rb index d8296940a04..65d1320534d 100644 --- a/lib/gitlab/ci/pipeline/seed/build.rb +++ b/lib/gitlab/ci/pipeline/seed/build.rb @@ -39,13 +39,15 @@ module Gitlab end def bridge? - @attributes.to_h.dig(:options, :trigger).present? + hash_attributes = @attributes.to_h + hash_attributes.dig(:options, :trigger).present? || + hash_attributes.dig(:options, :triggered_by).present? end 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/lib/gitlab/ci/yaml_processor.rb b/lib/gitlab/ci/yaml_processor.rb index 07ba6f83d47..32365f44955 100644 --- a/lib/gitlab/ci/yaml_processor.rb +++ b/lib/gitlab/ci/yaml_processor.rb @@ -54,7 +54,8 @@ module Gitlab parallel: job[:parallel], instance: job[:instance], start_in: job[:start_in], - trigger: job[:trigger] + trigger: job[:trigger], + triggered_by: job[:triggered_by] }.compact }.compact 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 9fdf78baa1e..aecbbb6e3d8 100644 --- a/spec/features/projects/pipelines/pipeline_spec.rb +++ b/spec/features/projects/pipelines/pipeline_spec.rb @@ -444,8 +444,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..ee77cfd6842 100644 --- a/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb @@ -22,11 +22,21 @@ describe Gitlab::Ci::Pipeline::Seed::Build do describe '#bridge?' do context 'when job is a bridge' do - let(:attributes) do - { name: 'rspec', ref: 'master', options: { trigger: 'my/project' } } + 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 - it { is_expected.to be_bridge } + context 'when job is an upstream bridge' do + let(:attributes) do + { name: 'rspec', ref: 'master', options: { triggered_by: 'my/project' } } + end + + it { is_expected.to be_bridge } + end end context 'when trigger definition is empty' do @@ -37,6 +47,14 @@ describe Gitlab::Ci::Pipeline::Seed::Build do it { is_expected.not_to be_bridge } end + context 'when triggered_by definition is empty' do + let(:attributes) do + { name: 'rspec', ref: 'master', options: { triggered_by: '' } } + end + + it { is_expected.not_to be_bridge } + end + context 'when job is not a bridge' do it { is_expected.not_to be_bridge } end @@ -51,13 +69,26 @@ describe Gitlab::Ci::Pipeline::Seed::Build do end context 'when job is a bridge' do - let(:attributes) do - { name: 'rspec', ref: 'master', options: { trigger: 'my/project' } } + context 'when bridge is downstream' do + let(:attributes) do + { name: 'rspec', ref: 'master', options: { trigger: 'my/project' } } + end + + it 'returns a valid bridge resource' do + expect(subject.to_resource).to be_a(::Ci::Bridge) + expect(subject.to_resource).to be_valid + end end - it 'returns a valid bridge resource' do - expect(subject.to_resource).to be_a(::Ci::Bridge) - expect(subject.to_resource).to be_valid + context 'when bridge is upstream' do + let(:attributes) do + { name: 'rspec', ref: 'master', options: { triggered_by: 'my/project' } } + end + + it 'returns a valid bridge resource' do + expect(subject.to_resource).to be_a(::Ci::Bridge) + expect(subject.to_resource).to be_valid + end end end |