diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-09-18 14:29:43 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-09-18 14:29:43 +0200 |
commit | d79ad28fcb44c35d77de26d428ae61bc6d71e8ec (patch) | |
tree | 0eab721907e46ad6f91b22f719850f32529569f9 | |
parent | 6681ea9cd8d7001a352c95237d625057b6147f0b (diff) | |
download | gitlab-ce-d79ad28fcb44c35d77de26d428ae61bc6d71e8ec.tar.gz |
Do not pass project path from YAML processor
Use project full path that can be received from a pipeline object
-rw-r--r-- | app/models/ci/pipeline.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/ci/build/policy/kubernetes.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/build/policy/refs.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/ci/build/policy/specification.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/ci/yaml_processor.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/build/policy/refs_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/yaml_processor_spec.rb | 33 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 1 |
8 files changed, 40 insertions, 23 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 8d017b9b3b1..ae9ec166d65 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -31,6 +31,7 @@ module Ci has_many :auto_canceled_jobs, class_name: 'CommitStatus', foreign_key: 'auto_canceled_by_id' delegate :id, to: :project, prefix: true + delegate :full_path, to: :project, prefix: true validates :source, exclusion: { in: %w(unknown), unless: :importing? }, on: :create validates :sha, presence: { unless: :importing? } diff --git a/lib/gitlab/ci/build/policy/kubernetes.rb b/lib/gitlab/ci/build/policy/kubernetes.rb index bf3a95e08f0..b20d374288f 100644 --- a/lib/gitlab/ci/build/policy/kubernetes.rb +++ b/lib/gitlab/ci/build/policy/kubernetes.rb @@ -9,7 +9,7 @@ module Gitlab end end - def satisfied_by?(pipeline, **_) + def satisfied_by?(pipeline) pipeline.has_kubernetes_active? end end diff --git a/lib/gitlab/ci/build/policy/refs.rb b/lib/gitlab/ci/build/policy/refs.rb index 76a57f041e3..eadc0948d2f 100644 --- a/lib/gitlab/ci/build/policy/refs.rb +++ b/lib/gitlab/ci/build/policy/refs.rb @@ -7,21 +7,21 @@ module Gitlab @patterns = Array(refs) end - def satisfied_by?(pipeline, path: nil) + def satisfied_by?(pipeline) @patterns.any? do |pattern| - pattern, ref_path = pattern.split('@', 2) + pattern, path = pattern.split('@', 2) - matches_path?(ref_path, path) && + matches_path?(path, pipeline) && matches_pattern?(pattern, pipeline) end end private - def matches_path?(ref_path, expected_path) - return true unless ref_path + def matches_path?(path, pipeline) + return true unless path - expected_path == ref_path + pipeline.project_full_path == path end def matches_pattern?(pattern, pipeline) diff --git a/lib/gitlab/ci/build/policy/specification.rb b/lib/gitlab/ci/build/policy/specification.rb index 9ca3582b9b0..c317291f29d 100644 --- a/lib/gitlab/ci/build/policy/specification.rb +++ b/lib/gitlab/ci/build/policy/specification.rb @@ -3,7 +3,7 @@ module Gitlab module Build module Policy ## - # Abstract class that defines an intereface of job policy + # Abstract class that defines an interface of job policy # specification. # # Used for job's only/except policy configuration. @@ -15,7 +15,7 @@ module Gitlab @spec = spec end - def satisfied_by?(pipeline, **metadata) + def satisfied_by?(pipeline) raise NotImplementedError end end diff --git a/lib/gitlab/ci/yaml_processor.rb b/lib/gitlab/ci/yaml_processor.rb index 3a7a2761db8..da39a28df4c 100644 --- a/lib/gitlab/ci/yaml_processor.rb +++ b/lib/gitlab/ci/yaml_processor.rb @@ -63,8 +63,8 @@ module Gitlab except_specs = Gitlab::Ci::Build::Policy .fabricate(job.fetch(:except, {})) - only_specs.all? { |spec| spec.satisfied_by?(pipeline, path: @path) } && - except_specs.none? { |spec| spec.satisfied_by?(pipeline, path: @path) } + only_specs.all? { |spec| spec.satisfied_by?(pipeline) } && + except_specs.none? { |spec| spec.satisfied_by?(pipeline) } end selected_jobs.map { |_, job| build_attributes(job[:name]) } diff --git a/spec/lib/gitlab/ci/build/policy/refs_spec.rb b/spec/lib/gitlab/ci/build/policy/refs_spec.rb index 2eb612800fb..7211187e511 100644 --- a/spec/lib/gitlab/ci/build/policy/refs_spec.rb +++ b/spec/lib/gitlab/ci/build/policy/refs_spec.rb @@ -46,13 +46,13 @@ describe Gitlab::Ci::Build::Policy::Refs do end it 'is satisfied when provided patch matches specified one' do - expect(described_class.new(%w[master@some/repository])) - .to be_satisfied_by(pipeline, path: 'some/repository') + expect(described_class.new(%W[master@#{pipeline.project_full_path}])) + .to be_satisfied_by(pipeline) end it 'is not satisfied when path differs' do expect(described_class.new(%w[master@some/fork/repository])) - .not_to be_satisfied_by(pipeline, path: 'some/repository') + .not_to be_satisfied_by(pipeline) end end diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index 6637a235822..4b166cf3010 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -340,14 +340,20 @@ module Gitlab end it "returns builds if only has current repository path" do + seed_pipeline = pipeline(ref: 'deploy') + config = YAML.dump({ before_script: ["pwd"], - rspec: { script: "rspec", type: type, only: ["branches@path"] } + rspec: { + script: "rspec", + type: type, + only: ["branches@#{seed_pipeline.project_full_path}"] + } }) config_processor = Gitlab::Ci::YamlProcessor.new(config, path) - expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "deploy")).size).to eq(1) + expect(config_processor.pipeline_stage_builds(type, seed_pipeline).size).to eq(1) end it "does not return builds if only has different repository path" do @@ -517,14 +523,19 @@ module Gitlab end it "does not return builds if except has current repository path" do + seed_pipeline = pipeline(ref: 'deploy') + config = YAML.dump({ before_script: ["pwd"], - rspec: { script: "rspec", type: type, except: ["branches@path"] } + rspec: { + script: "rspec", + type: type, + except: ["branches@#{seed_pipeline.project_full_path}"] } }) config_processor = Gitlab::Ci::YamlProcessor.new(config, path) - expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "deploy")).size).to eq(0) + expect(config_processor.pipeline_stage_builds(type, seed_pipeline).size).to eq(0) end it "returns builds if except has different repository path" do @@ -539,18 +550,22 @@ module Gitlab end it "returns build except specified type" do + master_pipeline = pipeline(ref: 'master') + test_pipeline = pipeline(ref: 'test') + deploy_pipeline = pipeline(ref: 'deploy') + config = YAML.dump({ before_script: ["pwd"], - rspec: { script: "rspec", type: "test", except: ["master", "deploy", "test@fork"] }, + rspec: { script: "rspec", type: "test", except: ["master", "deploy", "test@#{test_pipeline.project_full_path}"] }, staging: { script: "deploy", type: "deploy", except: ["master"] }, - production: { script: "deploy", type: "deploy", except: ["master@fork"] } + production: { script: "deploy", type: "deploy", except: ["master@#{master_pipeline.project_full_path}"] } }) config_processor = Gitlab::Ci::YamlProcessor.new(config, 'fork') - expect(config_processor.pipeline_stage_builds("deploy", pipeline(ref: "deploy")).size).to eq(2) - expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "test")).size).to eq(0) - expect(config_processor.pipeline_stage_builds("deploy", pipeline(ref: "master")).size).to eq(0) + expect(config_processor.pipeline_stage_builds("deploy", deploy_pipeline).size).to eq(2) + expect(config_processor.pipeline_stage_builds("test", test_pipeline).size).to eq(0) + expect(config_processor.pipeline_stage_builds("deploy", master_pipeline).size).to eq(0) end context 'for invalid value' do diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 77f0be6b120..9c1e460ab20 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -26,6 +26,7 @@ describe Ci::Pipeline, :mailer do it { is_expected.to respond_to :git_author_name } it { is_expected.to respond_to :git_author_email } it { is_expected.to respond_to :short_sha } + it { is_expected.to delegate_method(:full_path).to(:project).with_prefix } describe '#source' do context 'when creating new pipeline' do |