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
785d7919
Commit
785d7919
authored
Aug 13, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
2e2317a7
980b863c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
4 deletions
+57
-4
lib/gitlab/ci/config/entry/job.rb
lib/gitlab/ci/config/entry/job.rb
+3
-0
lib/gitlab/config/entry/attributable.rb
lib/gitlab/config/entry/attributable.rb
+4
-0
lib/gitlab/config/entry/validators.rb
lib/gitlab/config/entry/validators.rb
+11
-0
spec/lib/gitlab/ci/config/entry/job_spec.rb
spec/lib/gitlab/ci/config/entry/job_spec.rb
+36
-4
spec/lib/gitlab/config/entry/attributable_spec.rb
spec/lib/gitlab/config/entry/attributable_spec.rb
+3
-0
No files found.
lib/gitlab/ci/config/entry/job.rb
View file @
785d7919
...
...
@@ -16,8 +16,11 @@ module Gitlab
dependencies needs before_script after_script variables
environment coverage retry parallel extends]
.
freeze
REQUIRED_BY_NEEDS
=
%i[stage]
.
freeze
validations
do
validates
:config
,
allowed_keys:
ALLOWED_KEYS
validates
:config
,
required_keys:
REQUIRED_BY_NEEDS
,
if: :has_needs?
validates
:config
,
presence:
true
validates
:script
,
presence:
true
validates
:name
,
presence:
true
...
...
lib/gitlab/config/entry/attributable.rb
View file @
785d7919
...
...
@@ -18,6 +18,10 @@ module Gitlab
config
[
attribute
]
end
define_method
(
"has_
#{
attribute
}
?"
)
do
config
.
is_a?
(
Hash
)
&&
config
.
key?
(
attribute
)
end
end
end
end
...
...
lib/gitlab/config/entry/validators.rb
View file @
785d7919
...
...
@@ -26,6 +26,17 @@ module Gitlab
end
end
class
RequiredKeysValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
present_keys
=
options
[
:in
]
-
value
.
try
(
:keys
).
to_a
if
present_keys
.
any?
record
.
errors
.
add
(
attribute
,
"missing required keys: "
+
present_keys
.
join
(
', '
))
end
end
end
class
AllowedValuesValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
unless
options
[
:in
].
include?
(
value
.
to_s
)
...
...
spec/lib/gitlab/ci/config/entry/job_spec.rb
View file @
785d7919
...
...
@@ -89,14 +89,23 @@ describe Gitlab::Ci::Config::Entry::Job do
context
'when has needs'
do
let
(
:config
)
do
{
script:
'echo'
,
needs:
[
'another-job'
]
}
{
stage:
'test'
,
script:
'echo'
,
needs:
[
'another-job'
]
}
end
it
{
expect
(
entry
).
to
be_valid
}
context
'when has dependencies'
do
let
(
:config
)
do
{
script:
'echo'
,
dependencies:
[
'another-job'
],
needs:
[
'another-job'
]
}
{
stage:
'test'
,
script:
'echo'
,
dependencies:
[
'another-job'
],
needs:
[
'another-job'
]
}
end
it
{
expect
(
entry
).
to
be_valid
}
...
...
@@ -256,7 +265,11 @@ describe Gitlab::Ci::Config::Entry::Job do
context
'when has needs'
do
context
'that are not a array of strings'
do
let
(
:config
)
do
{
script:
'echo'
,
needs:
'build-job'
}
{
stage:
'test'
,
script:
'echo'
,
needs:
'build-job'
}
end
it
'returns error about invalid type'
do
...
...
@@ -267,7 +280,12 @@ describe Gitlab::Ci::Config::Entry::Job do
context
'when have dependencies that are not subset of needs'
do
let
(
:config
)
do
{
script:
'echo'
,
dependencies:
[
'another-job'
],
needs:
[
'build-job'
]
}
{
stage:
'test'
,
script:
'echo'
,
dependencies:
[
'another-job'
],
needs:
[
'build-job'
]
}
end
it
'returns error about invalid data'
do
...
...
@@ -275,6 +293,20 @@ describe Gitlab::Ci::Config::Entry::Job do
expect
(
entry
.
errors
).
to
include
'job dependencies the another-job should be part of needs'
end
end
context
'when stage: is missing'
do
let
(
:config
)
do
{
script:
'echo'
,
needs:
[
'build-job'
]
}
end
it
'returns error about invalid data'
do
expect
(
entry
).
not_to
be_valid
expect
(
entry
.
errors
).
to
include
'job config missing required keys: stage'
end
end
end
end
end
...
...
spec/lib/gitlab/config/entry/attributable_spec.rb
View file @
785d7919
...
...
@@ -25,7 +25,9 @@ describe Gitlab::Config::Entry::Attributable do
end
it
'returns the value of config'
do
expect
(
instance
).
to
have_name
expect
(
instance
.
name
).
to
eq
'some name'
expect
(
instance
).
to
have_test
expect
(
instance
.
test
).
to
eq
'some test'
end
...
...
@@ -42,6 +44,7 @@ describe Gitlab::Config::Entry::Attributable do
end
it
'returns nil'
do
expect
(
instance
).
not_to
have_test
expect
(
instance
.
test
).
to
be_nil
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