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
5b9a6ca0
Commit
5b9a6ca0
authored
Aug 16, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic support for CI/CD config extension
parent
afb49b04
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
0 deletions
+94
-0
lib/gitlab/ci/config/extendable.rb
lib/gitlab/ci/config/extendable.rb
+31
-0
spec/lib/gitlab/ci/config/extendable_spec.rb
spec/lib/gitlab/ci/config/extendable_spec.rb
+63
-0
No files found.
lib/gitlab/ci/config/extendable.rb
0 → 100644
View file @
5b9a6ca0
module
Gitlab
module
Ci
class
Config
class
Extendable
include
Enumerable
ExtensionError
=
Class
.
new
(
StandardError
)
def
initialize
(
hash
)
@hash
=
hash
end
def
each
@hash
.
each_pair
do
|
key
,
value
|
next
unless
value
.
key?
(
:extends
)
yield
key
,
value
.
fetch
(
:extends
).
to_sym
,
value
end
end
def
extend!
@hash
.
tap
do
each
do
|
key
,
extends
,
value
|
@hash
[
key
]
=
@hash
.
fetch
(
extends
).
deep_merge
(
value
)
end
end
end
end
end
end
end
spec/lib/gitlab/ci/config/extendable_spec.rb
0 → 100644
View file @
5b9a6ca0
require
'fast_spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Extendable
do
subject
{
described_class
.
new
(
hash
)
}
describe
'#each'
do
context
'when there is extendable entry in the hash'
do
let
(
:test
)
do
{
extends:
'something'
,
only:
%w[master]
}
end
let
(
:hash
)
do
{
something:
{
script:
'ls'
},
test:
test
}
end
it
'yields the test hash'
do
expect
{
|
b
|
subject
.
each
(
&
b
)
}
.
to
yield_with_args
(
:test
,
:something
,
test
)
end
end
pending
'when not extending using a hash'
end
describe
'#extend!'
do
context
'when a hash has a single simple extension'
do
let
(
:hash
)
do
{
something:
{
script:
'deploy'
,
only:
{
variables:
%w[$SOMETHING]
}
},
test:
{
extends:
'something'
,
script:
'ls'
,
only:
{
refs:
%w[master]
}
}
}
end
it
'extends a hash with reverse merge'
do
expect
(
subject
.
extend!
).
to
eq
(
something:
{
script:
'deploy'
,
only:
{
variables:
%w[$SOMETHING]
}
},
test:
{
extends:
'something'
,
script:
'ls'
,
only:
{
refs:
%w[master]
,
variables:
%w[$SOMETHING]
}
}
)
end
end
pending
'when a hash recursive extensions'
pending
'when invalid `extends` is specified'
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