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
Boxiang Sun
gitlab-ce
Commits
fcb4d1f8
Commit
fcb4d1f8
authored
Aug 25, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement complex only/except policy CI/CD config
parent
8c409fc4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
4 deletions
+54
-4
lib/gitlab/ci/config/entry/policy.rb
lib/gitlab/ci/config/entry/policy.rb
+18
-2
lib/gitlab/ci/config/entry/simplifiable.rb
lib/gitlab/ci/config/entry/simplifiable.rb
+10
-2
spec/lib/gitlab/ci/config/entry/policy_spec.rb
spec/lib/gitlab/ci/config/entry/policy_spec.rb
+26
-0
No files found.
lib/gitlab/ci/config/entry/policy.rb
View file @
fcb4d1f8
...
...
@@ -3,7 +3,7 @@ module Gitlab
class
Config
module
Entry
##
# Entry that represents a trigger policy for the job.
# Entry that represents a
n only/except
trigger policy for the job.
#
class
Policy
<
Simplifiable
strategy
:RefsPolicy
,
if:
->
(
config
)
{
config
.
is_a?
(
Array
)
}
...
...
@@ -23,9 +23,25 @@ module Gitlab
class
ExpressionsPolicy
<
Entry
::
Node
include
Entry
::
Validatable
include
Entry
::
Attributable
attributes
:refs
,
:expressions
validations
do
validates
:config
,
type:
Hash
validates
:config
,
presence:
true
validates
:config
,
allowed_keys:
%i[refs expressions]
with_options
allow_nil:
true
do
validates
:refs
,
array_of_strings_or_regexps:
true
validates
:expressions
,
type:
Array
validates
:expressions
,
presence:
true
end
end
end
class
UnknownStrategy
<
Entry
::
Node
def
errors
[
'policy has to be either an array of conditions or a hash'
]
end
end
end
...
...
lib/gitlab/ci/config/entry/simplifiable.rb
View file @
fcb4d1f8
...
...
@@ -10,7 +10,7 @@ module Gitlab
variant
.
condition
.
call
(
config
)
end
entry
=
self
.
class
.
const_get
(
strategy
.
name
)
entry
=
self
.
class
.
entry_class
(
strategy
)
super
(
entry
.
new
(
config
,
metadata
))
end
...
...
@@ -22,7 +22,15 @@ module Gitlab
end
def
self
.
strategies
@strategies
||
[]
@strategies
.
to_a
end
def
self
.
entry_class
(
strategy
)
if
strategy
.
present?
self
.
const_get
(
strategy
.
name
)
else
self
::
UnknownStrategy
end
end
end
end
...
...
spec/lib/gitlab/ci/config/entry/policy_spec.rb
View file @
fcb4d1f8
...
...
@@ -57,5 +57,31 @@ describe Gitlab::Ci::Config::Entry::Policy do
end
context
'when using complex policy'
do
context
'when it is an empty hash'
do
let
(
:config
)
{
{
}
}
it
'reports an error about configuration not being present'
do
expect
(
entry
.
errors
).
to
include
/can't be blank/
end
end
context
'when it contains unknown keys'
do
let
(
:config
)
{
{
refs:
[
'something'
],
invalid:
'master'
}
}
it
'is not valid entry'
do
expect
(
entry
).
not_to
be_valid
expect
(
entry
.
errors
)
.
to
include
/policy config contains unknown keys: invalid/
end
end
end
context
'when policy strategy does not match'
do
let
(
:config
)
{
'string strategy'
}
it
'returns information about errors'
do
expect
(
entry
.
errors
)
.
to
include
'policy has to be either an array of conditions or a hash'
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