diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 22:14:29 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 22:14:29 +0000 |
commit | 9eeb914c7a90424e68d5737f34d9c5aee13508c6 (patch) | |
tree | f49f7a47517c598ab5cebe7c770789d83d5e2891 /lib | |
parent | 6026722aa6e33b2b7bebabac8f611507f535ca12 (diff) | |
download | gitlab-ce-9eeb914c7a90424e68d5737f34d9c5aee13508c6.tar.gz |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc44
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/config/entry/processable.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/variables.rb | 16 | ||||
-rw-r--r-- | lib/gitlab/ci/variables/helpers.rb | 28 | ||||
-rw-r--r-- | lib/gitlab/ci/yaml_processor/result.rb | 10 |
4 files changed, 27 insertions, 29 deletions
diff --git a/lib/gitlab/ci/config/entry/processable.rb b/lib/gitlab/ci/config/entry/processable.rb index 975da8662e1..78794f524f4 100644 --- a/lib/gitlab/ci/config/entry/processable.rb +++ b/lib/gitlab/ci/config/entry/processable.rb @@ -120,7 +120,7 @@ module Gitlab stage: stage_value, extends: extends, rules: rules_value, - job_variables: variables_entry.value_with_data, + job_variables: variables_value.to_h, root_variables_inheritance: root_variables_inheritance, only: only_value, except: except_value, diff --git a/lib/gitlab/ci/config/entry/variables.rb b/lib/gitlab/ci/config/entry/variables.rb index 3130aec0446..efb469ee32a 100644 --- a/lib/gitlab/ci/config/entry/variables.rb +++ b/lib/gitlab/ci/config/entry/variables.rb @@ -18,9 +18,7 @@ module Gitlab end def value - @config.to_h do |key, data| - [key.to_s, expand_data(data)[:value]] - end + @config.to_h { |key, value| [key.to_s, expand_value(value)[:value]] } end def self.default(**) @@ -28,9 +26,7 @@ module Gitlab end def value_with_data - @config.to_h do |key, data| - [key.to_s, expand_data(data)] - end + @config.to_h { |key, value| [key.to_s, expand_value(value)] } end def use_value_data? @@ -39,11 +35,11 @@ module Gitlab private - def expand_data(data) - if data.is_a?(Hash) - { value: data[:value].to_s, description: data[:description] }.compact + def expand_value(value) + if value.is_a?(Hash) + { value: value[:value].to_s, description: value[:description] } else - { value: data.to_s } + { value: value.to_s, description: nil } end end end 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 diff --git a/lib/gitlab/ci/yaml_processor/result.rb b/lib/gitlab/ci/yaml_processor/result.rb index f203f88442d..4bd1ac3b67f 100644 --- a/lib/gitlab/ci/yaml_processor/result.rb +++ b/lib/gitlab/ci/yaml_processor/result.rb @@ -43,7 +43,7 @@ module Gitlab end def root_variables - @root_variables ||= transform_to_array(variables) + @root_variables ||= transform_to_yaml_variables(variables) end def jobs @@ -70,7 +70,7 @@ module Gitlab environment: job[:environment_name], coverage_regex: job[:coverage], # yaml_variables is calculated with using job_variables in Seed::Build - job_variables: transform_to_array(job[:job_variables]), + job_variables: transform_to_yaml_variables(job[:job_variables]), root_variables_inheritance: job[:root_variables_inheritance], needs_attributes: job.dig(:needs, :job), interruptible: job[:interruptible], @@ -114,7 +114,7 @@ module Gitlab Gitlab::Ci::Variables::Helpers.inherit_yaml_variables( from: root_variables, - to: job[:job_variables], + to: transform_to_yaml_variables(job[:job_variables]), inheritance: job.fetch(:root_variables_inheritance, true) ) end @@ -137,8 +137,8 @@ module Gitlab job[:release] end - def transform_to_array(variables) - ::Gitlab::Ci::Variables::Helpers.transform_to_array(variables) + def transform_to_yaml_variables(variables) + ::Gitlab::Ci::Variables::Helpers.transform_to_yaml_variables(variables) end end end |