diff options
Diffstat (limited to 'app/services/git/base_hooks_service.rb')
-rw-r--r-- | app/services/git/base_hooks_service.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/app/services/git/base_hooks_service.rb b/app/services/git/base_hooks_service.rb index 0801fd4d03f..d935d9e8cdc 100644 --- a/app/services/git/base_hooks_service.rb +++ b/app/services/git/base_hooks_service.rb @@ -85,12 +85,36 @@ module Git before: oldrev, after: newrev, ref: ref, + variables_attributes: generate_vars_from_push_options || [], push_options: params[:push_options] || {}, checkout_sha: Gitlab::DataBuilder::Push.checkout_sha( project.repository, newrev, ref) } end + def ci_variables_from_push_options + strong_memoize(:ci_variables_from_push_options) do + params[:push_options]&.deep_symbolize_keys&.dig(:ci, :variable) + end + end + + def generate_vars_from_push_options + return [] unless ci_variables_from_push_options + + ci_variables_from_push_options.map do |var_definition, _count| + key, value = var_definition.to_s.split("=", 2) + + # Accept only valid format. We ignore the following formats + # 1. "=123". In this case, `key` will be an empty string + # 2. "FOO". In this case, `value` will be nil. + # However, the format "FOO=" will result in key beign `FOO` and value + # being an empty string. This is acceptable. + next if key.blank? || value.nil? + + { "key" => key, "variable_type" => "env_var", "secret_value" => value } + end.compact + end + def push_data_params(commits:, with_changed_files: true) { oldrev: oldrev, |