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
Jérome Perrin
gitlab-ce
Commits
96a7e162
Commit
96a7e162
authored
7 years ago
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor context variables in pipeline model class
parent
326dc7da
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
18 deletions
+14
-18
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+10
-6
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+4
-12
No files found.
app/models/ci/pipeline.rb
View file @
96a7e162
...
...
@@ -31,8 +31,6 @@ module Ci
has_many
:auto_canceled_jobs
,
class_name:
'CommitStatus'
,
foreign_key:
'auto_canceled_by_id'
delegate
:id
,
to: :project
,
prefix:
true
delegate
:deployment_variables
,
to: :project
,
prefix:
true
delegate
:secret_variables_for
,
to: :project
,
prefix:
true
validates
:source
,
exclusion:
{
in:
%w(unknown)
,
unless: :importing?
},
on: :create
validates
:sha
,
presence:
{
unless: :importing?
}
...
...
@@ -306,13 +304,19 @@ module Ci
@stage_seeds
||=
config_processor
.
stage_seeds
(
self
)
end
def
variables
project_secret_variables_for
(
ref:
ref
).
map
(
&
:to_runner_variable
)
+
project_deployment_variables
def
context_
variables
@context_variables
||=
project
.
secret_variables_for
(
ref:
ref
).
to_a
.
map
(
&
:to_runner_variable
)
+
project
.
deployment_variables
.
to_a
end
def
has_kubernetes_available?
(
variables
.
map
{
|
v
|
v
.
fetch
(
:key
)
}
&
%w[KUBECONFIG KUBE_DOMAIN]
).
many?
kubernetes_variables
=
context_variables
.
select
do
|
variable
|
variable
.
fetch
(
:key
).
in?
(
%w[KUBECONFIG KUBE_DOMAIN]
)
end
return
false
if
kubernetes_variables
.
empty?
kubernetes_variables
.
map
{
|
var
|
var
.
fetch
(
:value
).
present?
}.
all?
end
def
has_stage_seeds?
...
...
This diff is collapsed.
Click to expand it.
spec/models/ci/pipeline_spec.rb
View file @
96a7e162
...
...
@@ -27,14 +27,6 @@ describe Ci::Pipeline, :mailer do
it
{
is_expected
.
to
respond_to
:git_author_email
}
it
{
is_expected
.
to
respond_to
:short_sha
}
describe
'#project_deployment_variables'
do
it
'delegates deployment variables to project'
do
expect
(
pipeline
)
.
to
delegate_method
(
:deployment_variables
)
.
to
(
:project
).
with_prefix
end
end
describe
'#source'
do
context
'when creating new pipeline'
do
let
(
:pipeline
)
do
...
...
@@ -551,9 +543,9 @@ describe Ci::Pipeline, :mailer do
project:
project
)
end
describe
'#variables'
do
describe
'#
context_
variables'
do
it
'returns kubernetes-related variables'
do
variables
=
pipeline
.
variables
.
map
{
|
v
|
v
.
fetch
(
:key
)
}
variables
=
pipeline
.
context_
variables
.
map
{
|
v
|
v
.
fetch
(
:key
)
}
expect
(
variables
).
to
include
'KUBECONFIG'
,
'KUBE_DOMAIN'
end
...
...
@@ -567,9 +559,9 @@ describe Ci::Pipeline, :mailer do
end
context
'when kubernetes is not configured'
do
describe
'#variables'
do
describe
'#
context_
variables'
do
it
'does not return kubernetes related variables'
do
variables
=
pipeline
.
variables
.
map
{
|
v
|
v
.
fetch
(
:key
)
}
variables
=
pipeline
.
context_
variables
.
map
{
|
v
|
v
.
fetch
(
:key
)
}
expect
(
variables
).
not_to
include
'KUBECONFIG'
,
'KUBE_DOMAIN'
end
...
...
This diff is collapsed.
Click to expand it.
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