BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
13 deletions
+52
-13
entry.rb
lib/gitlab/ci/config/node/entry.rb
+27
-13
null.rb
lib/gitlab/ci/config/node/null.rb
+1
-0
before_script_spec.rb
spec/lib/gitlab/ci/config/node/before_script_spec.rb
+12
-0
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
...
@@ -12,22 +12,16 @@ module Gitlab
@nodes
=
{}
@nodes
=
{}
@errors
=
[]
@errors
=
[]
unless
leaf?
||
value
.
is_a?
(
Hash
)
unless
leaf?
||
has_config?
@errors
<<
'should be a configuration entry with hash value'
@errors
<<
'should be a configuration entry with hash value'
end
end
end
end
def
process!
def
process!
return
if
leaf?
||
!
valid?
return
if
leaf?
||
in
valid?
keys
.
each
do
|
key
,
entry_class
|
keys
.
each
do
|
key
,
entry_class
|
if
@value
.
has_key?
(
key
)
add_node
(
key
,
entry_class
)
entry
=
entry_class
.
new
(
@value
[
key
],
@root
,
self
)
else
entry
=
Node
::
Null
.
new
(
nil
,
@root
,
self
)
end
@nodes
[
key
]
=
entry
end
end
nodes
.
each
(
&
:process!
)
nodes
.
each
(
&
:process!
)
...
@@ -38,22 +32,30 @@ module Gitlab
...
@@ -38,22 +32,30 @@ module Gitlab
@nodes
.
values
@nodes
.
values
end
end
def
errors
@errors
+
nodes
.
map
(
&
:errors
).
flatten
end
def
valid?
def
valid?
errors
.
none?
errors
.
none?
end
end
def
invalid?
!
valid?
end
def
leaf?
def
leaf?
keys
.
none?
keys
.
none?
end
end
def
has_config?
@value
.
is_a?
(
Hash
)
end
def
keys
def
keys
self
.
class
.
nodes
||
{}
self
.
class
.
nodes
||
{}
end
end
def
errors
@errors
+
nodes
.
map
(
&
:errors
).
flatten
end
def
method_missing
(
name
,
*
args
)
def
method_missing
(
name
,
*
args
)
super
unless
keys
.
has_key?
(
name
)
super
unless
keys
.
has_key?
(
name
)
raise
InvalidError
unless
valid?
raise
InvalidError
unless
valid?
...
@@ -73,6 +75,18 @@ module Gitlab
...
@@ -73,6 +75,18 @@ module Gitlab
raise
NotImplementedError
raise
NotImplementedError
end
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
class
<<
self
attr_reader
:nodes
attr_reader
:nodes
...
...
lib/gitlab/ci/config/node/null.rb
View file @
5065612a
...
@@ -8,6 +8,7 @@ module Gitlab
...
@@ -8,6 +8,7 @@ module Gitlab
end
end
def
validate!
def
validate!
nil
end
end
def
method_missing
(
*
)
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
...
@@ -18,6 +18,12 @@ describe Gitlab::Ci::Config::Node::BeforeScript do
expect
(
entry
.
errors
).
to
be_empty
expect
(
entry
.
errors
).
to
be_empty
end
end
end
end
describe
'#has_config?'
do
it
'does not have config'
do
expect
(
entry
).
not_to
have_config
end
end
end
end
context
'when entry value is not correct'
do
context
'when entry value is not correct'
do
...
@@ -29,5 +35,11 @@ describe Gitlab::Ci::Config::Node::BeforeScript do
...
@@ -29,5 +35,11 @@ describe Gitlab::Ci::Config::Node::BeforeScript do
.
to
include
/should be an array of strings/
.
to
include
/should be an array of strings/
end
end
end
end
describe
'#invalid?'
do
it
'is not valid'
do
expect
(
entry
).
to
be_invalid
end
end
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
...
@@ -35,6 +35,12 @@ describe Gitlab::Ci::Config::Node::Global do
end
end
end
end
describe
'#has_config?'
do
it
'has config'
do
expect
(
global
).
to
have_config
end
end
describe
'#leaf?'
do
describe
'#leaf?'
do
it
'is not leaf'
do
it
'is not leaf'
do
expect
(
global
).
not_to
be_leaf
expect
(
global
).
not_to
be_leaf
...
@@ -59,6 +65,12 @@ describe Gitlab::Ci::Config::Node::Global do
...
@@ -59,6 +65,12 @@ describe Gitlab::Ci::Config::Node::Global do
end
end
end
end
describe
'#invalid?'
do
it
'is not valid'
do
expect
(
global
).
to
be_invalid
end
end
describe
'#errors'
do
describe
'#errors'
do
it
'reports errors from child nodes'
do
it
'reports errors from child nodes'
do
expect
(
global
.
errors
)
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