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:
Diffstat (limited to 'lib/gitlab/ci/variables/helpers.rb')
-rw-r--r--lib/gitlab/ci/variables/helpers.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/gitlab/ci/variables/helpers.rb b/lib/gitlab/ci/variables/helpers.rb
new file mode 100644
index 00000000000..e2a54f90ecb
--- /dev/null
+++ b/lib/gitlab/ci/variables/helpers.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Variables
+ module Helpers
+ class << self
+ def merge_variables(current_vars, new_vars)
+ current_vars = transform_from_yaml_variables(current_vars)
+ new_vars = transform_from_yaml_variables(new_vars)
+
+ transform_to_yaml_variables(
+ current_vars.merge(new_vars)
+ )
+ 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 if vars.is_a?(Hash)
+
+ vars.to_a.map { |var| [var[:key].to_s, var[:value]] }.to_h
+ end
+ end
+ end
+ end
+ end
+end