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
8c409fc4
Commit
8c409fc4
authored
Aug 25, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it possible to define CI/CD config strategies
parent
0d7d7c10
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
35 deletions
+88
-35
lib/gitlab/ci/config/entry/policy.rb
lib/gitlab/ci/config/entry/policy.rb
+21
-4
lib/gitlab/ci/config/entry/simplifiable.rb
lib/gitlab/ci/config/entry/simplifiable.rb
+31
-0
spec/lib/gitlab/ci/config/entry/policy_spec.rb
spec/lib/gitlab/ci/config/entry/policy_spec.rb
+36
-31
No files found.
lib/gitlab/ci/config/entry/policy.rb
View file @
8c409fc4
...
...
@@ -5,11 +5,28 @@ module Gitlab
##
# Entry that represents a trigger policy for the job.
#
class
Policy
<
Node
include
Validatable
class
Policy
<
Simplifiable
strategy
:RefsPolicy
,
if:
->
(
config
)
{
config
.
is_a?
(
Array
)
}
strategy
:ExpressionsPolicy
,
if:
->
(
config
)
{
config
.
is_a?
(
Hash
)
}
validations
do
validates
:config
,
array_of_strings_or_regexps:
true
class
RefsPolicy
<
Entry
::
Node
include
Entry
::
Validatable
validations
do
validates
:config
,
array_of_strings_or_regexps:
true
end
def
value
{
refs:
@config
}
end
end
class
ExpressionsPolicy
<
Entry
::
Node
include
Entry
::
Validatable
validations
do
validates
:config
,
type:
Hash
end
end
end
end
...
...
lib/gitlab/ci/config/entry/simplifiable.rb
0 → 100644
View file @
8c409fc4
module
Gitlab
module
Ci
class
Config
module
Entry
class
Simplifiable
<
SimpleDelegator
EntryStrategy
=
Struct
.
new
(
:name
,
:condition
)
def
initialize
(
config
,
**
metadata
)
strategy
=
self
.
class
.
strategies
.
find
do
|
variant
|
variant
.
condition
.
call
(
config
)
end
entry
=
self
.
class
.
const_get
(
strategy
.
name
)
super
(
entry
.
new
(
config
,
metadata
))
end
def
self
.
strategy
(
name
,
**
opts
)
EntryStrategy
.
new
(
name
,
opts
.
fetch
(
:if
)).
tap
do
|
strategy
|
(
@strategies
||=
[]).
append
(
strategy
)
end
end
def
self
.
strategies
@strategies
||
[]
end
end
end
end
end
end
spec/lib/gitlab/ci/config/entry/policy_spec.rb
View file @
8c409fc4
...
...
@@ -3,54 +3,59 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Entry
::
Policy
do
let
(
:entry
)
{
described_class
.
new
(
config
)
}
describe
'validations'
do
context
'when entry config value is valid'
do
context
'when config is a branch or tag name'
do
let
(
:config
)
{
%w[master feature/branch]
}
describe
'#valid?'
do
it
'is valid'
do
expect
(
entry
).
to
be_valid
context
'when using simplified policy'
do
describe
'validations'
do
context
'when entry config value is valid'
do
context
'when config is a branch or tag name'
do
let
(
:config
)
{
%w[master feature/branch]
}
describe
'#valid?'
do
it
'is valid'
do
expect
(
entry
).
to
be_valid
end
end
end
describe
'#value'
do
it
'returns key value'
do
expect
(
entry
.
value
).
to
eq
config
describe
'#value'
do
it
'returns key value'
do
expect
(
entry
.
value
).
to
eq
(
refs:
config
)
end
end
end
end
context
'when config is a regexp'
do
let
(
:config
)
{
[
'/^issue-.*$/'
]
}
context
'when config is a regexp'
do
let
(
:config
)
{
[
'/^issue-.*$/'
]
}
describe
'#valid?'
do
it
'is valid'
do
expect
(
entry
).
to
be_valid
describe
'#valid?'
do
it
'is valid'
do
expect
(
entry
).
to
be_valid
end
end
end
end
context
'when config is a special keyword'
do
let
(
:config
)
{
%w[tags triggers branches]
}
context
'when config is a special keyword'
do
let
(
:config
)
{
%w[tags triggers branches]
}
describe
'#valid?'
do
it
'is valid'
do
expect
(
entry
).
to
be_valid
describe
'#valid?'
do
it
'is valid'
do
expect
(
entry
).
to
be_valid
end
end
end
end
end
context
'when entry value is not valid'
do
let
(
:config
)
{
[
1
]
}
context
'when entry value is not valid'
do
let
(
:config
)
{
[
1
]
}
describe
'#errors'
do
it
'saves errors'
do
expect
(
entry
.
errors
)
.
to
include
'policy config should be an array of strings or regexps'
describe
'#errors'
do
it
'saves errors'
do
expect
(
entry
.
errors
)
.
to
include
/policy config should be an array of strings or regexps/
end
end
end
end
end
context
'when using complex policy'
do
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