Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
80587064
Commit
80587064
authored
Jul 10, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Require parent when using node factory in CI config
parent
8f7c98ee
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
20 deletions
+60
-20
lib/gitlab/ci/config/node/configurable.rb
lib/gitlab/ci/config/node/configurable.rb
+5
-4
lib/gitlab/ci/config/node/factory.rb
lib/gitlab/ci/config/node/factory.rb
+11
-2
lib/gitlab/ci/config/node/global.rb
lib/gitlab/ci/config/node/global.rb
+4
-3
lib/gitlab/ci/config/node/jobs.rb
lib/gitlab/ci/config/node/jobs.rb
+4
-4
spec/lib/gitlab/ci/config/node/factory_spec.rb
spec/lib/gitlab/ci/config/node/factory_spec.rb
+36
-7
No files found.
lib/gitlab/ci/config/node/configurable.rb
View file @
80587064
...
@@ -28,7 +28,8 @@ module Gitlab
...
@@ -28,7 +28,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
)
.
parent
(
self
)
.
with
(
key:
key
)
factory
.
create!
factory
.
create!
end
end
...
@@ -40,11 +41,11 @@ module Gitlab
...
@@ -40,11 +41,11 @@ module Gitlab
private
private
def
node
(
symbol
,
entry_class
,
metadata
)
def
node
(
key
,
node
,
metadata
)
factory
=
Node
::
Factory
.
new
(
entry_class
)
factory
=
Node
::
Factory
.
new
(
node
)
.
with
(
description:
metadata
[
:description
])
.
with
(
description:
metadata
[
:description
])
(
@nodes
||=
{}).
merge!
(
symbol
.
to_sym
=>
factory
)
(
@nodes
||=
{}).
merge!
(
key
.
to_sym
=>
factory
)
end
end
def
helpers
(
*
nodes
)
def
helpers
(
*
nodes
)
...
...
lib/gitlab/ci/config/node/factory.rb
View file @
80587064
...
@@ -18,6 +18,11 @@ module Gitlab
...
@@ -18,6 +18,11 @@ module Gitlab
self
self
end
end
def
parent
(
parent
)
@parent
=
parent
self
end
def
with
(
attributes
)
def
with
(
attributes
)
@attributes
.
merge!
(
attributes
)
@attributes
.
merge!
(
attributes
)
self
self
...
@@ -25,15 +30,19 @@ module Gitlab
...
@@ -25,15 +30,19 @@ module Gitlab
def
create!
def
create!
raise
InvalidFactory
unless
defined?
(
@value
)
raise
InvalidFactory
unless
defined?
(
@value
)
raise
InvalidFactory
unless
defined?
(
@parent
)
attributes
=
{
parent:
@parent
,
global:
@parent
.
global
}
attributes
.
merge!
(
@attributes
)
##
##
# We assume that unspecified entry is undefined.
# We assume that unspecified entry is undefined.
# See issue #18775.
# See issue #18775.
#
#
if
@value
.
nil?
if
@value
.
nil?
Node
::
Undefined
.
new
(
@node
,
@
attributes
)
Node
::
Undefined
.
new
(
@node
,
attributes
)
else
else
@node
.
new
(
@value
,
@
attributes
)
@node
.
new
(
@value
,
attributes
)
end
end
end
end
end
end
...
...
lib/gitlab/ci/config/node/global.rb
View file @
80587064
...
@@ -53,9 +53,10 @@ module Gitlab
...
@@ -53,9 +53,10 @@ module Gitlab
def
compose_jobs!
def
compose_jobs!
factory
=
Node
::
Factory
.
new
(
Node
::
Jobs
)
factory
=
Node
::
Factory
.
new
(
Node
::
Jobs
)
factory
.
value
(
@config
.
except
(
*
nodes
.
keys
))
.
value
(
@config
.
except
(
*
nodes
.
keys
))
factory
.
with
(
key: :jobs
,
parent:
self
,
global:
self
)
.
parent
(
self
)
factory
.
with
(
description:
'Jobs definition for this pipeline'
)
.
with
(
key: :jobs
,
global:
self
)
.
with
(
description:
'Jobs definition for this pipeline'
)
@entries
[
:jobs
]
=
factory
.
create!
@entries
[
:jobs
]
=
factory
.
create!
end
end
...
...
lib/gitlab/ci/config/node/jobs.rb
View file @
80587064
...
@@ -30,14 +30,14 @@ module Gitlab
...
@@ -30,14 +30,14 @@ module Gitlab
private
private
def
create
(
name
,
config
)
def
create
(
name
,
config
)
Node
::
Factory
.
new
(
job_
node
(
name
))
Node
::
Factory
.
new
(
node
(
name
))
.
value
(
config
||
{})
.
value
(
config
||
{})
.
with
(
key:
name
,
parent:
self
,
global:
@global
)
.
parent
(
self
)
.
with
(
description:
"
#{
name
}
job definition."
)
.
with
(
key:
name
,
description:
"
#{
name
}
job definition."
)
.
create!
.
create!
end
end
def
job_
node
(
name
)
def
node
(
name
)
if
name
.
to_s
.
start_with?
(
'.'
)
if
name
.
to_s
.
start_with?
(
'.'
)
Node
::
HiddenJob
Node
::
HiddenJob
else
else
...
...
spec/lib/gitlab/ci/config/node/factory_spec.rb
View file @
80587064
...
@@ -2,22 +2,40 @@ require 'spec_helper'
...
@@ -2,22 +2,40 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Factory
do
describe
Gitlab
::
Ci
::
Config
::
Node
::
Factory
do
describe
'#create!'
do
describe
'#create!'
do
let
(
:factory
)
{
described_class
.
new
(
entry_class
)
}
let
(
:factory
)
{
described_class
.
new
(
node
)
}
let
(
:entry_class
)
{
Gitlab
::
Ci
::
Config
::
Node
::
Script
}
let
(
:node
)
{
Gitlab
::
Ci
::
Config
::
Node
::
Script
}
let
(
:parent
)
{
double
(
'parent'
)
}
let
(
:global
)
{
double
(
'global'
)
}
context
'when setting up a value'
do
before
do
allow
(
parent
).
to
receive
(
:global
).
and_return
(
global
)
end
context
'when setting a concrete value'
do
it
'creates entry with valid value'
do
it
'creates entry with valid value'
do
entry
=
factory
entry
=
factory
.
value
([
'ls'
,
'pwd'
])
.
value
([
'ls'
,
'pwd'
])
.
parent
(
parent
)
.
create!
.
create!
expect
(
entry
.
value
).
to
eq
[
'ls'
,
'pwd'
]
expect
(
entry
.
value
).
to
eq
[
'ls'
,
'pwd'
]
end
end
it
'sets parent and global attributes'
do
entry
=
factory
.
value
(
'ls'
)
.
parent
(
parent
)
.
create!
expect
(
entry
.
global
).
to
eq
global
expect
(
entry
.
parent
).
to
eq
parent
end
context
'when setting description'
do
context
'when setting description'
do
it
'creates entry with description'
do
it
'creates entry with description'
do
entry
=
factory
entry
=
factory
.
value
([
'ls'
,
'pwd'
])
.
value
([
'ls'
,
'pwd'
])
.
parent
(
parent
)
.
with
(
description:
'test description'
)
.
with
(
description:
'test description'
)
.
create!
.
create!
...
@@ -30,6 +48,7 @@ describe Gitlab::Ci::Config::Node::Factory do
...
@@ -30,6 +48,7 @@ describe Gitlab::Ci::Config::Node::Factory do
it
'creates entry with custom key'
do
it
'creates entry with custom key'
do
entry
=
factory
entry
=
factory
.
value
([
'ls'
,
'pwd'
])
.
value
([
'ls'
,
'pwd'
])
.
parent
(
parent
)
.
with
(
key:
'test key'
)
.
with
(
key:
'test key'
)
.
create!
.
create!
...
@@ -38,20 +57,21 @@ describe Gitlab::Ci::Config::Node::Factory do
...
@@ -38,20 +57,21 @@ describe Gitlab::Ci::Config::Node::Factory do
end
end
context
'when setting a parent'
do
context
'when setting a parent'
do
let
(
:
paren
t
)
{
Object
.
new
}
let
(
:
objec
t
)
{
Object
.
new
}
it
'creates entry with valid parent'
do
it
'creates entry with valid parent'
do
entry
=
factory
entry
=
factory
.
value
(
'ls'
)
.
value
(
'ls'
)
.
with
(
parent:
parent
)
.
parent
(
parent
)
.
with
(
parent:
object
)
.
create!
.
create!
expect
(
entry
.
parent
).
to
eq
paren
t
expect
(
entry
.
parent
).
to
eq
objec
t
end
end
end
end
end
end
context
'when not setting
up
a value'
do
context
'when not setting a value'
do
it
'raises error'
do
it
'raises error'
do
expect
{
factory
.
create!
}.
to
raise_error
(
expect
{
factory
.
create!
}.
to
raise_error
(
Gitlab
::
Ci
::
Config
::
Node
::
Factory
::
InvalidFactory
Gitlab
::
Ci
::
Config
::
Node
::
Factory
::
InvalidFactory
...
@@ -59,10 +79,19 @@ describe Gitlab::Ci::Config::Node::Factory do
...
@@ -59,10 +79,19 @@ describe Gitlab::Ci::Config::Node::Factory do
end
end
end
end
context
'when not setting parent object'
do
it
'raises error'
do
expect
{
factory
.
value
(
'ls'
).
create!
}.
to
raise_error
(
Gitlab
::
Ci
::
Config
::
Node
::
Factory
::
InvalidFactory
)
end
end
context
'when creating entry with nil value'
do
context
'when creating entry with nil value'
do
it
'creates an undefined entry'
do
it
'creates an undefined entry'
do
entry
=
factory
entry
=
factory
.
value
(
nil
)
.
value
(
nil
)
.
parent
(
parent
)
.
create!
.
create!
expect
(
entry
).
to
be_an_instance_of
Gitlab
::
Ci
::
Config
::
Node
::
Undefined
expect
(
entry
).
to
be_an_instance_of
Gitlab
::
Ci
::
Config
::
Node
::
Undefined
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment