diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /app/finders/ci/variables_finder.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'app/finders/ci/variables_finder.rb')
-rw-r--r-- | app/finders/ci/variables_finder.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/app/finders/ci/variables_finder.rb b/app/finders/ci/variables_finder.rb new file mode 100644 index 00000000000..d933643ffb2 --- /dev/null +++ b/app/finders/ci/variables_finder.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Ci + class VariablesFinder + attr_reader :project, :params + + def initialize(project, params) + @project, @params = project, params + + raise ArgumentError, 'Please provide params[:key]' if params[:key].blank? + end + + def execute + variables = project.variables + variables = by_key(variables) + variables = by_environment_scope(variables) + variables + end + + private + + def by_key(variables) + variables.by_key(params[:key]) + end + + def by_environment_scope(variables) + environment_scope = params.dig(:filter, :environment_scope) + environment_scope.present? ? variables.by_environment_scope(environment_scope) : variables + end + end +end |