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
Jérome Perrin
gitlab-ce
Commits
1ac62de2
Commit
1ac62de2
authored
Jul 08, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract CI entry node validator and improve naming
parent
159aed1c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
25 deletions
+29
-25
lib/gitlab/ci/config.rb
lib/gitlab/ci/config.rb
+1
-0
lib/gitlab/ci/config/node/configurable.rb
lib/gitlab/ci/config/node/configurable.rb
+3
-3
lib/gitlab/ci/config/node/entry.rb
lib/gitlab/ci/config/node/entry.rb
+18
-18
lib/gitlab/ci/config/node/jobs.rb
lib/gitlab/ci/config/node/jobs.rb
+3
-3
spec/lib/gitlab/ci/config/node/jobs_spec.rb
spec/lib/gitlab/ci/config/node/jobs_spec.rb
+4
-1
No files found.
lib/gitlab/ci/config.rb
View file @
1ac62de2
...
...
@@ -15,6 +15,7 @@ module Gitlab
@global
=
Node
::
Global
.
new
(
@config
)
@global
.
process!
@global
.
validate!
end
def
valid?
...
...
lib/gitlab/ci/config/node/configurable.rb
View file @
1ac62de2
...
...
@@ -25,7 +25,7 @@ module Gitlab
private
def
create
_node
(
key
,
factory
)
def
create
(
key
,
factory
)
factory
.
value
(
config
[
key
])
.
with
(
key:
key
,
parent:
self
,
global:
global
)
...
...
@@ -50,12 +50,12 @@ module Gitlab
def
helpers
(
*
nodes
)
nodes
.
each
do
|
symbol
|
define_method
(
"
#{
symbol
}
_defined?"
)
do
@
nod
es
[
symbol
].
try
(
:defined?
)
@
entri
es
[
symbol
].
try
(
:defined?
)
end
define_method
(
"
#{
symbol
}
_value"
)
do
raise
Entry
::
InvalidError
unless
valid?
@
nod
es
[
symbol
].
try
(
:value
)
@
entri
es
[
symbol
].
try
(
:value
)
end
alias_method
symbol
.
to_sym
,
"
#{
symbol
}
_value"
.
to_sym
...
...
lib/gitlab/ci/config/node/entry.rb
View file @
1ac62de2
...
...
@@ -13,7 +13,7 @@ module Gitlab
def
initialize
(
config
,
**
attributes
)
@config
=
config
@
nod
es
=
{}
@
entri
es
=
{}
(
@attributes
=
attributes
).
each
do
|
attribute
,
value
|
public_send
(
"
#{
attribute
}
="
,
value
)
...
...
@@ -24,8 +24,18 @@ module Gitlab
end
def
process!
compose!
unless
leaf?
@validator
.
validate
(
:processed
)
if
valid?
return
unless
valid?
nodes
.
each
do
|
key
,
essence
|
@entries
[
key
]
=
create
(
key
,
essence
)
end
@entries
.
each_value
(
&
:process!
)
end
def
validate!
@validator
.
validate
(
:after
)
@entries
.
each_value
(
&
:validate!
)
end
def
leaf?
...
...
@@ -37,7 +47,7 @@ module Gitlab
end
def
descendants
@
nod
es
.
values
@
entri
es
.
values
end
def
ancestors
...
...
@@ -49,18 +59,18 @@ module Gitlab
end
def
errors
@validator
.
messages
+
@
nod
es
.
values
.
flat_map
(
&
:errors
)
@validator
.
messages
+
@
entri
es
.
values
.
flat_map
(
&
:errors
)
end
def
value
if
leaf?
@config
else
meaningful
=
@
nod
es
.
select
do
|
_key
,
value
|
meaningful
=
@
entri
es
.
select
do
|
_key
,
value
|
value
.
defined?
&&
value
.
relevant?
end
Hash
[
meaningful
.
map
{
|
key
,
node
|
[
key
,
node
.
value
]
}]
Hash
[
meaningful
.
map
{
|
key
,
entry
|
[
key
,
entry
.
value
]
}]
end
end
...
...
@@ -85,17 +95,7 @@ module Gitlab
private
def
compose!
return
unless
valid?
nodes
.
each
do
|
key
,
essence
|
@nodes
[
key
]
=
create_node
(
key
,
essence
)
end
@nodes
.
each_value
(
&
:process!
)
end
def
create_node
(
key
,
essence
)
def
create
(
entry
,
essence
)
raise
NotImplementedError
end
end
...
...
lib/gitlab/ci/config/node/jobs.rb
View file @
1ac62de2
...
...
@@ -10,7 +10,7 @@ module Gitlab
validations
do
validates
:config
,
type:
Hash
validate
:jobs_presence
,
on: :
processed
validate
:jobs_presence
,
on: :
after
def
jobs_presence
unless
relevant?
...
...
@@ -24,12 +24,12 @@ module Gitlab
end
def
relevant?
@
nod
es
.
values
.
any?
(
&
:relevant?
)
@
entri
es
.
values
.
any?
(
&
:relevant?
)
end
private
def
create
_node
(
name
,
config
)
def
create
(
name
,
config
)
job_node
(
name
).
new
(
config
,
job_attributes
(
name
))
end
...
...
spec/lib/gitlab/ci/config/node/jobs_spec.rb
View file @
1ac62de2
...
...
@@ -35,7 +35,10 @@ describe Gitlab::Ci::Config::Node::Jobs do
end
context
'when processed'
do
before
{
entry
.
process!
}
before
do
entry
.
process!
entry
.
validate!
end
it
'returns error about no visible jobs defined'
do
expect
(
entry
.
errors
)
...
...
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