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
Boxiang Sun
gitlab-ce
Commits
87fe50f2
Commit
87fe50f2
authored
Jun 08, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delegate Ci config entry value to single method
parent
cba266aa
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
25 deletions
+48
-25
lib/gitlab/ci/config/node/before_script.rb
lib/gitlab/ci/config/node/before_script.rb
+1
-3
lib/gitlab/ci/config/node/entry.rb
lib/gitlab/ci/config/node/entry.rb
+24
-10
lib/gitlab/ci/config/node/global.rb
lib/gitlab/ci/config/node/global.rb
+0
-4
lib/gitlab/ci/config/node/null.rb
lib/gitlab/ci/config/node/null.rb
+7
-0
spec/lib/gitlab/ci/config/node/before_script_spec.rb
spec/lib/gitlab/ci/config/node/before_script_spec.rb
+2
-8
spec/lib/gitlab/ci/config/node/global_spec.rb
spec/lib/gitlab/ci/config/node/global_spec.rb
+8
-0
spec/lib/gitlab/ci/config/node/null_spec.rb
spec/lib/gitlab/ci/config/node/null_spec.rb
+6
-0
No files found.
lib/gitlab/ci/config/node/before_script.rb
View file @
87fe50f2
...
@@ -9,9 +9,7 @@ module Gitlab
...
@@ -9,9 +9,7 @@ module Gitlab
'Script that is executed before the one defined in a job.'
'Script that is executed before the one defined in a job.'
end
end
def
script
def
value
raise
unless
valid?
@value
.
join
(
"
\n
"
)
@value
.
join
(
"
\n
"
)
end
end
...
...
lib/gitlab/ci/config/node/entry.rb
View file @
87fe50f2
...
@@ -3,17 +3,14 @@ module Gitlab
...
@@ -3,17 +3,14 @@ module Gitlab
class
Config
class
Config
module
Node
module
Node
class
Entry
class
Entry
attr_reader
:value
,
:nodes
,
:parent
class
InvalidError
<
StandardError
;
end
def
initialize
(
value
,
root
=
nil
,
parent
=
nil
)
def
initialize
(
value
,
root
=
nil
,
parent
=
nil
)
@value
=
value
@value
=
value
@root
=
root
@root
=
root
@parent
=
parent
@parent
=
parent
@nodes
,
@errors
=
[],
[]
@nodes
=
{}
@errors
=
[]
keys
.
each_key
do
|
key
|
instance_variable_set
(
"@
#{
key
}
"
,
Null
.
new
(
nil
,
root
,
self
))
end
unless
leaf?
||
value
.
is_a?
(
Hash
)
unless
leaf?
||
value
.
is_a?
(
Hash
)
@errors
<<
'should be a configuration entry with hash value'
@errors
<<
'should be a configuration entry with hash value'
...
@@ -24,17 +21,23 @@ module Gitlab
...
@@ -24,17 +21,23 @@ module Gitlab
return
if
leaf?
||
!
valid?
return
if
leaf?
||
!
valid?
keys
.
each
do
|
key
,
entry_class
|
keys
.
each
do
|
key
,
entry_class
|
next
unless
@value
.
has_key?
(
key
)
if
@value
.
has_key?
(
key
)
entry
=
entry_class
.
new
(
@value
[
key
],
@root
,
self
)
entry
=
entry_class
.
new
(
@value
[
key
],
@root
,
self
)
instance_variable_set
(
"@
#{
key
}
"
,
entry
)
else
@nodes
.
append
(
entry
)
entry
=
Node
::
Null
.
new
(
nil
,
@root
,
self
)
end
@nodes
[
key
]
=
entry
end
end
nodes
.
each
(
&
:process!
)
nodes
.
each
(
&
:process!
)
nodes
.
each
(
&
:validate!
)
nodes
.
each
(
&
:validate!
)
end
end
def
nodes
@nodes
.
values
end
def
errors
def
errors
@errors
+
nodes
.
map
(
&
:errors
).
flatten
@errors
+
nodes
.
map
(
&
:errors
).
flatten
end
end
...
@@ -51,6 +54,17 @@ module Gitlab
...
@@ -51,6 +54,17 @@ module Gitlab
self
.
class
.
nodes
||
{}
self
.
class
.
nodes
||
{}
end
end
def
method_missing
(
name
,
*
args
)
super
unless
keys
.
has_key?
(
name
)
raise
InvalidError
unless
valid?
@nodes
[
name
].
value
end
def
value
raise
NotImplementedError
end
def
validate!
def
validate!
raise
NotImplementedError
raise
NotImplementedError
end
end
...
...
lib/gitlab/ci/config/node/global.rb
View file @
87fe50f2
...
@@ -4,10 +4,6 @@ module Gitlab
...
@@ -4,10 +4,6 @@ module Gitlab
module
Node
module
Node
class
Global
<
Entry
class
Global
<
Entry
add_node
:before_script
,
BeforeScript
add_node
:before_script
,
BeforeScript
def
before_script
@before_script
.
script
end
end
end
end
end
end
end
...
...
lib/gitlab/ci/config/node/null.rb
View file @
87fe50f2
...
@@ -3,6 +3,13 @@ module Gitlab
...
@@ -3,6 +3,13 @@ module Gitlab
class
Config
class
Config
module
Node
module
Node
class
Null
<
Entry
class
Null
<
Entry
def
value
nil
end
def
validate!
end
def
method_missing
(
*
)
def
method_missing
(
*
)
nil
nil
end
end
...
...
spec/lib/gitlab/ci/config/node/before_script_spec.rb
View file @
87fe50f2
...
@@ -7,9 +7,9 @@ describe Gitlab::Ci::Config::Node::BeforeScript do
...
@@ -7,9 +7,9 @@ describe Gitlab::Ci::Config::Node::BeforeScript do
context
'when entry value is correct'
do
context
'when entry value is correct'
do
let
(
:value
)
{
[
'ls'
,
'pwd'
]
}
let
(
:value
)
{
[
'ls'
,
'pwd'
]
}
describe
'#
script
'
do
describe
'#
value
'
do
it
'returns concatenated command'
do
it
'returns concatenated command'
do
expect
(
entry
.
script
).
to
eq
"ls
\n
pwd"
expect
(
entry
.
value
).
to
eq
"ls
\n
pwd"
end
end
end
end
...
@@ -29,11 +29,5 @@ describe Gitlab::Ci::Config::Node::BeforeScript do
...
@@ -29,11 +29,5 @@ 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
'#script'
do
it
'raises error'
do
expect
{
entry
.
script
}.
to
raise_error
end
end
end
end
end
end
spec/lib/gitlab/ci/config/node/global_spec.rb
View file @
87fe50f2
...
@@ -65,6 +65,14 @@ describe Gitlab::Ci::Config::Node::Global do
...
@@ -65,6 +65,14 @@ describe Gitlab::Ci::Config::Node::Global do
.
to
include
'before_script should be an array of strings'
.
to
include
'before_script should be an array of strings'
end
end
end
end
describe
'#before_script'
do
it
'raises error'
do
expect
{
global
.
before_script
}.
to
raise_error
(
Gitlab
::
Ci
::
Config
::
Node
::
Entry
::
InvalidError
)
end
end
end
end
context
'when value is not a hash'
do
context
'when value is not a hash'
do
...
...
spec/lib/gitlab/ci/config/node/null_spec.rb
View file @
87fe50f2
...
@@ -14,4 +14,10 @@ describe Gitlab::Ci::Config::Node::Null do
...
@@ -14,4 +14,10 @@ describe Gitlab::Ci::Config::Node::Null do
expect
(
entry
.
any_method
).
to
be
nil
expect
(
entry
.
any_method
).
to
be
nil
end
end
end
end
describe
'#value'
do
it
'returns nill'
do
expect
(
entry
.
value
).
to
be
nil
end
end
end
end
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