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
41bcbdd8
Commit
41bcbdd8
authored
Jul 15, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add metadata to new CI config and expose job name
parent
615c9730
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
60 additions
and
69 deletions
+60
-69
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+2
-2
lib/gitlab/ci/config/node/configurable.rb
lib/gitlab/ci/config/node/configurable.rb
+1
-2
lib/gitlab/ci/config/node/entry.rb
lib/gitlab/ci/config/node/entry.rb
+2
-5
lib/gitlab/ci/config/node/factory.rb
lib/gitlab/ci/config/node/factory.rb
+5
-5
lib/gitlab/ci/config/node/global.rb
lib/gitlab/ci/config/node/global.rb
+2
-3
lib/gitlab/ci/config/node/job.rb
lib/gitlab/ci/config/node/job.rb
+9
-11
lib/gitlab/ci/config/node/jobs.rb
lib/gitlab/ci/config/node/jobs.rb
+5
-4
spec/lib/gitlab/ci/config/node/factory_spec.rb
spec/lib/gitlab/ci/config/node/factory_spec.rb
+14
-23
spec/lib/gitlab/ci/config/node/global_spec.rb
spec/lib/gitlab/ci/config/node/global_spec.rb
+8
-5
spec/lib/gitlab/ci/config/node/job_spec.rb
spec/lib/gitlab/ci/config/node/job_spec.rb
+5
-4
spec/lib/gitlab/ci/config/node/jobs_spec.rb
spec/lib/gitlab/ci/config/node/jobs_spec.rb
+7
-5
No files found.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
41bcbdd8
...
...
@@ -82,7 +82,7 @@ module Ci
stage:
job
[
:stage
],
commands:
[
job
[
:before_script
]
||
@before_script
,
job
[
:script
]].
flatten
.
compact
.
join
(
"
\n
"
),
tag_list:
job
[
:tags
]
||
[],
name:
name
,
name:
job
[
:name
]
,
only:
job
[
:only
],
except:
job
[
:except
],
allow_failure:
job
[
:allow_failure
]
||
false
,
...
...
@@ -113,7 +113,7 @@ module Ci
def
validate_job_keys!
(
name
,
job
)
job
.
keys
.
each
do
|
key
|
unless
ALLOWED_JOB_KEYS
.
include?
key
unless
(
ALLOWED_JOB_KEYS
+
%i[name]
)
.
include?
key
raise
ValidationError
,
"
#{
name
}
job: unknown parameter
#{
key
}
"
end
end
...
...
lib/gitlab/ci/config/node/configurable.rb
View file @
41bcbdd8
...
...
@@ -28,8 +28,7 @@ module Gitlab
def
create
(
key
,
factory
)
factory
.
value
(
@config
[
key
])
.
parent
(
self
)
.
with
(
key:
key
)
.
with
(
key:
key
,
parent:
self
)
factory
.
create!
end
...
...
lib/gitlab/ci/config/node/entry.rb
View file @
41bcbdd8
...
...
@@ -11,13 +11,10 @@ module Gitlab
attr_reader
:config
,
:attributes
attr_accessor
:key
,
:parent
,
:description
def
initialize
(
config
,
**
attributes
)
def
initialize
(
config
,
**
metadata
)
@config
=
config
@entries
=
{}
(
@attributes
=
attributes
).
each
do
|
attribute
,
value
|
public_send
(
"
#{
attribute
}
="
,
value
)
end
@metadata
=
metadata
@validator
=
self
.
class
.
validator
.
new
(
self
)
@validator
.
validate
(
:new
)
...
...
lib/gitlab/ci/config/node/factory.rb
View file @
41bcbdd8
...
...
@@ -10,6 +10,7 @@ module Gitlab
def
initialize
(
node
)
@node
=
node
@metadata
=
{}
@attributes
=
{}
end
...
...
@@ -18,8 +19,8 @@ module Gitlab
self
end
def
parent
(
parent
)
@
parent
=
parent
def
metadata
(
metadata
)
@
metadata
.
merge!
(
metadata
)
self
end
...
...
@@ -30,7 +31,6 @@ module Gitlab
def
create!
raise
InvalidFactory
unless
defined?
(
@value
)
raise
InvalidFactory
unless
defined?
(
@parent
)
##
# We assume that unspecified entry is undefined.
...
...
@@ -60,9 +60,9 @@ module Gitlab
end
def
fabricate
(
node
,
value
=
nil
)
node
.
new
(
value
).
tap
do
|
entry
|
node
.
new
(
value
,
@metadata
).
tap
do
|
entry
|
entry
.
key
=
@attributes
[
:key
]
entry
.
parent
=
@attributes
[
:parent
]
||
@parent
entry
.
parent
=
@attributes
[
:parent
]
entry
.
description
=
@attributes
[
:description
]
end
end
...
...
lib/gitlab/ci/config/node/global.rb
View file @
41bcbdd8
...
...
@@ -54,9 +54,8 @@ module Gitlab
def
compose_jobs!
factory
=
Node
::
Factory
.
new
(
Node
::
Jobs
)
.
value
(
@config
.
except
(
*
nodes
.
keys
))
.
parent
(
self
)
.
with
(
key: :jobs
,
global:
self
)
.
with
(
description:
'Jobs definition for this pipeline'
)
.
with
(
key: :jobs
,
parent:
self
,
description:
'Jobs definition for this pipeline'
)
@entries
[
:jobs
]
=
factory
.
create!
end
...
...
lib/gitlab/ci/config/node/job.rb
View file @
41bcbdd8
...
...
@@ -10,12 +10,9 @@ module Gitlab
validations
do
validates
:config
,
presence:
true
with_options
on: :processed
do
validates
:name
,
presence:
true
validates
:name
,
type:
Symbol
end
end
node
:before_script
,
Script
,
description:
'Global before script overridden in this job.'
...
...
@@ -38,7 +35,7 @@ module Gitlab
helpers
:before_script
,
:script
,
:stage
,
:type
,
:after_script
,
:cache
def
name
@
key
@
metadata
[
:name
]
end
def
value
...
...
@@ -48,11 +45,12 @@ module Gitlab
private
def
to_hash
{
before_script:
before_script_value
,
script:
script_value
,
stage:
stage_value
,
cache:
cache_value
,
after_script:
after_script_value
}
{
name:
name
,
before_script:
before_script
,
script:
script
,
stage:
stage
,
cache:
cache
,
after_script:
after_script
}
end
def
compose!
...
...
lib/gitlab/ci/config/node/jobs.rb
View file @
41bcbdd8
...
...
@@ -31,14 +31,15 @@ module Gitlab
private
def
create
(
name
,
config
)
Node
::
Factory
.
new
(
node
(
name
))
Node
::
Factory
.
new
(
job_class
(
name
))
.
value
(
config
||
{})
.
parent
(
self
)
.
with
(
key:
name
,
description:
"
#{
name
}
job definition."
)
.
metadata
(
name:
name
)
.
with
(
key:
name
,
parent:
self
,
description:
"
#{
name
}
job definition."
)
.
create!
end
def
node
(
name
)
def
job_class
(
name
)
if
name
.
to_s
.
start_with?
(
'.'
)
Node
::
HiddenJob
else
...
...
spec/lib/gitlab/ci/config/node/factory_spec.rb
View file @
41bcbdd8
...
...
@@ -4,32 +4,20 @@ describe Gitlab::Ci::Config::Node::Factory do
describe
'#create!'
do
let
(
:factory
)
{
described_class
.
new
(
node
)
}
let
(
:node
)
{
Gitlab
::
Ci
::
Config
::
Node
::
Script
}
let
(
:parent
)
{
double
(
'parent'
)
}
context
'when setting a concrete value'
do
it
'creates entry with valid value'
do
entry
=
factory
.
value
([
'ls'
,
'pwd'
])
.
parent
(
parent
)
.
create!
expect
(
entry
.
value
).
to
eq
[
'ls'
,
'pwd'
]
end
it
'sets parent attributes'
do
entry
=
factory
.
value
(
'ls'
)
.
parent
(
parent
)
.
create!
expect
(
entry
.
parent
).
to
eq
parent
end
context
'when setting description'
do
it
'creates entry with description'
do
entry
=
factory
.
value
([
'ls'
,
'pwd'
])
.
parent
(
parent
)
.
with
(
description:
'test description'
)
.
create!
...
...
@@ -42,7 +30,6 @@ describe Gitlab::Ci::Config::Node::Factory do
it
'creates entry with custom key'
do
entry
=
factory
.
value
([
'ls'
,
'pwd'
])
.
parent
(
parent
)
.
with
(
key:
'test key'
)
.
create!
...
...
@@ -56,7 +43,6 @@ describe Gitlab::Ci::Config::Node::Factory do
it
'creates entry with valid parent'
do
entry
=
factory
.
value
(
'ls'
)
.
parent
(
parent
)
.
with
(
parent:
object
)
.
create!
...
...
@@ -73,23 +59,28 @@ describe Gitlab::Ci::Config::Node::Factory do
end
end
context
'when not setting parent object'
do
it
'raises error'
do
expect
{
factory
.
value
(
'ls'
).
create!
}.
to
raise_error
(
Gitlab
::
Ci
::
Config
::
Node
::
Factory
::
InvalidFactory
)
end
end
context
'when creating entry with nil value'
do
it
'creates an undefined entry'
do
entry
=
factory
.
value
(
nil
)
.
parent
(
parent
)
.
create!
expect
(
entry
).
to
be_an_instance_of
Gitlab
::
Ci
::
Config
::
Node
::
Undefined
end
end
context
'when passing metadata'
do
let
(
:node
)
{
spy
(
'node'
)
}
it
'passes metadata as a parameter'
do
factory
.
value
(
'some value'
)
.
metadata
(
some:
'hash'
)
.
create!
expect
(
node
).
to
have_received
(
:new
)
.
with
(
'some value'
,
{
some:
'hash'
})
end
end
end
end
spec/lib/gitlab/ci/config/node/global_spec.rb
View file @
41bcbdd8
...
...
@@ -128,11 +128,14 @@ describe Gitlab::Ci::Config::Node::Global do
describe
'#jobs'
do
it
'returns jobs configuration'
do
expect
(
global
.
jobs
)
.
to
eq
(
rspec:
{
script:
%w[rspec ls]
,
expect
(
global
.
jobs
).
to
eq
(
rspec:
{
name: :rspec
,
script:
%w[rspec ls]
,
stage:
'test'
},
spinach:
{
script:
%w[spinach]
,
stage:
'test'
})
spinach:
{
name: :spinach
,
script:
%w[spinach]
,
stage:
'test'
}
)
end
end
end
...
...
spec/lib/gitlab/ci/config/node/job_spec.rb
View file @
41bcbdd8
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Job
do
let
(
:entry
)
{
described_class
.
new
(
config
,
key
: :rspec
)
}
let
(
:entry
)
{
described_class
.
new
(
config
,
name
: :rspec
)
}
before
do
entry
.
process!
...
...
@@ -19,7 +19,7 @@ describe Gitlab::Ci::Config::Node::Job do
end
context
'when job name is empty'
do
let
(
:entry
)
{
described_class
.
new
(
config
,
key
:
''
.
to_sym
)
}
let
(
:entry
)
{
described_class
.
new
(
config
,
name
:
''
.
to_sym
)
}
it
'reports error'
do
expect
(
entry
.
errors
)
...
...
@@ -35,7 +35,7 @@ describe Gitlab::Ci::Config::Node::Job do
describe
'#errors'
do
it
'reports error about a config type'
do
expect
(
entry
.
errors
)
.
to
include
'
rspec
config should be a hash'
.
to
include
'
job
config should be a hash'
end
end
end
...
...
@@ -62,7 +62,8 @@ describe Gitlab::Ci::Config::Node::Job do
it
'returns correct value'
do
expect
(
entry
.
value
)
.
to
eq
(
before_script:
%w[ls pwd]
,
.
to
eq
(
name: :rspec
,
before_script:
%w[ls pwd]
,
script:
%w[rspec]
,
stage:
'test'
,
after_script:
%w[cleanup]
)
...
...
spec/lib/gitlab/ci/config/node/jobs_spec.rb
View file @
41bcbdd8
...
...
@@ -61,10 +61,12 @@ describe Gitlab::Ci::Config::Node::Jobs do
describe
'#value'
do
it
'returns key value'
do
expect
(
entry
.
value
)
.
to
eq
(
rspec:
{
script:
%w[rspec]
,
expect
(
entry
.
value
).
to
eq
(
rspec:
{
name: :rspec
,
script:
%w[rspec]
,
stage:
'test'
},
spinach:
{
script:
%w[spinach]
,
spinach:
{
name: :spinach
,
script:
%w[spinach]
,
stage:
'test'
})
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