BigW Consortium Gitlab

Commit 96a7e162 by Grzegorz Bizon

Refactor context variables in pipeline model class

parent 326dc7da
...@@ -31,8 +31,6 @@ module Ci ...@@ -31,8 +31,6 @@ module Ci
has_many :auto_canceled_jobs, class_name: 'CommitStatus', foreign_key: 'auto_canceled_by_id' has_many :auto_canceled_jobs, class_name: 'CommitStatus', foreign_key: 'auto_canceled_by_id'
delegate :id, to: :project, prefix: true 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 :source, exclusion: { in: %w(unknown), unless: :importing? }, on: :create
validates :sha, presence: { unless: :importing? } validates :sha, presence: { unless: :importing? }
...@@ -306,13 +304,19 @@ module Ci ...@@ -306,13 +304,19 @@ module Ci
@stage_seeds ||= config_processor.stage_seeds(self) @stage_seeds ||= config_processor.stage_seeds(self)
end end
def variables def context_variables
project_secret_variables_for(ref: ref).map(&:to_runner_variable) + @context_variables ||= project.secret_variables_for(ref: ref).to_a
project_deployment_variables .map(&:to_runner_variable) + project.deployment_variables.to_a
end end
def has_kubernetes_available? 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 end
def has_stage_seeds? def has_stage_seeds?
......
...@@ -27,14 +27,6 @@ describe Ci::Pipeline, :mailer do ...@@ -27,14 +27,6 @@ describe Ci::Pipeline, :mailer do
it { is_expected.to respond_to :git_author_email } it { is_expected.to respond_to :git_author_email }
it { is_expected.to respond_to :short_sha } 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 describe '#source' do
context 'when creating new pipeline' do context 'when creating new pipeline' do
let(:pipeline) do let(:pipeline) do
...@@ -551,9 +543,9 @@ describe Ci::Pipeline, :mailer do ...@@ -551,9 +543,9 @@ describe Ci::Pipeline, :mailer do
project: project) project: project)
end end
describe '#variables' do describe '#context_variables' do
it 'returns kubernetes-related 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' expect(variables).to include 'KUBECONFIG', 'KUBE_DOMAIN'
end end
...@@ -567,9 +559,9 @@ describe Ci::Pipeline, :mailer do ...@@ -567,9 +559,9 @@ describe Ci::Pipeline, :mailer do
end end
context 'when kubernetes is not configured' do context 'when kubernetes is not configured' do
describe '#variables' do describe '#context_variables' do
it 'does not return kubernetes related 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' expect(variables).not_to include 'KUBECONFIG', 'KUBE_DOMAIN'
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment