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
b0ae0d73
Commit
b0ae0d73
authored
Jul 07, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use only node factory to create CI config entries
parent
6f02da2c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
27 deletions
+37
-27
factory.rb
lib/gitlab/ci/config/node/factory.rb
+16
-12
global.rb
lib/gitlab/ci/config/node/global.rb
+2
-2
jobs.rb
lib/gitlab/ci/config/node/jobs.rb
+7
-13
factory_spec.rb
spec/lib/gitlab/ci/config/node/factory_spec.rb
+12
-0
No files found.
lib/gitlab/ci/config/node/factory.rb
View file @
b0ae0d73
...
@@ -21,26 +21,30 @@ module Gitlab
...
@@ -21,26 +21,30 @@ module Gitlab
def
create!
def
create!
raise
InvalidFactory
unless
@attributes
.
has_key?
(
:value
)
raise
InvalidFactory
unless
@attributes
.
has_key?
(
:value
)
fabricate
.
tap
do
|
entry
|
entry
.
key
=
@attributes
[
:key
]
entry
.
parent
=
@attributes
[
:parent
]
entry
.
description
=
@attributes
[
:description
]
end
end
private
def
fabricate
##
##
# We assume that unspecified entry is undefined.
# We assume that unspecified entry is undefined.
# See issue #18775.
# See issue #18775.
#
#
if
@attributes
[
:value
].
nil?
if
@attributes
[
:value
].
nil?
Node
::
Undefined
.
new
(
@node
)
fabricate
(
Node
::
Undefined
,
@node
)
else
else
@node
.
new
(
@attributes
[
:value
])
fabricate
(
@node
,
@attributes
[
:value
])
end
end
def
self
.
fabricate
(
node
,
value
,
**
attributes
)
node
.
new
(
value
).
tap
do
|
entry
|
entry
.
key
=
attributes
[
:key
]
entry
.
parent
=
attributes
[
:parent
]
entry
.
description
=
attributes
[
:description
]
end
end
end
end
private
def
fabricate
(
node
,
value
)
self
.
class
.
fabricate
(
node
,
value
,
@attributes
)
end
end
end
end
end
end
end
...
...
lib/gitlab/ci/config/node/global.rb
View file @
b0ae0d73
...
@@ -42,8 +42,8 @@ module Gitlab
...
@@ -42,8 +42,8 @@ module Gitlab
def
initialize
(
config
)
def
initialize
(
config
)
return
super
unless
config
.
is_a?
(
Hash
)
return
super
unless
config
.
is_a?
(
Hash
)
jobs
=
config
.
except
(
*
self
.
class
.
nodes
.
keys
)
jobs
=
config
.
except
(
*
nodes
.
keys
)
global
=
config
.
slice
(
*
self
.
class
.
nodes
.
keys
)
global
=
config
.
slice
(
*
nodes
.
keys
)
super
(
global
.
merge
(
jobs:
jobs
))
super
(
global
.
merge
(
jobs:
jobs
))
end
end
...
...
lib/gitlab/ci/config/node/jobs.rb
View file @
b0ae0d73
...
@@ -33,20 +33,14 @@ module Gitlab
...
@@ -33,20 +33,14 @@ module Gitlab
private
private
def
create_node
(
key
,
essence
)
def
create_node
(
key
,
value
)
fabricate_job
(
key
,
essence
).
tap
do
|
job
|
node
=
key
.
to_s
.
start_with?
(
'.'
)
?
Node
::
HiddenJob
:
Node
::
Job
job
.
key
=
key
job
.
parent
=
self
job
.
description
=
"
#{
key
}
job definition."
end
end
def
fabricate_job
(
key
,
essence
)
attributes
=
{
key:
key
,
if
key
.
to_s
.
start_with?
(
'.'
)
parent:
self
,
Node
::
HiddenJob
.
new
(
essence
)
description:
"
#{
key
}
job definition."
}
else
Node
::
Job
.
new
(
essence
)
Node
::
Factory
.
fabricate
(
node
,
value
,
attributes
)
end
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/config/node/factory_spec.rb
View file @
b0ae0d73
...
@@ -5,6 +5,18 @@ describe Gitlab::Ci::Config::Node::Factory do
...
@@ -5,6 +5,18 @@ describe Gitlab::Ci::Config::Node::Factory do
let
(
:factory
)
{
described_class
.
new
(
entry_class
)
}
let
(
:factory
)
{
described_class
.
new
(
entry_class
)
}
let
(
:entry_class
)
{
Gitlab
::
Ci
::
Config
::
Node
::
Script
}
let
(
:entry_class
)
{
Gitlab
::
Ci
::
Config
::
Node
::
Script
}
describe
'.fabricate'
do
it
'fabricates entry with attributes set'
do
fabricated
=
described_class
.
fabricate
(
entry_class
,
[
'ls'
],
parent:
factory
,
key: :test
)
expect
(
fabricated
.
parent
).
to
be
factory
expect
(
fabricated
.
key
).
to
eq
:test
expect
(
fabricated
.
value
).
to
eq
[
'ls'
]
end
end
context
'when setting up a value'
do
context
'when setting up a value'
do
it
'creates entry with valid value'
do
it
'creates entry with valid value'
do
entry
=
factory
entry
=
factory
...
...
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