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
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
Show 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,12 +5,29 @@ module Gitlab
...
@@ -5,12 +5,29 @@ module Gitlab
##
##
# Entry that represents a trigger policy for the job.
# Entry that represents a trigger policy for the job.
#
#
class
Policy
<
Node
class
Policy
<
Simplifiable
include
Validatable
strategy
:RefsPolicy
,
if:
->
(
config
)
{
config
.
is_a?
(
Array
)
}
strategy
:ExpressionsPolicy
,
if:
->
(
config
)
{
config
.
is_a?
(
Hash
)
}
class
RefsPolicy
<
Entry
::
Node
include
Entry
::
Validatable
validations
do
validations
do
validates
:config
,
array_of_strings_or_regexps:
true
validates
:config
,
array_of_strings_or_regexps:
true
end
end
def
value
{
refs:
@config
}
end
end
class
ExpressionsPolicy
<
Entry
::
Node
include
Entry
::
Validatable
validations
do
validates
:config
,
type:
Hash
end
end
end
end
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,6 +3,7 @@ require 'spec_helper'
...
@@ -3,6 +3,7 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Entry
::
Policy
do
describe
Gitlab
::
Ci
::
Config
::
Entry
::
Policy
do
let
(
:entry
)
{
described_class
.
new
(
config
)
}
let
(
:entry
)
{
described_class
.
new
(
config
)
}
context
'when using simplified policy'
do
describe
'validations'
do
describe
'validations'
do
context
'when entry config value is valid'
do
context
'when entry config value is valid'
do
context
'when config is a branch or tag name'
do
context
'when config is a branch or tag name'
do
...
@@ -16,7 +17,7 @@ describe Gitlab::Ci::Config::Entry::Policy do
...
@@ -16,7 +17,7 @@ describe Gitlab::Ci::Config::Entry::Policy do
describe
'#value'
do
describe
'#value'
do
it
'returns key value'
do
it
'returns key value'
do
expect
(
entry
.
value
).
to
eq
config
expect
(
entry
.
value
).
to
eq
(
refs:
config
)
end
end
end
end
end
end
...
@@ -48,9 +49,13 @@ describe Gitlab::Ci::Config::Entry::Policy do
...
@@ -48,9 +49,13 @@ describe Gitlab::Ci::Config::Entry::Policy do
describe
'#errors'
do
describe
'#errors'
do
it
'saves errors'
do
it
'saves errors'
do
expect
(
entry
.
errors
)
expect
(
entry
.
errors
)
.
to
include
'policy config should be an array of strings or regexps'
.
to
include
/policy config should be an array of strings or regexps/
end
end
end
end
end
end
end
end
end
context
'when using complex policy'
do
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