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
3e16b015
Commit
3e16b015
authored
Jul 14, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert logical validation in CI job stage entry
parent
f7c80e9f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
84 deletions
+15
-84
gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+7
-0
job.rb
lib/gitlab/ci/config/node/job.rb
+0
-1
stage.rb
lib/gitlab/ci/config/node/stage.rb
+0
-16
gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+2
-2
stage_spec.rb
spec/lib/gitlab/ci/config/node/stage_spec.rb
+6
-65
No files found.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
3e16b015
...
@@ -105,6 +105,7 @@ module Ci
...
@@ -105,6 +105,7 @@ module Ci
validate_job_keys!
(
name
,
job
)
validate_job_keys!
(
name
,
job
)
validate_job_types!
(
name
,
job
)
validate_job_types!
(
name
,
job
)
validate_job_stage!
(
name
,
job
)
if
job
[
:stage
]
validate_job_variables!
(
name
,
job
)
if
job
[
:variables
]
validate_job_variables!
(
name
,
job
)
if
job
[
:variables
]
validate_job_cache!
(
name
,
job
)
if
job
[
:cache
]
validate_job_cache!
(
name
,
job
)
if
job
[
:cache
]
validate_job_artifacts!
(
name
,
job
)
if
job
[
:artifacts
]
validate_job_artifacts!
(
name
,
job
)
if
job
[
:artifacts
]
...
@@ -153,6 +154,12 @@ module Ci
...
@@ -153,6 +154,12 @@ module Ci
end
end
end
end
def
validate_job_stage!
(
name
,
job
)
unless
job
[
:stage
].
is_a?
(
String
)
&&
job
[
:stage
].
in?
(
@stages
)
raise
ValidationError
,
"
#{
name
}
job: stage parameter should be
#{
@stages
.
join
(
", "
)
}
"
end
end
def
validate_job_variables!
(
name
,
job
)
def
validate_job_variables!
(
name
,
job
)
unless
validate_variables
(
job
[
:variables
])
unless
validate_variables
(
job
[
:variables
])
raise
ValidationError
,
raise
ValidationError
,
...
...
lib/gitlab/ci/config/node/job.rb
View file @
3e16b015
...
@@ -12,7 +12,6 @@ module Gitlab
...
@@ -12,7 +12,6 @@ module Gitlab
validates
:config
,
presence:
true
validates
:config
,
presence:
true
with_options
on: :processed
do
with_options
on: :processed
do
validates
:global
,
required:
true
validates
:name
,
presence:
true
validates
:name
,
presence:
true
validates
:name
,
type:
Symbol
validates
:name
,
type:
Symbol
end
end
...
...
lib/gitlab/ci/config/node/stage.rb
View file @
3e16b015
...
@@ -10,22 +10,6 @@ module Gitlab
...
@@ -10,22 +10,6 @@ module Gitlab
validations
do
validations
do
validates
:config
,
type:
String
validates
:config
,
type:
String
with_options
on: :processed
do
validates
:global
,
required:
true
validate
do
unless
known?
errors
.
add
(
:config
,
'should be one of defined stages '
\
"(
#{
global
.
stages
.
join
(
', '
)
}
)"
)
end
end
end
end
def
known?
@global
.
stages
.
include?
(
@config
)
end
end
def
self
.
default
def
self
.
default
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
3e16b015
...
@@ -1089,14 +1089,14 @@ EOT
...
@@ -1089,14 +1089,14 @@ EOT
config
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
type:
"acceptance"
}
})
config
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
type:
"acceptance"
}
})
expect
do
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
jobs:rspec:type config should be one of defined stages (build, test, deploy)
"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
rspec job: stage parameter should be build, test, deploy
"
)
end
end
it
"returns errors if job stage is not a defined stage"
do
it
"returns errors if job stage is not a defined stage"
do
config
=
YAML
.
dump
({
types:
[
"build"
,
"test"
],
rspec:
{
script:
"test"
,
type:
"acceptance"
}
})
config
=
YAML
.
dump
({
types:
[
"build"
,
"test"
],
rspec:
{
script:
"test"
,
type:
"acceptance"
}
})
expect
do
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
jobs:rspec:type config should be one of defined stages (build, test)
"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
rspec job: stage parameter should be build, test
"
)
end
end
it
"returns errors if stages is not an array"
do
it
"returns errors if stages is not an array"
do
...
...
spec/lib/gitlab/ci/config/node/stage_spec.rb
View file @
3e16b015
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Stage
do
describe
Gitlab
::
Ci
::
Config
::
Node
::
Stage
do
let
(
:stage
)
{
described_class
.
new
(
config
,
global:
global
)
}
let
(
:stage
)
{
described_class
.
new
(
config
)
}
let
(
:global
)
{
spy
(
'Global'
)
}
describe
'validations'
do
describe
'validations'
do
context
'when stage config value is correct'
do
context
'when stage config value is correct'
do
let
(
:config
)
{
'build'
}
let
(
:config
)
{
'build'
}
before
do
allow
(
global
).
to
receive
(
:stages
).
and_return
(
%w[build]
)
end
describe
'#value'
do
describe
'#value'
do
it
'returns a stage key'
do
it
'returns a stage key'
do
expect
(
stage
.
value
).
to
eq
config
expect
(
stage
.
value
).
to
eq
config
...
@@ -25,66 +20,12 @@ describe Gitlab::Ci::Config::Node::Stage do
...
@@ -25,66 +20,12 @@ describe Gitlab::Ci::Config::Node::Stage do
end
end
end
end
context
'when stage config is incorrect'
do
context
'when value has a wrong type'
do
describe
'#errors'
do
let
(
:config
)
{
{
test:
true
}
}
context
'when reference to global node is not set'
do
let
(
:stage
)
{
described_class
.
new
(
'test'
)
}
it
'raises error'
do
expect
{
stage
.
validate!
}.
to
raise_error
(
Gitlab
::
Ci
::
Config
::
Node
::
Entry
::
InvalidError
,
/Entry needs global attribute set internally./
)
end
end
context
'when value has a wrong type'
do
let
(
:config
)
{
{
test:
true
}
}
it
'reports errors about wrong type'
do
expect
(
stage
.
errors
)
.
to
include
'stage config should be a string'
end
end
context
'when stage is not present in global configuration'
do
let
(
:config
)
{
'unknown'
}
before
do
allow
(
global
)
.
to
receive
(
:stages
).
and_return
(
%w[test deploy]
)
end
it
'reports error about missing stage'
do
stage
.
validate!
expect
(
stage
.
errors
)
.
to
include
'stage config should be one of '
\
'defined stages (test, deploy)'
end
end
end
end
end
describe
'#known?'
do
before
do
allow
(
global
).
to
receive
(
:stages
).
and_return
(
%w[test deploy]
)
end
context
'when stage is not known'
do
let
(
:config
)
{
:unknown
}
it
'returns false'
do
expect
(
stage
.
known?
).
to
be
false
end
end
context
'when stage is known'
do
let
(
:config
)
{
'test'
}
it
'returns false'
do
it
'reports errors about wrong type'
do
expect
(
stage
.
known?
).
to
be
true
expect
(
stage
.
errors
)
.
to
include
'stage config should be a string'
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