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

variables_finder.rb « ci « finders « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d933643ffb26b343d54b856d9f59d551d16797b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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