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
1d57db0d
Commit
1d57db0d
authored
Mar 14, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve predefined variables collection methods
parent
e7e06566
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
13 deletions
+22
-13
app/models/project.rb
app/models/project.rb
+10
-11
lib/gitlab/ci/variables/collection.rb
lib/gitlab/ci/variables/collection.rb
+2
-2
spec/lib/gitlab/ci/variables/collection_spec.rb
spec/lib/gitlab/ci/variables/collection_spec.rb
+10
-0
No files found.
app/models/project.rb
View file @
1d57db0d
...
@@ -1574,17 +1574,16 @@ class Project < ActiveRecord::Base
...
@@ -1574,17 +1574,16 @@ class Project < ActiveRecord::Base
def
predefined_variables
def
predefined_variables
visibility
=
Gitlab
::
VisibilityLevel
.
string_level
(
visibility_level
)
visibility
=
Gitlab
::
VisibilityLevel
.
string_level
(
visibility_level
)
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
variables
|
Gitlab
::
Ci
::
Variables
::
Collection
.
new
variables
.
append
(
key:
'CI_PROJECT_ID'
,
value:
id
.
to_s
)
.
append
(
key:
'CI_PROJECT_ID'
,
value:
id
.
to_s
)
variables
.
append
(
key:
'CI_PROJECT_NAME'
,
value:
path
)
.
append
(
key:
'CI_PROJECT_NAME'
,
value:
path
)
variables
.
append
(
key:
'CI_PROJECT_PATH'
,
value:
full_path
)
.
append
(
key:
'CI_PROJECT_PATH'
,
value:
full_path
)
variables
.
append
(
key:
'CI_PROJECT_PATH_SLUG'
,
value:
full_path_slug
)
.
append
(
key:
'CI_PROJECT_PATH_SLUG'
,
value:
full_path_slug
)
variables
.
append
(
key:
'CI_PROJECT_NAMESPACE'
,
value:
namespace
.
full_path
)
.
append
(
key:
'CI_PROJECT_NAMESPACE'
,
value:
namespace
.
full_path
)
variables
.
append
(
key:
'CI_PROJECT_URL'
,
value:
web_url
)
.
append
(
key:
'CI_PROJECT_URL'
,
value:
web_url
)
variables
.
append
(
key:
'CI_PROJECT_VISIBILITY'
,
value:
visibility
)
.
append
(
key:
'CI_PROJECT_VISIBILITY'
,
value:
visibility
)
variables
.
concat
(
container_registry_variables
)
.
concat
(
container_registry_variables
)
variables
.
concat
(
auto_devops_variables
)
.
concat
(
auto_devops_variables
)
end
end
end
def
container_registry_variables
def
container_registry_variables
...
...
lib/gitlab/ci/variables/collection.rb
View file @
1d57db0d
...
@@ -11,11 +11,11 @@ module Gitlab
...
@@ -11,11 +11,11 @@ module Gitlab
end
end
def
append
(
resource
)
def
append
(
resource
)
@variables
.
append
(
Collection
::
Item
.
fabricate
(
resource
))
tap
{
@variables
.
append
(
Collection
::
Item
.
fabricate
(
resource
))
}
end
end
def
concat
(
resources
)
def
concat
(
resources
)
resources
.
each
{
|
variable
|
self
.
append
(
variable
)
}
tap
{
resources
.
each
{
|
variable
|
self
.
append
(
variable
)
}
}
end
end
def
each
def
each
...
...
spec/lib/gitlab/ci/variables/collection_spec.rb
View file @
1d57db0d
...
@@ -35,6 +35,11 @@ describe Gitlab::Ci::Variables::Collection do
...
@@ -35,6 +35,11 @@ describe Gitlab::Ci::Variables::Collection do
expect
(
subject
).
to
be_one
expect
(
subject
).
to
be_one
end
end
it
'returns self'
do
expect
(
subject
.
append
(
key:
'VAR'
,
value:
'test'
))
.
to
eq
subject
end
end
end
describe
'#concat'
do
describe
'#concat'
do
...
@@ -60,6 +65,11 @@ describe Gitlab::Ci::Variables::Collection do
...
@@ -60,6 +65,11 @@ describe Gitlab::Ci::Variables::Collection do
expect
(
collection
).
to
include
(
key:
'VAR_2'
,
value:
'2'
,
public:
true
)
expect
(
collection
).
to
include
(
key:
'VAR_2'
,
value:
'2'
,
public:
true
)
expect
(
collection
).
to
include
(
key:
'VAR_3'
,
value:
'3'
,
public:
true
)
expect
(
collection
).
to
include
(
key:
'VAR_3'
,
value:
'3'
,
public:
true
)
end
end
it
'returns self'
do
expect
(
subject
.
concat
([
key:
'VAR'
,
value:
'test'
]))
.
to
eq
subject
end
end
end
describe
'#+'
do
describe
'#+'
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