Use node factory to assemble global CI config entry
This commit is contained in:
parent
ccbdb4022a
commit
9edced40dd
|
@ -27,8 +27,8 @@ module Gitlab
|
||||||
|
|
||||||
def create(key, factory)
|
def create(key, factory)
|
||||||
factory
|
factory
|
||||||
.value(config[key])
|
.value(@config[key])
|
||||||
.with(key: key, parent: self, global: global)
|
.with(key: key, parent: self, global: @global)
|
||||||
|
|
||||||
factory.create!
|
factory.create!
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,30 +33,38 @@ module Gitlab
|
||||||
node :cache, Node::Cache,
|
node :cache, Node::Cache,
|
||||||
description: 'Configure caching between build jobs.'
|
description: 'Configure caching between build jobs.'
|
||||||
|
|
||||||
node :jobs, Node::Jobs,
|
|
||||||
description: 'Definition of jobs for this pipeline.'
|
|
||||||
|
|
||||||
helpers :before_script, :image, :services, :after_script,
|
helpers :before_script, :image, :services, :after_script,
|
||||||
:variables, :stages, :types, :cache, :jobs
|
:variables, :stages, :types, :cache, :jobs
|
||||||
|
|
||||||
def initialize(config, **attributes)
|
def initialize(*)
|
||||||
super(setup(config), attributes)
|
super
|
||||||
@global = self
|
@global = self
|
||||||
end
|
end
|
||||||
|
|
||||||
def stages
|
|
||||||
stages_defined? ? stages_value : types_value
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def setup(config)
|
def compose!
|
||||||
return config unless config.is_a?(Hash)
|
super
|
||||||
|
|
||||||
jobs = config.except(*nodes.keys)
|
compose_stages!
|
||||||
global = config.slice(*nodes.keys)
|
compose_jobs!
|
||||||
|
end
|
||||||
|
|
||||||
global.merge(jobs: jobs)
|
def compose_stages!
|
||||||
|
factory = Node::Factory.new(Node::Jobs)
|
||||||
|
factory.value(@config.except(*nodes.keys))
|
||||||
|
factory.with(key: :jobs, parent: self, global: self)
|
||||||
|
factory.with(description: 'Jobs definition for this pipeline')
|
||||||
|
|
||||||
|
@entries[:jobs] = factory.create!
|
||||||
|
end
|
||||||
|
|
||||||
|
def compose_jobs!
|
||||||
|
if types_defined? && !stages_defined?
|
||||||
|
@entries[:stages] = @entries[:types]
|
||||||
|
end
|
||||||
|
|
||||||
|
@entries.delete(:types)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,7 +35,7 @@ describe Gitlab::Ci::Config::Node::Global do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates node object for each entry' do
|
it 'creates node object for each entry' do
|
||||||
expect(global.descendants.count).to eq 9
|
expect(global.descendants.count).to eq 8
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates node object using valid class' do
|
it 'creates node object using valid class' do
|
||||||
|
@ -142,7 +142,7 @@ describe Gitlab::Ci::Config::Node::Global do
|
||||||
|
|
||||||
describe '#nodes' do
|
describe '#nodes' do
|
||||||
it 'instantizes all nodes' do
|
it 'instantizes all nodes' do
|
||||||
expect(global.descendants.count).to eq 9
|
expect(global.descendants.count).to eq 8
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'contains undefined nodes' do
|
it 'contains undefined nodes' do
|
||||||
|
|
Loading…
Reference in New Issue