Skip to content
Snippets Groups Projects
Commit 10a486b3 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Remove YAML processor refactoring stubs and fix specs

parent 241197c2
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -26,7 +26,7 @@ module Gitlab
 
def matches_pattern?(pattern, pipeline)
return true if pipeline.tag? && pattern == 'tags'
return true if !pipeline.tag? && pattern == 'branches'
return true if pipeline.branch? && pattern == 'branches'
return true if source_to_pattern(pipeline.source) == pattern
 
if pattern.first == "/" && pattern.last == "/"
Loading
Loading
Loading
Loading
@@ -22,28 +22,12 @@ module Gitlab
end
 
 
# REFACTORING STUB, remove this method, used only in tests.
#
def builds_for_stage_and_ref(stage, ref, tag = false, source = nil)
pipeline_stage_builds(stage, ::Ci::Pipeline.new(ref: ref, source: source, tag: tag))
end
def builds
@jobs.map do |name, _|
build_attributes(name)
end
end
 
def stage_seeds(pipeline)
seeds = @stages.uniq.map do |stage|
builds = pipeline_stage_builds(stage, pipeline)
Gitlab::Ci::Stage::Seed.new(pipeline, stage, builds) if builds.any?
end
seeds.compact
end
def build_attributes(name)
job = @jobs[name.to_sym] || {}
 
Loading
Loading
@@ -71,21 +55,8 @@ module Gitlab
}.compact }
end
 
def self.validation_message(content)
return 'Please provide content of .gitlab-ci.yml' if content.blank?
begin
Gitlab::Ci::YamlProcessor.new(content)
nil
rescue ValidationError, Psych::SyntaxError => e
e.message
end
end
private
def pipeline_stage_builds(stage, pipeline)
stage_jobs = @jobs.select do |_, job|
selected_jobs = @jobs.select do |_, job|
next unless job[:stage] == stage
 
only_specs = Gitlab::Ci::Build::Policy
Loading
Loading
@@ -97,9 +68,32 @@ module Gitlab
except_specs.none? { |spec| spec.satisfied_by?(pipeline, path: @path) }
end
 
stage_jobs.map { |_, job| build_attributes(job[:name]) }
selected_jobs.map { |_, job| build_attributes(job[:name]) }
end
def stage_seeds(pipeline)
seeds = @stages.uniq.map do |stage|
builds = pipeline_stage_builds(stage, pipeline)
Gitlab::Ci::Stage::Seed.new(pipeline, stage, builds) if builds.any?
end
seeds.compact
end
def self.validation_message(content)
return 'Please provide content of .gitlab-ci.yml' if content.blank?
begin
Gitlab::Ci::YamlProcessor.new(content)
nil
rescue ValidationError, Psych::SyntaxError => e
e.message
end
end
 
private
def initial_parsing
##
# Global config
Loading
Loading
Loading
Loading
@@ -167,8 +167,6 @@ module Gitlab
end
 
context 'when kubernetes policy is specified' do
let(:pipeline) { create(:ci_empty_pipeline) }
let(:config) do
YAML.dump(
spinach: { stage: 'test', script: 'spinach' },
Loading
Loading
@@ -204,7 +202,7 @@ module Gitlab
end
end
 
describe "#builds_for_stage_and_ref" do
describe "#pipeline_stage_builds" do
let(:type) { 'test' }
 
it "returns builds if no branch specified" do
Loading
Loading
@@ -215,8 +213,8 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(1)
expect(config_processor.builds_for_stage_and_ref(type, "master").first).to eq({
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "master")).size).to eq(1)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "master")).first).to eq({
stage: "test",
stage_idx: 1,
name: "rspec",
Loading
Loading
@@ -243,7 +241,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(0)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "master")).size).to eq(0)
end
 
it "does not return builds if only has regexp with another branch" do
Loading
Loading
@@ -254,7 +252,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(0)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "master")).size).to eq(0)
end
 
it "returns builds if only has specified this branch" do
Loading
Loading
@@ -265,7 +263,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(1)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "master")).size).to eq(1)
end
 
it "returns builds if only has a list of branches including specified" do
Loading
Loading
@@ -276,7 +274,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "deploy")).size).to eq(1)
end
 
it "returns builds if only has a branches keyword specified" do
Loading
Loading
@@ -287,7 +285,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "deploy")).size).to eq(1)
end
 
it "does not return builds if only has a tags keyword" do
Loading
Loading
@@ -298,7 +296,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(0)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "deploy")).size).to eq(0)
end
 
it "returns builds if only has special keywords specified and source matches" do
Loading
Loading
@@ -317,7 +315,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, possibility[:source]).size).to eq(1)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: 'deploy', tag: false, source: possibility[:source])).size).to eq(1)
end
end
 
Loading
Loading
@@ -337,7 +335,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, possibility[:source]).size).to eq(0)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: 'deploy', tag: false, source: possibility[:source])).size).to eq(0)
end
end
 
Loading
Loading
@@ -349,7 +347,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "deploy")).size).to eq(1)
end
 
it "does not return builds if only has different repository path" do
Loading
Loading
@@ -360,7 +358,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(0)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "deploy")).size).to eq(0)
end
 
it "returns build only for specified type" do
Loading
Loading
@@ -373,9 +371,9 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, 'fork')
 
expect(config_processor.builds_for_stage_and_ref("deploy", "deploy").size).to eq(2)
expect(config_processor.builds_for_stage_and_ref("test", "deploy").size).to eq(1)
expect(config_processor.builds_for_stage_and_ref("deploy", "master").size).to eq(1)
expect(config_processor.pipeline_stage_builds("deploy", pipeline(ref: "deploy")).size).to eq(2)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "deploy")).size).to eq(1)
expect(config_processor.pipeline_stage_builds("deploy", pipeline(ref: "master")).size).to eq(1)
end
 
context 'for invalid value' do
Loading
Loading
@@ -420,7 +418,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(1)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "master")).size).to eq(1)
end
 
it "returns builds if except has regexp with another branch" do
Loading
Loading
@@ -431,7 +429,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(1)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "master")).size).to eq(1)
end
 
it "does not return builds if except has specified this branch" do
Loading
Loading
@@ -442,7 +440,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq(0)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "master")).size).to eq(0)
end
 
it "does not return builds if except has a list of branches including specified" do
Loading
Loading
@@ -453,7 +451,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(0)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "deploy")).size).to eq(0)
end
 
it "does not return builds if except has a branches keyword specified" do
Loading
Loading
@@ -464,7 +462,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(0)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "deploy")).size).to eq(0)
end
 
it "returns builds if except has a tags keyword" do
Loading
Loading
@@ -475,7 +473,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "deploy")).size).to eq(1)
end
 
it "does not return builds if except has special keywords specified and source matches" do
Loading
Loading
@@ -494,7 +492,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, possibility[:source]).size).to eq(0)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: 'deploy', tag: false, source: possibility[:source])).size).to eq(0)
end
end
 
Loading
Loading
@@ -514,7 +512,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "deploy", false, possibility[:source]).size).to eq(1)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: 'deploy', tag: false, source: possibility[:source])).size).to eq(1)
end
end
 
Loading
Loading
@@ -526,7 +524,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(0)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "deploy")).size).to eq(0)
end
 
it "returns builds if except has different repository path" do
Loading
Loading
@@ -537,7 +535,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq(1)
expect(config_processor.pipeline_stage_builds(type, pipeline(ref: "deploy")).size).to eq(1)
end
 
it "returns build except specified type" do
Loading
Loading
@@ -550,9 +548,9 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, 'fork')
 
expect(config_processor.builds_for_stage_and_ref("deploy", "deploy").size).to eq(2)
expect(config_processor.builds_for_stage_and_ref("test", "test").size).to eq(0)
expect(config_processor.builds_for_stage_and_ref("deploy", "master").size).to eq(0)
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)
end
 
context 'for invalid value' do
Loading
Loading
@@ -593,7 +591,7 @@ module Gitlab
let(:config_data) { YAML.dump(config) }
let(:config_processor) { Gitlab::Ci::YamlProcessor.new(config_data, path) }
 
