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
1d2c83cf
Commit
1d2c83cf
authored
Dec 22, 2020
by
Pedro Pombeiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address MR review comments
parent
2a61ddc6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
21 deletions
+20
-21
lib/gitlab/ci/variables/collection/sorted.rb
lib/gitlab/ci/variables/collection/sorted.rb
+16
-17
spec/lib/gitlab/ci/variables/collection/sorted_spec.rb
spec/lib/gitlab/ci/variables/collection/sorted_spec.rb
+4
-4
No files found.
lib/gitlab/ci/variables/collection/sorted.rb
View file @
1d2c83cf
...
...
@@ -13,27 +13,24 @@ module Gitlab
end
def
valid?
return
@valid
unless
@valid
.
nil?
@valid
=
check_errors
.
nil?
strong_memoize
(
:valid
)
do
errors
.
nil?
end
end
#
check_
errors sorts an array of variables, ignoring unknown variable references,
# errors sorts an array of variables, ignoring unknown variable references,
# and returning an error string if a circular variable reference is found
def
check_
errors
def
errors
return
if
Feature
.
disabled?
(
:variable_inside_variable
)
message
=
nil
# Check for cyclic dependencies and build error message in that case
each_strongly_connected_component
do
|
component
|
if
component
.
size
>
1
message
=
"circular variable reference detected:
#{
component
.
map
{
|
v
|
v
[
:key
]
}
.inspect}"
break
strong_memoize
(
:errors
)
do
# Check for cyclic dependencies and build error message in that case
errors
=
each_strongly_connected_component
.
filter_map
do
|
component
|
"
#{
component
.
map
{
|
v
|
v
[
:key
]
}
.inspect}"
if
component
.
size
>
1
end
end
message
"circular variable reference detected:
#{
errors
.
join
(
', '
)
}
"
if
errors
.
any?
end
end
# sort sorts an array of variables, ignoring unknown variable references.
...
...
@@ -41,14 +38,16 @@ module Gitlab
def
sort
return
@variables
if
Feature
.
disabled?
(
:variable_inside_variable
)
clear_memoization
(
:valid
)
begin
# Perform a topological sort
variables
=
tsort
@
valid
=
true
valid
=
true
rescue
TSort
::
Cyclic
variables
=
@variables
@
valid
=
false
valid
=
false
end
strong_memoize
(
:valid
)
{
valid
}
variables
end
...
...
@@ -64,7 +63,7 @@ module Gitlab
end
def
input_vars
strong_memoize
(
:in
clusion
)
do
strong_memoize
(
:in
put_vars
)
do
@variables
.
index_by
{
|
env
|
env
.
fetch
(
:key
)
}
end
end
...
...
spec/lib/gitlab/ci/variables/collection/sorted_spec.rb
View file @
1d2c83cf
...
...
@@ -9,7 +9,7 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
stub_feature_flags
(
variable_inside_variable:
variable_inside_variable_enabled
)
end
describe
'#
check_
errors'
do
describe
'#errors'
do
context
'when FF :variable_inside_variable is disabled'
do
let
(
:variable_inside_variable_enabled
)
{
false
}
...
...
@@ -60,7 +60,7 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
subject
{
Gitlab
::
Ci
::
Variables
::
Collection
::
Sorted
.
new
(
variables
)
}
it
'does not report error'
do
expect
(
subject
.
check_
errors
).
to
eq
(
nil
)
expect
(
subject
.
errors
).
to
eq
(
nil
)
end
it
'valid? reports true'
do
...
...
@@ -104,8 +104,8 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Sorted do
with_them
do
subject
{
Gitlab
::
Ci
::
Variables
::
Collection
::
Sorted
.
new
(
variables
)
}
it
'
check_
errors matches expected validation result'
do
expect
(
subject
.
check_
errors
).
to
eq
(
validation_result
)
it
'errors matches expected validation result'
do
expect
(
subject
.
errors
).
to
eq
(
validation_result
)
end
it
'valid? matches expected validation result'
do
...
...
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