Commit bd1f1aca authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Improve predefined variables collection methods

parent 33404c7b6060
...@@ -1574,17 +1574,16 @@ def has_ci? ...@@ -1574,17 +1574,16 @@ def has_ci?
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
......
...@@ -11,11 +11,11 @@ def initialize(variables = []) ...@@ -11,11 +11,11 @@ def initialize(variables = [])
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
......
...@@ -35,6 +35,11 @@ ...@@ -35,6 +35,11 @@
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 @@ ...@@ -60,6 +65,11 @@
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
......
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