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
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
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
27 deletions
+37
-27
lib/gitlab/ci/config/node/factory.rb
lib/gitlab/ci/config/node/factory.rb
+16
-12
lib/gitlab/ci/config/node/global.rb
lib/gitlab/ci/config/node/global.rb
+2
-2
lib/gitlab/ci/config/node/jobs.rb
lib/gitlab/ci/config/node/jobs.rb
+7
-13
spec/lib/gitlab/ci/config/node/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
def
create!
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.
# See issue #18775.
#
if
@attributes
[
:value
].
nil?
Node
::
Undefined
.
new
(
@node
)
fabricate
(
Node
::
Undefined
,
@node
)
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
private
def
fabricate
(
node
,
value
)
self
.
class
.
fabricate
(
node
,
value
,
@attributes
)
end
end
end
end
...
...
lib/gitlab/ci/config/node/global.rb
View file @
b0ae0d73
...
...
@@ -42,8 +42,8 @@ module Gitlab
def
initialize
(
config
)
return
super
unless
config
.
is_a?
(
Hash
)
jobs
=
config
.
except
(
*
self
.
class
.
nodes
.
keys
)
global
=
config
.
slice
(
*
self
.
class
.
nodes
.
keys
)
jobs
=
config
.
except
(
*
nodes
.
keys
)
global
=
config
.
slice
(
*
nodes
.
keys
)
super
(
global
.
merge
(
jobs:
jobs
))
end
...
...
lib/gitlab/ci/config/node/jobs.rb
View file @
b0ae0d73
...
...
@@ -33,20 +33,14 @@ module Gitlab
private
def
create_node
(
key
,
essence
)
fabricate_job
(
key
,
essence
).
tap
do
|
job
|
job
.
key
=
key
job
.
parent
=
self
job
.
description
=
"
#{
key
}
job definition."
end
end
def
create_node
(
key
,
value
)
node
=
key
.
to_s
.
start_with?
(
'.'
)
?
Node
::
HiddenJob
:
Node
::
Job
def
fabricate_job
(
key
,
essence
)
if
key
.
to_s
.
start_with?
(
'.'
)
Node
::
HiddenJob
.
new
(
essence
)
else
Node
::
Job
.
new
(
essence
)
end
attributes
=
{
key:
key
,
parent:
self
,
description:
"
#{
key
}
job definition."
}
Node
::
Factory
.
fabricate
(
node
,
value
,
attributes
)
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
let
(
:factory
)
{
described_class
.
new
(
entry_class
)
}
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
it
'creates entry with valid value'
do
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