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
5065612a
Commit
5065612a
authored
Jun 08, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add minor improvements in new Ci config design
parent
87fe50f2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
13 deletions
+52
-13
lib/gitlab/ci/config/node/entry.rb
lib/gitlab/ci/config/node/entry.rb
+27
-13
lib/gitlab/ci/config/node/null.rb
lib/gitlab/ci/config/node/null.rb
+1
-0
spec/lib/gitlab/ci/config/node/before_script_spec.rb
spec/lib/gitlab/ci/config/node/before_script_spec.rb
+12
-0
spec/lib/gitlab/ci/config/node/global_spec.rb
spec/lib/gitlab/ci/config/node/global_spec.rb
+12
-0
No files found.
lib/gitlab/ci/config/node/entry.rb
View file @
5065612a
...
...
@@ -12,22 +12,16 @@ module Gitlab
@nodes
=
{}
@errors
=
[]
unless
leaf?
||
value
.
is_a?
(
Hash
)
unless
leaf?
||
has_config?
@errors
<<
'should be a configuration entry with hash value'
end
end
def
process!
return
if
leaf?
||
!
valid?
return
if
leaf?
||
in
valid?
keys
.
each
do
|
key
,
entry_class
|
if
@value
.
has_key?
(
key
)
entry
=
entry_class
.
new
(
@value
[
key
],
@root
,
self
)
else
entry
=
Node
::
Null
.
new
(
nil
,
@root
,
self
)
end
@nodes
[
key
]
=
entry
add_node
(
key
,
entry_class
)
end
nodes
.
each
(
&
:process!
)
...
...
@@ -38,22 +32,30 @@ module Gitlab
@nodes
.
values
end
def
errors
@errors
+
nodes
.
map
(
&
:errors
).
flatten
end
def
valid?
errors
.
none?
end
def
invalid?
!
valid?
end
def
leaf?
keys
.
none?
end
def
has_config?
@value
.
is_a?
(
Hash
)
end
def
keys
self
.
class
.
nodes
||
{}
end
def
errors
@errors
+
nodes
.
map
(
&
:errors
).
flatten
end
def
method_missing
(
name
,
*
args
)
super
unless
keys
.
has_key?
(
name
)
raise
InvalidError
unless
valid?
...
...
@@ -73,6 +75,18 @@ module Gitlab
raise
NotImplementedError
end
private
def
add_node
(
key
,
entry_class
)
if
@value
.
has_key?
(
key
)
entry
=
entry_class
.
new
(
@value
[
key
],
@root
,
self
)
else
entry
=
Node
::
Null
.
new
(
nil
,
@root
,
self
)
end
@nodes
[
key
]
=
entry
end
class
<<
self
attr_reader
:nodes
...
...
lib/gitlab/ci/config/node/null.rb
View file @
5065612a
...
...
@@ -8,6 +8,7 @@ module Gitlab
end
def
validate!
nil
end
def
method_missing
(
*
)
...
...
spec/lib/gitlab/ci/config/node/before_script_spec.rb
View file @
5065612a
...
...
@@ -18,6 +18,12 @@ describe Gitlab::Ci::Config::Node::BeforeScript do
expect
(
entry
.
errors
).
to
be_empty
end
end
describe
'#has_config?'
do
it
'does not have config'
do
expect
(
entry
).
not_to
have_config
end
end
end
context
'when entry value is not correct'
do
...
...
@@ -29,5 +35,11 @@ describe Gitlab::Ci::Config::Node::BeforeScript do
.
to
include
/should be an array of strings/
end
end
describe
'#invalid?'
do
it
'is not valid'
do
expect
(
entry
).
to
be_invalid
end
end
end
end
spec/lib/gitlab/ci/config/node/global_spec.rb
View file @
5065612a
...
...
@@ -35,6 +35,12 @@ describe Gitlab::Ci::Config::Node::Global do
end
end
describe
'#has_config?'
do
it
'has config'
do
expect
(
global
).
to
have_config
end
end
describe
'#leaf?'
do
it
'is not leaf'
do
expect
(
global
).
not_to
be_leaf
...
...
@@ -59,6 +65,12 @@ describe Gitlab::Ci::Config::Node::Global do
end
end
describe
'#invalid?'
do
it
'is not valid'
do
expect
(
global
).
to
be_invalid
end
end
describe
'#errors'
do
it
'reports errors from child nodes'
do
expect
(
global
.
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