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
Léo-Paul Géneau
gitlab-ce
Commits
a7ac2f74
Commit
a7ac2f74
authored
Jul 07, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify CI config entry node factory, use attribs
parent
9410aecc
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
54 deletions
+37
-54
lib/gitlab/ci/config/node/configurable.rb
lib/gitlab/ci/config/node/configurable.rb
+3
-1
lib/gitlab/ci/config/node/entry.rb
lib/gitlab/ci/config/node/entry.rb
+7
-7
lib/gitlab/ci/config/node/factory.rb
lib/gitlab/ci/config/node/factory.rb
+9
-18
lib/gitlab/ci/config/node/global.rb
lib/gitlab/ci/config/node/global.rb
+4
-0
lib/gitlab/ci/config/node/jobs.rb
lib/gitlab/ci/config/node/jobs.rb
+5
-5
lib/gitlab/ci/config/node/undefined.rb
lib/gitlab/ci/config/node/undefined.rb
+2
-4
spec/lib/gitlab/ci/config/node/factory_spec.rb
spec/lib/gitlab/ci/config/node/factory_spec.rb
+7
-19
No files found.
lib/gitlab/ci/config/node/configurable.rb
View file @
a7ac2f74
...
@@ -26,7 +26,9 @@ module Gitlab
...
@@ -26,7 +26,9 @@ module Gitlab
private
private
def
create_node
(
key
,
factory
)
def
create_node
(
key
,
factory
)
factory
.
with
(
value:
@config
[
key
],
key:
key
,
parent:
self
)
factory
.
value
(
config
[
key
])
.
with
(
key:
key
,
parent:
self
,
global:
global
)
factory
.
create!
factory
.
create!
end
end
...
...
lib/gitlab/ci/config/node/entry.rb
View file @
a7ac2f74
...
@@ -8,13 +8,17 @@ module Gitlab
...
@@ -8,13 +8,17 @@ module Gitlab
class
Entry
class
Entry
class
InvalidError
<
StandardError
;
end
class
InvalidError
<
StandardError
;
end
attr_reader
:config
attr_reader
:config
,
:attributes
attr_accessor
:key
,
:parent
,
:description
attr_accessor
:key
,
:parent
,
:
global
,
:
description
def
initialize
(
config
)
def
initialize
(
config
,
**
attributes
)
@config
=
config
@config
=
config
@nodes
=
{}
@nodes
=
{}
(
@attributes
=
attributes
).
each
do
|
attribute
,
value
|
public_send
(
"
#{
attribute
}
="
,
value
)
end
@validator
=
self
.
class
.
validator
.
new
(
self
)
@validator
=
self
.
class
.
validator
.
new
(
self
)
@validator
.
validate
@validator
.
validate
end
end
...
@@ -68,10 +72,6 @@ module Gitlab
...
@@ -68,10 +72,6 @@ module Gitlab
true
true
end
end
def
attributes
{
key:
@key
,
parent:
@parent
,
description:
@description
}
end
def
self
.
default
def
self
.
default
end
end
...
...
lib/gitlab/ci/config/node/factory.rb
View file @
a7ac2f74
...
@@ -13,38 +13,29 @@ module Gitlab
...
@@ -13,38 +13,29 @@ module Gitlab
@attributes
=
{}
@attributes
=
{}
end
end
def
value
(
value
)
@value
=
value
self
end
def
with
(
attributes
)
def
with
(
attributes
)
@attributes
.
merge!
(
attributes
)
@attributes
.
merge!
(
attributes
)
self
self
end
end
def
create!
def
create!
raise
InvalidFactory
unless
@attributes
.
has_key?
(
:
value
)
raise
InvalidFactory
unless
defined?
(
@
value
)
##
##
# We assume that unspecified entry is undefined.
# We assume that unspecified entry is undefined.
# See issue #18775.
# See issue #18775.
#
#
if
@
attributes
[
:value
]
.
nil?
if
@
value
.
nil?
fabricate
(
Node
::
Undefined
,
@node
)
Node
::
Undefined
.
new
(
@node
,
@attributes
)
else
else
fabricate
(
@node
,
@attributes
[
:value
]
)
@node
.
new
(
@value
,
@attributes
)
end
end
end
end
def
self
.
fabricate
(
node
,
value
,
**
attributes
)
node
.
new
(
value
).
tap
do
|
entry
|
entry
.
key
=
attributes
[
:key
]
entry
.
parent
=
attributes
[
:parent
]
entry
.
description
=
attributes
[
:description
]
end
end
private
def
fabricate
(
node
,
value
)
self
.
class
.
fabricate
(
node
,
value
,
@attributes
)
end
end
end
end
end
end
end
...
...
lib/gitlab/ci/config/node/global.rb
View file @
a7ac2f74
...
@@ -51,6 +51,10 @@ module Gitlab
...
@@ -51,6 +51,10 @@ module Gitlab
def
stages
def
stages
stages_defined?
?
stages_value
:
types_value
stages_defined?
?
stages_value
:
types_value
end
end
def
global
self
end
end
end
end
end
end
end
...
...
lib/gitlab/ci/config/node/jobs.rb
View file @
a7ac2f74
...
@@ -30,13 +30,13 @@ module Gitlab
...
@@ -30,13 +30,13 @@ module Gitlab
private
private
def
create_node
(
key
,
value
)
def
create_node
(
key
,
value
)
node
=
key
.
to_s
.
start_with?
(
'.'
)
?
Node
::
HiddenJob
:
Node
::
Job
job_
node
=
key
.
to_s
.
start_with?
(
'.'
)
?
Node
::
HiddenJob
:
Node
::
Job
attributes
=
{
key:
key
,
job_
attributes
=
{
key:
key
,
parent:
self
,
parent:
self
,
description:
"
#{
key
}
job definition."
}
description:
"
#{
key
}
job definition."
}
Node
::
Factory
.
fabricate
(
node
,
value
,
attributes
)
job_node
.
new
(
value
,
attributes
.
merge
(
job_attributes
)
)
end
end
end
end
end
end
...
...
lib/gitlab/ci/config/node/undefined.rb
View file @
a7ac2f74
...
@@ -19,7 +19,7 @@ module Gitlab
...
@@ -19,7 +19,7 @@ module Gitlab
validates
:config
,
type:
Class
validates
:config
,
type:
Class
end
end
def
initialize
(
node
)
def
initialize
(
node
,
**
attributes
)
super
super
@strategy
=
create_strategy
(
node
,
node
.
default
)
@strategy
=
create_strategy
(
node
,
node
.
default
)
end
end
...
@@ -34,9 +34,7 @@ module Gitlab
...
@@ -34,9 +34,7 @@ module Gitlab
if
default
.
nil?
if
default
.
nil?
Undefined
::
NullStrategy
.
new
Undefined
::
NullStrategy
.
new
else
else
entry
=
Node
::
Factory
entry
=
node
.
new
(
default
,
attributes
)
.
fabricate
(
node
,
default
,
attributes
)
Undefined
::
DefaultStrategy
.
new
(
entry
)
Undefined
::
DefaultStrategy
.
new
(
entry
)
end
end
end
end
...
...
spec/lib/gitlab/ci/config/node/factory_spec.rb
View file @
a7ac2f74
...
@@ -5,24 +5,10 @@ describe Gitlab::Ci::Config::Node::Factory do
...
@@ -5,24 +5,10 @@ describe Gitlab::Ci::Config::Node::Factory do
let
(
:factory
)
{
described_class
.
new
(
entry_class
)
}
let
(
:factory
)
{
described_class
.
new
(
entry_class
)
}
let
(
:entry_class
)
{
Gitlab
::
Ci
::
Config
::
Node
::
Script
}
let
(
:entry_class
)
{
Gitlab
::
Ci
::
Config
::
Node
::
Script
}
describe
'.fabricate'
do
it
'fabricates entry with attributes set'
do
fabricated
=
described_class
.
fabricate
(
entry_class
,
[
'ls'
],
parent:
true
,
key: :test
)
expect
(
fabricated
.
parent
).
to
be
true
expect
(
fabricated
.
key
).
to
eq
:test
expect
(
fabricated
.
value
).
to
eq
[
'ls'
]
expect
(
fabricated
.
attributes
)
.
to
eq
(
parent:
true
,
key: :test
,
description:
nil
)
end
end
context
'when setting up a value'
do
context
'when setting up a value'
do
it
'creates entry with valid value'
do
it
'creates entry with valid value'
do
entry
=
factory
entry
=
factory
.
with
(
value:
[
'ls'
,
'pwd'
])
.
value
(
[
'ls'
,
'pwd'
])
.
create!
.
create!
expect
(
entry
.
value
).
to
eq
[
'ls'
,
'pwd'
]
expect
(
entry
.
value
).
to
eq
[
'ls'
,
'pwd'
]
...
@@ -31,7 +17,7 @@ describe Gitlab::Ci::Config::Node::Factory do
...
@@ -31,7 +17,7 @@ describe Gitlab::Ci::Config::Node::Factory do
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
.
with
(
value:
[
'ls'
,
'pwd'
])
.
value
(
[
'ls'
,
'pwd'
])
.
with
(
description:
'test description'
)
.
with
(
description:
'test description'
)
.
create!
.
create!
...
@@ -43,7 +29,8 @@ describe Gitlab::Ci::Config::Node::Factory do
...
@@ -43,7 +29,8 @@ describe Gitlab::Ci::Config::Node::Factory do
context
'when setting key'
do
context
'when setting key'
do
it
'creates entry with custom key'
do
it
'creates entry with custom key'
do
entry
=
factory
entry
=
factory
.
with
(
value:
[
'ls'
,
'pwd'
],
key:
'test key'
)
.
value
([
'ls'
,
'pwd'
])
.
with
(
key:
'test key'
)
.
create!
.
create!
expect
(
entry
.
key
).
to
eq
'test key'
expect
(
entry
.
key
).
to
eq
'test key'
...
@@ -55,7 +42,8 @@ describe Gitlab::Ci::Config::Node::Factory do
...
@@ -55,7 +42,8 @@ describe Gitlab::Ci::Config::Node::Factory do
it
'creates entry with valid parent'
do
it
'creates entry with valid parent'
do
entry
=
factory
entry
=
factory
.
with
(
value:
'ls'
,
parent:
parent
)
.
value
(
'ls'
)
.
with
(
parent:
parent
)
.
create!
.
create!
expect
(
entry
.
parent
).
to
eq
parent
expect
(
entry
.
parent
).
to
eq
parent
...
@@ -74,7 +62,7 @@ describe Gitlab::Ci::Config::Node::Factory do
...
@@ -74,7 +62,7 @@ describe Gitlab::Ci::Config::Node::Factory do
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
.
with
(
value:
nil
)
.
value
(
nil
)
.
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