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

refs_finder.rb « finders « git « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a0117bc0fa91e45c9f1b37f32415aff7506e2174 (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
# frozen_string_literal: true

module Gitlab
  module Git
    module Finders
      class RefsFinder
        attr_reader :repository, :search, :ref_type

        UnknownRefTypeError = Class.new(StandardError)

        def initialize(repository, search:, ref_type:)
          @repository = repository
          @search = search
          @ref_type = ref_type
        end

        def execute
          pattern = [prefix, search, "*"].compact.join

          repository.list_refs(
            [pattern]
          )
        end

        private

        def prefix
          case ref_type
          when :branches
            Gitlab::Git::BRANCH_REF_PREFIX
          when :tags
            Gitlab::Git::TAG_REF_PREFIX
          else
            raise UnknownRefTypeError, "ref_type must be one of [:branches, :tags]"
          end
        end
      end
    end
  end
end