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
Tatuya Kamada
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
...
@@ -15,6 +15,7 @@ module Gitlab
@global
=
Node
::
Global
.
new
(
@config
)
@global
=
Node
::
Global
.
new
(
@config
)
@global
.
process!
@global
.
process!
@global
.
validate!
end
end
def
valid?
def
valid?
...
...
lib/gitlab/ci/config/node/configurable.rb
View file @
1ac62de2
...
@@ -25,7 +25,7 @@ module Gitlab
...
@@ -25,7 +25,7 @@ module Gitlab
private
private
def
create
_node
(
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
)
...
@@ -50,12 +50,12 @@ module Gitlab
...
@@ -50,12 +50,12 @@ module Gitlab
def
helpers
(
*
nodes
)
def
helpers
(
*
nodes
)
nodes
.
each
do
|
symbol
|
nodes
.
each
do
|
symbol
|
define_method
(
"
#{
symbol
}
_defined?"
)
do
define_method
(
"
#{
symbol
}
_defined?"
)
do
@
nod
es
[
symbol
].
try
(
:defined?
)
@
entri
es
[
symbol
].
try
(
:defined?
)
end
end
define_method
(
"
#{
symbol
}
_value"
)
do
define_method
(
"
#{
symbol
}
_value"
)
do
raise
Entry
::
InvalidError
unless
valid?
raise
Entry
::
InvalidError
unless
valid?
@
nod
es
[
symbol
].
try
(
:value
)
@
entri
es
[
symbol
].
try
(
:value
)
end
end
alias_method
symbol
.
to_sym
,
"
#{
symbol
}
_value"
.
to_sym
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
...
@@ -13,7 +13,7 @@ module Gitlab
def
initialize
(
config
,
**
attributes
)
def
initialize
(
config
,
**
attributes
)
@config
=
config
@config
=
config
@
nod
es
=
{}
@
entri
es
=
{}
(
@attributes
=
attributes
).
each
do
|
attribute
,
value
|
(
@attributes
=
attributes
).
each
do
|
attribute
,
value
|
public_send
(
"
#{
attribute
}
="
,
value
)
public_send
(
"
#{
attribute
}
="
,
value
)
...
@@ -24,8 +24,18 @@ module Gitlab
...
@@ -24,8 +24,18 @@ module Gitlab
end
end
def
process!
def
process!
compose!
unless
leaf?
return
unless
valid?
@validator
.
validate
(
:processed
)
if
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
end
def
leaf?
def
leaf?
...
@@ -37,7 +47,7 @@ module Gitlab
...
@@ -37,7 +47,7 @@ module Gitlab
end
end
def
descendants
def
descendants
@
nod
es
.
values
@
entri
es
.
values
end
end
def
ancestors
def
ancestors
...
@@ -49,18 +59,18 @@ module Gitlab
...
@@ -49,18 +59,18 @@ module Gitlab
end
end
def
errors
def
errors
@validator
.
messages
+
@
nod
es
.
values
.
flat_map
(
&
:errors
)
@validator
.
messages
+
@
entri
es
.
values
.
flat_map
(
&
:errors
)
end
end
def
value
def
value
if
leaf?
if
leaf?
@config
@config
else
else
meaningful
=
@
nod
es
.
select
do
|
_key
,
value
|
meaningful
=
@
entri
es
.
select
do
|
_key
,
value
|
value
.
defined?
&&
value
.
relevant?
value
.
defined?
&&
value
.
relevant?
end
end
Hash
[
meaningful
.
map
{
|
key
,
node
|
[
key
,
node
.
value
]
}]
Hash
[
meaningful
.
map
{
|
key
,
entry
|
[
key
,
entry
.
value
]
}]
end
end
end
end
...
@@ -85,17 +95,7 @@ module Gitlab
...
@@ -85,17 +95,7 @@ module Gitlab
private
private
def
compose!
def
create
(
entry
,
essence
)
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
)
raise
NotImplementedError
raise
NotImplementedError
end
end
end
end
...
...
lib/gitlab/ci/config/node/jobs.rb
View file @
1ac62de2
...
@@ -10,7 +10,7 @@ module Gitlab
...
@@ -10,7 +10,7 @@ module Gitlab
validations
do
validations
do
validates
:config
,
type:
Hash
validates
:config
,
type:
Hash
validate
:jobs_presence
,
on: :
processed
validate
:jobs_presence
,
on: :
after
def
jobs_presence
def
jobs_presence
unless
relevant?
unless
relevant?
...
@@ -24,12 +24,12 @@ module Gitlab
...
@@ -24,12 +24,12 @@ module Gitlab
end
end
def
relevant?
def
relevant?
@
nod
es
.
values
.
any?
(
&
:relevant?
)
@
entri
es
.
values
.
any?
(
&
:relevant?
)
end
end
private
private
def
create
_node
(
name
,
config
)
def
create
(
name
,
config
)
job_node
(
name
).
new
(
config
,
job_attributes
(
name
))
job_node
(
name
).
new
(
config
,
job_attributes
(
name
))
end
end
...
...
spec/lib/gitlab/ci/config/node/jobs_spec.rb
View file @
1ac62de2
...
@@ -35,7 +35,10 @@ describe Gitlab::Ci::Config::Node::Jobs do
...
@@ -35,7 +35,10 @@ describe Gitlab::Ci::Config::Node::Jobs do
end
end
context
'when processed'
do
context
'when processed'
do
before
{
entry
.
process!
}
before
do
entry
.
process!
entry
.
validate!
end
it
'returns error about no visible jobs defined'
do
it
'returns error about no visible jobs defined'
do
expect
(
entry
.
errors
)
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