Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-19 01:14:29 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-19 01:14:29 +0300
commit9eeb914c7a90424e68d5737f34d9c5aee13508c6 (patch)
treef49f7a47517c598ab5cebe7c770789d83d5e2891 /lib/gitlab/ci/variables/helpers.rb
parent6026722aa6e33b2b7bebabac8f611507f535ca12 (diff)
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc44
Diffstat (limited to 'lib/gitlab/ci/variables/helpers.rb')
-rw-r--r--lib/gitlab/ci/variables/helpers.rb28
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/gitlab/ci/variables/helpers.rb b/lib/gitlab/ci/variables/helpers.rb
index 300b2708e6d..7cc727bb3ea 100644
--- a/lib/gitlab/ci/variables/helpers.rb
+++ b/lib/gitlab/ci/variables/helpers.rb
@@ -6,24 +6,26 @@ module Gitlab
module Helpers
class << self
def merge_variables(current_vars, new_vars)
- return current_vars if new_vars.blank?
+ current_vars = transform_from_yaml_variables(current_vars)
+ new_vars = transform_from_yaml_variables(new_vars)
- current_vars = transform_to_array(current_vars) if current_vars.is_a?(Hash)
- new_vars = transform_to_array(new_vars) if new_vars.is_a?(Hash)
-
- (new_vars + current_vars).uniq { |var| var[:key] }
+ transform_to_yaml_variables(
+ current_vars.merge(new_vars)
+ )
end
- def transform_to_array(vars)
- vars.to_h.map do |key, data|
- if data.is_a?(Hash)
- { key: key.to_s, **data.except(:key) }
- else
- { key: key.to_s, value: data }
- end
+ def transform_to_yaml_variables(vars)
+ vars.to_h.map do |key, value|
+ { key: key.to_s, value: value, public: true }
end
end
+ def transform_from_yaml_variables(vars)
+ return vars.stringify_keys.transform_values(&:to_s) if vars.is_a?(Hash)
+
+ vars.to_a.to_h { |var| [var[:key].to_s, var[:value]] }
+ end
+
def inherit_yaml_variables(from:, to:, inheritance:)
merge_variables(apply_inheritance(from, inheritance), to)
end
@@ -33,7 +35,7 @@ module Gitlab
def apply_inheritance(variables, inheritance)
case inheritance
when true then variables
- when false then []
+ when false then {}
when Array then variables.select { |var| inheritance.include?(var[:key]) }
end
end