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
2c41fbb1
Commit
2c41fbb1
authored
Aug 16, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect circular dependenies in CI/CD `extends:` entry
parent
ef26622d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
6 deletions
+42
-6
lib/gitlab/ci/config/extendable/collection.rb
lib/gitlab/ci/config/extendable/collection.rb
+1
-0
lib/gitlab/ci/config/extendable/entry.rb
lib/gitlab/ci/config/extendable/entry.rb
+13
-5
spec/lib/gitlab/ci/config/extendable/collection_spec.rb
spec/lib/gitlab/ci/config/extendable/collection_spec.rb
+28
-1
No files found.
lib/gitlab/ci/config/extendable/collection.rb
View file @
2c41fbb1
...
@@ -6,6 +6,7 @@ module Gitlab
...
@@ -6,6 +6,7 @@ module Gitlab
include
Enumerable
include
Enumerable
ExtensionError
=
Class
.
new
(
StandardError
)
ExtensionError
=
Class
.
new
(
StandardError
)
CircularDependencyError
=
Class
.
new
(
ExtensionError
)
def
initialize
(
hash
)
def
initialize
(
hash
)
@hash
=
hash
@hash
=
hash
...
...
lib/gitlab/ci/config/extendable/entry.rb
View file @
2c41fbb1
...
@@ -5,9 +5,9 @@ module Gitlab
...
@@ -5,9 +5,9 @@ module Gitlab
class
Entry
class
Entry
attr_reader
:key
attr_reader
:key
def
initialize
(
key
,
hash
,
parent
=
nil
)
def
initialize
(
key
,
context
,
parent
=
nil
)
@key
=
key
@key
=
key
@
hash
=
hash
@
context
=
context
@parent
=
parent
@parent
=
parent
end
end
...
@@ -16,12 +16,12 @@ module Gitlab
...
@@ -16,12 +16,12 @@ module Gitlab
end
end
def
value
def
value
@value
||=
@
hash
.
fetch
(
@key
)
@value
||=
@
context
.
fetch
(
@key
)
end
end
def
base
def
base
Extendable
::
Entry
Extendable
::
Entry
.
new
(
extends
,
@
hash
,
self
)
.
new
(
extends
,
@
context
,
self
)
.
extend!
.
extend!
end
end
...
@@ -33,9 +33,17 @@ module Gitlab
...
@@ -33,9 +33,17 @@ module Gitlab
value
.
fetch
(
:extends
).
to_sym
value
.
fetch
(
:extends
).
to_sym
end
end
def
path
Array
(
@parent
&
.
path
).
compact
.
push
(
key
)
end
def
extend!
def
extend!
if
path
.
count
(
key
)
>
1
raise
Extendable
::
Collection
::
CircularDependencyError
end
if
extensible?
if
extensible?
@
hash
[
key
]
=
base
.
deep_merge
(
value
)
@
context
[
key
]
=
base
.
deep_merge
(
value
)
else
else
value
value
end
end
...
...
spec/lib/gitlab/ci/config/extendable/collection_spec.rb
View file @
2c41fbb1
...
@@ -117,6 +117,33 @@ describe Gitlab::Ci::Config::Extendable::Collection do
...
@@ -117,6 +117,33 @@ describe Gitlab::Ci::Config::Extendable::Collection do
end
end
pending
'when invalid `extends` is specified'
pending
'when invalid `extends` is specified'
pending
'when circular dependecy has been detected'
context
'when circular dependecy has been detected'
do
let
(
:hash
)
do
{
test:
{
extends:
'something'
,
script:
'ls'
,
only:
{
refs:
%w[master]
}
},
something:
{
extends:
'.first'
,
script:
'deploy'
,
only:
{
variables:
%w[$SOMETHING]
}
},
'.first'
:
{
extends:
'something'
,
script:
'run'
,
only:
{
kubernetes:
'active'
}
}
}
end
it
'raises an error'
do
expect
{
subject
.
extend!
}
.
to
raise_error
(
described_class
::
CircularDependencyError
)
end
end
end
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