subject { config_processor.builds_for_stage_and_ref("test", "master").first }
subject { config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first }
 
describe "before_script" do
context "in global context" do
Loading
Loading
@@ -676,8 +674,8 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first).to eq({
stage: "test",
stage_idx: 1,
name: "rspec",
Loading
Loading
@@ -711,8 +709,8 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first).to eq({
stage: "test",
stage_idx: 1,
name: "rspec",
Loading
Loading
@@ -744,8 +742,8 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first).to eq({
stage: "test",
stage_idx: 1,
name: "rspec",
Loading
Loading
@@ -773,8 +771,8 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first).to eq({
stage: "test",
stage_idx: 1,
name: "rspec",
Loading
Loading
@@ -920,7 +918,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
builds = config_processor.builds_for_stage_and_ref("test", "master")
builds = config_processor.pipeline_stage_builds("test", pipeline(ref: "master"))
expect(builds.size).to eq(1)
expect(builds.first[:when]).to eq(when_state)
end
Loading
Loading
@@ -951,8 +949,8 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config)
 
expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
expect(config_processor.builds_for_stage_and_ref("test", "master").first[:options][:cache]).to eq(
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first[:options][:cache]).to eq(
paths: ["logs/", "binaries/"],
untracked: true,
key: 'key',
Loading
Loading
@@ -970,8 +968,8 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config)
 
expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
expect(config_processor.builds_for_stage_and_ref("test", "master").first[:options][:cache]).to eq(
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first[:options][:cache]).to eq(
paths: ["logs/", "binaries/"],
untracked: true,
key: 'key',
Loading
Loading
@@ -990,8 +988,8 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config)
 
expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
expect(config_processor.builds_for_stage_and_ref("test", "master").first[:options][:cache]).to eq(
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first[:options][:cache]).to eq(
paths: ["test/"],
untracked: false,
key: 'local',
Loading
Loading
@@ -1019,8 +1017,8 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config)
 
expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq(1)
expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first).to eq({
stage: "test",
stage_idx: 1,
name: "rspec",
Loading
Loading
@@ -1057,7 +1055,7 @@ module Gitlab
 
config_processor = Gitlab::Ci::YamlProcessor.new(config, path)
 
builds = config_processor.builds_for_stage_and_ref("test", "master")
builds = config_processor.pipeline_stage_builds("test", pipeline(ref: "master"))
expect(builds.size).to eq(1)
expect(builds.first[:options][:artifacts][:when]).to eq(when_state)
end
Loading
Loading
@@ -1072,7 +1070,7 @@ module Gitlab
end
 
let(:processor) { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)) }
let(:builds) { processor.builds_for_stage_and_ref('deploy', 'master') }
let(:builds) { processor.pipeline_stage_builds('deploy', pipeline(ref: 'master')) }
 
context 'when a production environment is specified' do
let(:environment) { 'production' }
Loading
Loading
@@ -1229,7 +1227,7 @@ module Gitlab
 
describe "Hidden jobs" do
let(:config_processor) { Gitlab::Ci::YamlProcessor.new(config) }
subject { config_processor.builds_for_stage_and_ref("test", "master") }
subject { config_processor.pipeline_stage_builds("test", pipeline(ref: "master")) }
 
shared_examples 'hidden_job_handling' do
it "doesn't create jobs that start with dot" do
Loading
Loading
@@ -1277,7 +1275,7 @@ module Gitlab
 
describe "YAML Alias/Anchor" do
let(:config_processor) { Gitlab::Ci::YamlProcessor.new(config) }
subject { config_processor.builds_for_stage_and_ref("build", "master") }
subject { config_processor.pipeline_stage_builds("build", pipeline(ref: "master")) }
 
shared_examples 'job_templates_handling' do
it "is correctly supported for jobs" do
Loading
Loading
@@ -1694,6 +1692,10 @@ EOT
end
end
end
def pipeline(**attributes)
build_stubbed(:ci_empty_pipeline, **attributes)
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment