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
85810edb
Commit
85810edb
authored
Feb 18, 2021
by
Pedro Pombeiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Applied MR review suggestions
parent
4e80792b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
34 deletions
+21
-34
lib/gitlab/ci/variables/collection.rb
lib/gitlab/ci/variables/collection.rb
+7
-15
lib/gitlab/ci/variables/collection/item.rb
lib/gitlab/ci/variables/collection/item.rb
+4
-0
lib/gitlab/ci/variables/collection/sort.rb
lib/gitlab/ci/variables/collection/sort.rb
+1
-1
spec/lib/gitlab/ci/variables/collection/item_spec.rb
spec/lib/gitlab/ci/variables/collection/item_spec.rb
+1
-0
spec/lib/gitlab/ci/variables/collection_spec.rb
spec/lib/gitlab/ci/variables/collection_spec.rb
+8
-18
No files found.
lib/gitlab/ci/variables/collection.rb
View file @
85810edb
...
...
@@ -10,18 +10,18 @@ module Gitlab
def
initialize
(
variables
=
[],
errors
=
nil
)
@variables
=
[]
@var
_hash
=
{}
@var
iables_by_key
=
{}
@errors
=
errors
variables
.
each
{
|
variable
|
self
.
append
(
variable
)
}
end
def
append
(
resource
)
tap
do
item
=
Collection
::
Item
.
fabricate
(
resource
)
@variables
.
append
(
item
)
@var_hash
[
item
[
:key
]]
=
item
end
item
=
Collection
::
Item
.
fabricate
(
resource
)
@variables
.
append
(
item
)
@variables_by_key
[
item
[
:key
]]
=
item
self
end
def
concat
(
resources
)
...
...
@@ -42,7 +42,7 @@ module Gitlab
end
def
[]
(
key
)
@var
_hash
[
key
]
@var
iables_by_key
[
key
]
end
def
size
...
...
@@ -53,14 +53,6 @@ module Gitlab
self
.
map
(
&
:to_runner_variable
)
end
def
include?
(
obj
)
return
false
unless
obj
.
is_a?
(
Hash
)
&&
obj
.
has_key?
(
:key
)
key
=
obj
.
fetch
(
:key
)
found_var
=
@var_hash
[
key
]
!
found_var
.
nil?
&&
found_var
.
to_runner_variable
==
Collection
::
Item
.
fabricate
(
obj
).
to_runner_variable
end
def
to_hash
self
.
to_runner_variables
.
map
{
|
env
|
[
env
.
fetch
(
:key
),
env
.
fetch
(
:value
)]
}
...
...
lib/gitlab/ci/variables/collection/item.rb
View file @
85810edb
...
...
@@ -14,6 +14,10 @@ module Gitlab
}
end
def
value
@variable
.
fetch
(
:value
)
end
def
[]
(
key
)
@variable
.
fetch
(
key
)
end
...
...
lib/gitlab/ci/variables/collection/sort.rb
View file @
85810edb
...
...
@@ -52,7 +52,7 @@ module Gitlab
end
def
tsort_each_child
(
variable
,
&
block
)
each_variable_reference
(
variable
[
:value
]
,
&
block
)
each_variable_reference
(
variable
.
value
,
&
block
)
end
def
input_vars
...
...
spec/lib/gitlab/ci/variables/collection/item_spec.rb
View file @
85810edb
...
...
@@ -32,6 +32,7 @@ RSpec.describe Gitlab::Ci::Variables::Collection::Item do
it
'saves given value'
do
expect
(
subject
[
:key
]).
to
eq
variable_key
expect
(
subject
[
:value
]).
to
eq
expected_value
expect
(
subject
.
value
).
to
eq
expected_value
end
end
...
...
spec/lib/gitlab/ci/variables/collection_spec.rb
View file @
85810edb
...
...
@@ -129,26 +129,16 @@ RSpec.describe Gitlab::Ci::Variables::Collection do
expect
(
collection
.
size
).
to
eq
(
2
)
end
end
describe
'#include?'
do
it
'returns false for unknown variable'
do
collection
=
described_class
.
new
([])
expect
(
collection
.
include?
({
key:
'VAR'
,
value:
'value'
,
public:
true
,
masked:
false
})).
to
eq
(
false
)
end
it
'returns false for unsupported scenario of variable name argument'
do
collection
=
described_class
.
new
([{
key:
'VAR'
,
value:
'value'
,
public:
true
,
masked:
false
}])
expect
(
collection
.
include?
(
'VAR'
)).
to
eq
(
false
)
end
it
'returns true for known variable'
do
variable
=
{
key:
'VAR'
,
value:
'value'
,
public:
true
,
masked:
false
}
collection
=
described_class
.
new
([
variable
])
it
'returns 3 for collection with 2 duplicate variables'
do
collection
=
described_class
.
new
(
[
{
key:
'VAR1'
,
value:
'value'
,
public:
true
,
masked:
false
},
{
key:
'VAR2'
,
value:
'value'
,
public:
true
,
masked:
false
},
{
key:
'VAR1'
,
value:
'value'
,
public:
true
,
masked:
false
}
])
expect
(
collection
.
include?
(
variable
)).
to
eq
(
true
)
expect
(
collection
.
size
).
to
eq
(
3
)
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