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
Jérome Perrin
gitlab-ce
Commits
24b686eb
Commit
24b686eb
authored
Jul 18, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move job artifacts configuration new CI config code
parent
47fa9f33
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
154 additions
and
27 deletions
+154
-27
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+0
-20
lib/gitlab/ci/config/node/artifacts.rb
lib/gitlab/ci/config/node/artifacts.rb
+32
-0
lib/gitlab/ci/config/node/attributable.rb
lib/gitlab/ci/config/node/attributable.rb
+23
-0
lib/gitlab/ci/config/node/job.rb
lib/gitlab/ci/config/node/job.rb
+6
-1
lib/gitlab/ci/config/node/validators.rb
lib/gitlab/ci/config/node/validators.rb
+10
-0
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+6
-6
spec/lib/gitlab/ci/config/node/artifacts_spec.rb
spec/lib/gitlab/ci/config/node/artifacts_spec.rb
+34
-0
spec/lib/gitlab/ci/config/node/attributable_spec.rb
spec/lib/gitlab/ci/config/node/attributable_spec.rb
+43
-0
No files found.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
24b686eb
...
...
@@ -148,26 +148,6 @@ module Ci
raise
ValidationError
,
"
#{
name
}
job: artifacts unknown parameter
#{
key
}
"
end
end
if
job
[
:artifacts
][
:name
]
&&
!
validate_string
(
job
[
:artifacts
][
:name
])
raise
ValidationError
,
"
#{
name
}
job: artifacts:name parameter should be a string"
end
if
job
[
:artifacts
][
:untracked
]
&&
!
validate_boolean
(
job
[
:artifacts
][
:untracked
])
raise
ValidationError
,
"
#{
name
}
job: artifacts:untracked parameter should be an boolean"
end
if
job
[
:artifacts
][
:paths
]
&&
!
validate_array_of_strings
(
job
[
:artifacts
][
:paths
])
raise
ValidationError
,
"
#{
name
}
job: artifacts:paths parameter should be an array of strings"
end
if
job
[
:artifacts
][
:when
]
&&
!
job
[
:artifacts
][
:when
].
in?
(
%w[on_success on_failure always]
)
raise
ValidationError
,
"
#{
name
}
job: artifacts:when parameter should be on_success, on_failure or always"
end
if
job
[
:artifacts
][
:expire_in
]
&&
!
validate_duration
(
job
[
:artifacts
][
:expire_in
])
raise
ValidationError
,
"
#{
name
}
job: artifacts:expire_in parameter should be a duration"
end
end
def
validate_job_dependencies!
(
name
,
job
)
...
...
lib/gitlab/ci/config/node/artifacts.rb
0 → 100644
View file @
24b686eb
module
Gitlab
module
Ci
class
Config
module
Node
##
# Entry that represents a configuration of job artifacts.
#
class
Artifacts
<
Entry
include
Validatable
include
Attributable
attributes
:name
,
:untracked
,
:paths
,
:when
,
:expire_in
validations
do
validates
:config
,
type:
Hash
with_options
allow_nil:
true
do
validates
:name
,
type:
String
validates
:untracked
,
boolean:
true
validates
:paths
,
array_of_strings:
true
validates
:when
,
inclusion:
{
in:
%w[on_success on_failure always]
,
message:
'should be on_success, on_failure '
\
'or always'
}
validates
:expire_in
,
duration:
true
end
end
end
end
end
end
end
lib/gitlab/ci/config/node/attributable.rb
0 → 100644
View file @
24b686eb
module
Gitlab
module
Ci
class
Config
module
Node
module
Attributable
extend
ActiveSupport
::
Concern
class_methods
do
def
attributes
(
*
attributes
)
attributes
.
each
do
|
attribute
|
define_method
(
attribute
)
do
return
unless
config
.
is_a?
(
Hash
)
config
[
attribute
]
end
end
end
end
end
end
end
end
end
lib/gitlab/ci/config/node/job.rb
View file @
24b686eb
...
...
@@ -47,8 +47,12 @@ module Gitlab
node
:variables
,
Variables
,
description:
'Environment variables available for this job.'
node
:artifacts
,
Artifacts
,
description:
'Artifacts configuration for this job.'
helpers
:before_script
,
:script
,
:stage
,
:type
,
:after_script
,
:cache
,
:image
,
:services
,
:only
,
:except
,
:variables
:cache
,
:image
,
:services
,
:only
,
:except
,
:variables
,
:artifacts
def
name
@metadata
[
:name
]
...
...
@@ -71,6 +75,7 @@ module Gitlab
only:
only
,
except:
except
,
variables:
variables_defined?
?
variables
:
nil
,
artifacts:
artifacts
,
after_script:
after_script
}
end
...
...
lib/gitlab/ci/config/node/validators.rb
View file @
24b686eb
...
...
@@ -33,6 +33,16 @@ module Gitlab
end
end
class
DurationValidator
<
ActiveModel
::
EachValidator
include
LegacyValidationHelpers
def
validate_each
(
record
,
attribute
,
value
)
unless
validate_duration
(
value
)
record
.
errors
.
add
(
attribute
,
'should be a duration'
)
end
end
end
class
RequiredValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
if
value
.
nil?
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
24b686eb
...
...
@@ -1138,42 +1138,42 @@ EOT
config
=
YAML
.
dump
({
types:
[
"build"
,
"test"
],
rspec:
{
script:
"test"
,
artifacts:
{
name:
1
}
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
rspec job: artifacts:name parameter
should be a string"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
jobs:rspec:artifacts name
should be a string"
)
end
it
"returns errors if job artifacts:when is not an a predefined value"
do
config
=
YAML
.
dump
({
types:
[
"build"
,
"test"
],
rspec:
{
script:
"test"
,
artifacts:
{
when:
1
}
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
rspec job: artifacts:when parameter
should be on_success, on_failure or always"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
jobs:rspec:artifacts when
should be on_success, on_failure or always"
)
end
it
"returns errors if job artifacts:expire_in is not an a string"
do
config
=
YAML
.
dump
({
types:
[
"build"
,
"test"
],
rspec:
{
script:
"test"
,
artifacts:
{
expire_in:
1
}
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
rspec job: artifacts:expire_in parameter
should be a duration"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
jobs:rspec:artifacts expire in
should be a duration"
)
end
it
"returns errors if job artifacts:expire_in is not an a valid duration"
do
config
=
YAML
.
dump
({
types:
[
"build"
,
"test"
],
rspec:
{
script:
"test"
,
artifacts:
{
expire_in:
"7 elephants"
}
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
rspec job: artifacts:expire_in parameter
should be a duration"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
jobs:rspec:artifacts expire in
should be a duration"
)
end
it
"returns errors if job artifacts:untracked is not an array of strings"
do
config
=
YAML
.
dump
({
types:
[
"build"
,
"test"
],
rspec:
{
script:
"test"
,
artifacts:
{
untracked:
"string"
}
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
rspec job: artifacts:untracked parameter should be an boolean
"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
jobs:rspec:artifacts untracked should be a boolean value
"
)
end
it
"returns errors if job artifacts:paths is not an array of strings"
do
config
=
YAML
.
dump
({
types:
[
"build"
,
"test"
],
rspec:
{
script:
"test"
,
artifacts:
{
paths:
"string"
}
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
rspec job: artifacts:paths parameter
should be an array of strings"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
jobs:rspec:artifacts paths
should be an array of strings"
)
end
it
"returns errors if cache:untracked is not an array of strings"
do
...
...
spec/lib/gitlab/ci/config/node/artifacts_spec.rb
0 → 100644
View file @
24b686eb
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Artifacts
do
let
(
:entry
)
{
described_class
.
new
(
config
)
}
describe
'validation'
do
context
'when entry config value is correct'
do
let
(
:config
)
{
{
paths:
%w[public/]
}
}
describe
'#value'
do
it
'returns image string'
do
expect
(
entry
.
value
).
to
eq
config
end
end
describe
'#valid?'
do
it
'is valid'
do
expect
(
entry
).
to
be_valid
end
end
end
context
'when entry value is not correct'
do
let
(
:config
)
{
{
name:
10
}
}
describe
'#errors'
do
it
'saves errors'
do
expect
(
entry
.
errors
)
.
to
include
'artifacts name should be a string'
end
end
end
end
end
spec/lib/gitlab/ci/config/node/attributable_spec.rb
0 → 100644
View file @
24b686eb
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Attributable
do
let
(
:node
)
{
Class
.
new
}
let
(
:instance
)
{
node
.
new
}
before
do
node
.
include
(
described_class
)
node
.
class_eval
do
attributes
:name
,
:test
end
end
context
'config is a hash'
do
before
do
allow
(
instance
)
.
to
receive
(
:config
)
.
and_return
({
name:
'some name'
,
test:
'some test'
})
end
it
'returns the value of config'
do
expect
(
instance
.
name
).
to
eq
'some name'
expect
(
instance
.
test
).
to
eq
'some test'
end
it
'returns no method error for unknown attributes'
do
expect
{
instance
.
unknown
}.
to
raise_error
(
NoMethodError
)
end
end
context
'config is not a hash'
do
before
do
allow
(
instance
)
.
to
receive
(
:config
)
.
and_return
(
'some test'
)
end
it
'returns nil'
do
expect
(
instance
.
test
).
to
be_nil
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