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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
12080ba1
Commit
12080ba1
authored
Jun 10, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify new ci config entry class interface
parent
828a15bc
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
62 deletions
+44
-62
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
+3
-12
lib/gitlab/ci/config/node/null.rb
lib/gitlab/ci/config/node/null.rb
+6
-6
lib/gitlab/ci/config/node/script.rb
lib/gitlab/ci/config/node/script.rb
+2
-2
spec/lib/gitlab/ci/config/node/global_spec.rb
spec/lib/gitlab/ci/config/node/global_spec.rb
+0
-12
spec/lib/gitlab/ci/config/node/null_spec.rb
spec/lib/gitlab/ci/config/node/null_spec.rb
+1
-1
spec/lib/gitlab/ci/config/node/script_spec.rb
spec/lib/gitlab/ci/config/node/script_spec.rb
+29
-26
No files found.
lib/gitlab/ci/config/node/configurable.rb
View file @
12080ba1
...
@@ -19,7 +19,7 @@ module Gitlab
...
@@ -19,7 +19,7 @@ module Gitlab
def
initialize
(
*
)
def
initialize
(
*
)
super
super
unless
leaf?
||
has_config?
unless
@value
.
is_a?
(
Hash
)
@errors
<<
'should be a configuration entry with hash value'
@errors
<<
'should be a configuration entry with hash value'
end
end
end
end
...
@@ -39,9 +39,9 @@ module Gitlab
...
@@ -39,9 +39,9 @@ module Gitlab
def
create_entry
(
key
,
entry_class
)
def
create_entry
(
key
,
entry_class
)
if
@value
.
has_key?
(
key
)
if
@value
.
has_key?
(
key
)
entry_class
.
new
(
@value
[
key
]
,
@root
,
self
)
entry_class
.
new
(
@value
[
key
])
else
else
Node
::
Null
.
new
(
nil
,
@root
,
self
)
Node
::
Null
.
new
(
nil
)
end
end
end
end
...
...
lib/gitlab/ci/config/node/entry.rb
View file @
12080ba1
...
@@ -10,16 +10,15 @@ module Gitlab
...
@@ -10,16 +10,15 @@ module Gitlab
attr_accessor
:description
attr_accessor
:description
def
initialize
(
value
,
root
=
nil
,
parent
=
nil
)
def
initialize
(
value
)
@value
=
value
@value
=
value
@root
=
root
@parent
=
parent
@nodes
=
{}
@nodes
=
{}
@errors
=
[]
@errors
=
[]
end
end
def
process!
def
process!
return
if
leaf?
||
invalid?
return
if
leaf?
return
unless
valid?
compose!
compose!
...
@@ -41,18 +40,10 @@ module Gitlab
...
@@ -41,18 +40,10 @@ module Gitlab
errors
.
none?
errors
.
none?
end
end
def
invalid?
!
valid?
end
def
leaf?
def
leaf?
allowed_nodes
.
none?
allowed_nodes
.
none?
end
end
def
has_config?
@value
.
is_a?
(
Hash
)
end
def
errors
def
errors
@errors
+
nodes
.
map
(
&
:errors
).
flatten
@errors
+
nodes
.
map
(
&
:errors
).
flatten
end
end
...
...
lib/gitlab/ci/config/node/null.rb
View file @
12080ba1
module
Gitlab
module
Gitlab
module
Ci
module
Ci
class
Config
class
Config
##
# This class represents a configuration entry that is not being used
# in configuration file.
#
# This implements Null Object pattern.
#
module
Node
module
Node
##
# This class represents a configuration entry that is not being used
# in configuration file.
#
# This implements Null Object pattern.
#
class
Null
<
Entry
class
Null
<
Entry
def
value
def
value
nil
nil
...
...
lib/gitlab/ci/config/node/script.rb
View file @
12080ba1
...
@@ -6,8 +6,8 @@ module Gitlab
...
@@ -6,8 +6,8 @@ module Gitlab
# Entry that represents a script.
# Entry that represents a script.
#
#
# Each element in the value array is a command that will be executed
# Each element in the value array is a command that will be executed
# by GitLab Runner. Currently we concatenate th
is
commands with
# by GitLab Runner. Currently we concatenate th
ese
commands with
# new line character as a separator
what is compatbi
le with
# new line character as a separator
, what is compatib
le with
# implementation in Runner.
# implementation in Runner.
#
#
class
Script
<
Entry
class
Script
<
Entry
...
...
spec/lib/gitlab/ci/config/node/global_spec.rb
View file @
12080ba1
...
@@ -49,12 +49,6 @@ describe Gitlab::Ci::Config::Node::Global do
...
@@ -49,12 +49,6 @@ 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
...
@@ -91,12 +85,6 @@ describe Gitlab::Ci::Config::Node::Global do
...
@@ -91,12 +85,6 @@ 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
)
...
...
spec/lib/gitlab/ci/config/node/null_spec.rb
View file @
12080ba1
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Null
do
describe
Gitlab
::
Ci
::
Config
::
Node
::
Null
do
let
(
:entry
)
{
described_class
.
new
(
double
,
double
)
}
let
(
:entry
)
{
described_class
.
new
(
nil
)
}
describe
'#leaf?'
do
describe
'#leaf?'
do
it
'is leaf node'
do
it
'is leaf node'
do
...
...
spec/lib/gitlab/ci/config/node/script_spec.rb
View file @
12080ba1
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Script
do
describe
Gitlab
::
Ci
::
Config
::
Node
::
Script
do
let
(
:entry
)
{
described_class
.
new
(
value
,
double
)}
let
(
:entry
)
{
described_class
.
new
(
value
)
}
before
{
entry
.
validate!
}
context
'when entry value is correct
'
do
describe
'#validate!
'
do
let
(
:value
)
{
[
'ls'
,
'pwd'
]
}
before
{
entry
.
validate!
}
describe
'#value'
do
context
'when entry value is correct'
do
it
'returns concatenated command'
do
let
(
:value
)
{
[
'ls'
,
'pwd'
]
}
expect
(
entry
.
value
).
to
eq
"ls
\n
pwd"
describe
'#value'
do
it
'returns concatenated command'
do
expect
(
entry
.
value
).
to
eq
"ls
\n
pwd"
end
end
end
end
describe
'#errors'
do
describe
'#errors'
do
it
'does not append errors'
do
it
'does not append errors'
do
expect
(
entry
.
errors
).
to
be_empty
expect
(
entry
.
errors
).
to
be_empty
end
end
end
end
describe
'#has_config?'
do
describe
'#valid?'
do
it
'does not have config'
do
it
'is valid'
do
expect
(
entry
).
not_to
have_config
expect
(
entry
).
to
be_valid
end
end
end
end
end
end
context
'when entry value is not correct'
do
context
'when entry value is not correct'
do
let
(
:value
)
{
'ls'
}
let
(
:value
)
{
'ls'
}
describe
'#errors'
do
describe
'#errors'
do
it
'saves errors'
do
it
'saves errors'
do
expect
(
entry
.
errors
)
expect
(
entry
.
errors
)
.
to
include
/should be an array of strings/
.
to
include
/should be an array of strings/
end
end
end
end
describe
'#invalid?'
do
describe
'#valid?'
do
it
'is not valid'
do
it
'is not valid'
do
expect
(
entry
).
to
be_invalid
expect
(
entry
).
not_to
be_valid
end
end
end
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