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

group.rb « builder « variables « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3f3e04038dfecb4db0c8ddba8f35b666b95079b7 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true

module Gitlab
  module Ci
    module Variables
      class Builder
        class Group
          include Gitlab::Utils::StrongMemoize

          def initialize(group)
            @group = group
          end

          def secret_variables(environment:, protected_ref: false)
            return [] unless group

            variables = base_scope
            variables = variables.unprotected unless protected_ref
            variables = variables.for_environment(environment)
            variables = variables.group_by(&:group_id)
            variables = list_of_ids.reverse.flat_map { |group| variables[group.id] }.compact
            Gitlab::Ci::Variables::Collection.new(variables)
          end

          private

          attr_reader :group

          def base_scope
            strong_memoize(:base_scope) do
              ::Ci::GroupVariable.for_groups(list_of_ids)
            end
          end

          def list_of_ids
            strong_memoize(:list_of_ids) do
              if group.root_ancestor.use_traversal_ids?
                [group] + group.ancestors(hierarchy_order: :asc)
              else
                [group] + group.ancestors
              end
            end
          end
        end
      end
    end
  end
end