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
56ae9f6b
Commit
56ae9f6b
authored
Jul 14, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve CI job entry validations in new config
parent
036e297c
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
54 additions
and
39 deletions
+54
-39
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+0
-7
lib/gitlab/ci/config/node/configurable.rb
lib/gitlab/ci/config/node/configurable.rb
+4
-2
lib/gitlab/ci/config/node/job.rb
lib/gitlab/ci/config/node/job.rb
+12
-8
lib/gitlab/ci/config/node/jobs.rb
lib/gitlab/ci/config/node/jobs.rb
+6
-5
lib/gitlab/ci/config/node/validator.rb
lib/gitlab/ci/config/node/validator.rb
+9
-2
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+2
-2
spec/lib/gitlab/ci/config/node/global_spec.rb
spec/lib/gitlab/ci/config/node/global_spec.rb
+6
-8
spec/lib/gitlab/ci/config/node/job_spec.rb
spec/lib/gitlab/ci/config/node/job_spec.rb
+13
-3
spec/lib/gitlab/ci/config/node/jobs_spec.rb
spec/lib/gitlab/ci/config/node/jobs_spec.rb
+2
-2
No files found.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
56ae9f6b
...
@@ -102,7 +102,6 @@ module Ci
...
@@ -102,7 +102,6 @@ module Ci
def
validate_job!
(
name
,
job
)
def
validate_job!
(
name
,
job
)
raise
ValidationError
,
"Unknown parameter:
#{
name
}
"
unless
job
.
is_a?
(
Hash
)
&&
job
.
has_key?
(
:script
)
raise
ValidationError
,
"Unknown parameter:
#{
name
}
"
unless
job
.
is_a?
(
Hash
)
&&
job
.
has_key?
(
:script
)
validate_job_name!
(
name
)
validate_job_keys!
(
name
,
job
)
validate_job_keys!
(
name
,
job
)
validate_job_types!
(
name
,
job
)
validate_job_types!
(
name
,
job
)
...
@@ -112,12 +111,6 @@ module Ci
...
@@ -112,12 +111,6 @@ module Ci
validate_job_dependencies!
(
name
,
job
)
if
job
[
:dependencies
]
validate_job_dependencies!
(
name
,
job
)
if
job
[
:dependencies
]
end
end
def
validate_job_name!
(
name
)
if
name
.
blank?
||
!
validate_string
(
name
)
raise
ValidationError
,
"job name should be non-empty string"
end
end
def
validate_job_keys!
(
name
,
job
)
def
validate_job_keys!
(
name
,
job
)
##
##
# TODO, remove refactoring keys
# TODO, remove refactoring keys
...
...
lib/gitlab/ci/config/node/configurable.rb
View file @
56ae9f6b
...
@@ -55,8 +55,10 @@ module Gitlab
...
@@ -55,8 +55,10 @@ module Gitlab
end
end
define_method
(
"
#{
symbol
}
_value"
)
do
define_method
(
"
#{
symbol
}
_value"
)
do
return
unless
valid?
if
@entries
[
symbol
]
@entries
[
symbol
].
value
if
@entries
[
symbol
]
return
unless
@entries
[
symbol
].
valid?
@entries
[
symbol
].
value
end
end
end
alias_method
symbol
.
to_sym
,
"
#{
symbol
}
_value"
.
to_sym
alias_method
symbol
.
to_sym
,
"
#{
symbol
}
_value"
.
to_sym
...
...
lib/gitlab/ci/config/node/job.rb
View file @
56ae9f6b
...
@@ -10,7 +10,12 @@ module Gitlab
...
@@ -10,7 +10,12 @@ module Gitlab
validations
do
validations
do
validates
:config
,
presence:
true
validates
:config
,
presence:
true
validates
:global
,
required:
true
,
on: :processed
with_options
on: :processed
do
validates
:global
,
required:
true
validates
:name
,
presence:
true
validates
:name
,
type:
Symbol
end
end
end
node
:before_script
,
Script
,
node
:before_script
,
Script
,
...
@@ -30,11 +35,11 @@ module Gitlab
...
@@ -30,11 +35,11 @@ module Gitlab
helpers
:before_script
,
:script
,
:stage
,
:type
,
:after_script
helpers
:before_script
,
:script
,
:stage
,
:type
,
:after_script
def
name
@key
end
def
value
def
value
##
# TODO, refactoring step: do not expose internal configuration,
# return only hash value without merging it to internal config.
#
@config
.
merge
(
to_hash
.
compact
)
@config
.
merge
(
to_hash
.
compact
)
end
end
...
@@ -53,10 +58,9 @@ module Gitlab
...
@@ -53,10 +58,9 @@ module Gitlab
private
private
def
to_hash
def
to_hash
{
before_script:
before_script
,
{
script:
script
,
script:
script
,
commands:
commands
,
stage:
stage
,
stage:
stage
,
commands:
commands
,
after_script:
after_script
}
after_script:
after_script
}
end
end
...
...
lib/gitlab/ci/config/node/jobs.rb
View file @
56ae9f6b
...
@@ -10,20 +10,21 @@ module Gitlab
...
@@ -10,20 +10,21 @@ module Gitlab
validations
do
validations
do
validates
:config
,
type:
Hash
validates
:config
,
type:
Hash
validate
:jobs_presence
,
on: :processed
def
jobs_presence
with_options
on: :processed
do
unless
relevant?
validate
do
unless
has_visible_job?
errors
.
add
(
:config
,
'should contain at least one visible job'
)
errors
.
add
(
:config
,
'should contain at least one visible job'
)
end
end
end
end
end
end
end
def
nodes
def
nodes
@config
@config
end
end
def
relevant
?
def
has_visible_job
?
@entries
.
values
.
any?
(
&
:relevant?
)
@entries
.
values
.
any?
(
&
:relevant?
)
end
end
...
...
lib/gitlab/ci/config/node/validator.rb
View file @
56ae9f6b
...
@@ -31,8 +31,15 @@ module Gitlab
...
@@ -31,8 +31,15 @@ module Gitlab
def
location
def
location
predecessors
=
ancestors
.
map
(
&
:key
).
compact
predecessors
=
ancestors
.
map
(
&
:key
).
compact
current
=
key
||
@node
.
class
.
name
.
demodulize
.
underscore
.
humanize
predecessors
.
append
(
key_name
).
join
(
':'
)
predecessors
.
append
(
current
).
join
(
':'
)
end
def
key_name
if
key
.
blank?
||
key
.
nil?
@node
.
class
.
name
.
demodulize
.
underscore
.
humanize
else
key
end
end
end
end
end
end
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
56ae9f6b
...
@@ -998,14 +998,14 @@ EOT
...
@@ -998,14 +998,14 @@ EOT
config
=
YAML
.
dump
({
''
=>
{
script:
"test"
}
})
config
=
YAML
.
dump
({
''
=>
{
script:
"test"
}
})
expect
do
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"job
name should be non-empty string
"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"job
s:job name can't be blank
"
)
end
end
it
"returns errors if job name is non-string"
do
it
"returns errors if job name is non-string"
do
config
=
YAML
.
dump
({
10
=>
{
script:
"test"
}
})
config
=
YAML
.
dump
({
10
=>
{
script:
"test"
}
})
expect
do
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"job
name should be non-empty string
"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"job
s:10 name should be a symbol
"
)
end
end
it
"returns errors if job image parameter is invalid"
do
it
"returns errors if job image parameter is invalid"
do
...
...
spec/lib/gitlab/ci/config/node/global_spec.rb
View file @
56ae9f6b
...
@@ -129,14 +129,12 @@ describe Gitlab::Ci::Config::Node::Global do
...
@@ -129,14 +129,12 @@ describe Gitlab::Ci::Config::Node::Global do
describe
'#jobs'
do
describe
'#jobs'
do
it
'returns jobs configuration'
do
it
'returns jobs configuration'
do
expect
(
global
.
jobs
)
expect
(
global
.
jobs
)
.
to
eq
(
rspec:
{
before_script:
%w[ls pwd]
,
.
to
eq
(
rspec:
{
script:
%w[rspec ls]
,
script:
%w[rspec ls]
,
stage:
'test'
,
commands:
"ls
\n
pwd
\n
rspec
\n
ls"
,
commands:
"ls
\n
pwd
\n
rspec
\n
ls"
},
stage:
'test'
},
spinach:
{
script:
%w[spinach]
,
spinach:
{
before_script:
%w[ls pwd]
,
stage:
'test'
,
script:
%w[spinach]
,
commands:
"ls
\n
pwd
\n
spinach"
})
commands:
"ls
\n
pwd
\n
spinach"
,
stage:
'test'
})
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/config/node/job_spec.rb
View file @
56ae9f6b
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Job
do
describe
Gitlab
::
Ci
::
Config
::
Node
::
Job
do
let
(
:entry
)
{
described_class
.
new
(
config
,
global:
global
)
}
let
(
:entry
)
{
described_class
.
new
(
config
,
attributes
)
}
let
(
:global
)
{
spy
(
'Global'
)
}
let
(
:attributes
)
{
{
key: :rspec
,
global:
global
}
}
let
(
:global
)
{
double
(
'global'
,
stages:
%w[test]
)
}
before
do
before
do
entry
.
process!
entry
.
process!
...
@@ -18,6 +19,15 @@ describe Gitlab::Ci::Config::Node::Job do
...
@@ -18,6 +19,15 @@ describe Gitlab::Ci::Config::Node::Job do
expect
(
entry
).
to
be_valid
expect
(
entry
).
to
be_valid
end
end
end
end
context
'when job name is empty'
do
let
(
:attributes
)
{
{
key:
''
,
global:
global
}
}
it
'reports error'
do
expect
(
entry
.
errors
)
.
to
include
"job name can't be blank"
end
end
end
end
context
'when entry value is not correct'
do
context
'when entry value is not correct'
do
...
@@ -27,7 +37,7 @@ describe Gitlab::Ci::Config::Node::Job do
...
@@ -27,7 +37,7 @@ describe Gitlab::Ci::Config::Node::Job do
describe
'#errors'
do
describe
'#errors'
do
it
'reports error about a config type'
do
it
'reports error about a config type'
do
expect
(
entry
.
errors
)
expect
(
entry
.
errors
)
.
to
include
'
job
config should be a hash'
.
to
include
'
rspec
config should be a hash'
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/config/node/jobs_spec.rb
View file @
56ae9f6b
...
@@ -34,8 +34,8 @@ describe Gitlab::Ci::Config::Node::Jobs do
...
@@ -34,8 +34,8 @@ describe Gitlab::Ci::Config::Node::Jobs do
context
'when job is unspecified'
do
context
'when job is unspecified'
do
let
(
:config
)
{
{
rspec:
nil
}
}
let
(
:config
)
{
{
rspec:
nil
}
}
it
'
is not valid
'
do
it
'
reports error
'
do
expect
(
entry
).
not_to
be_valid
expect
(
entry
.
errors
).
to
include
"rspec config can't be blank"
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