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

dvcs.rb « jira « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ddf2cd76709c5af78866a7562e134e94f26a7d7e (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 Jira
    module Dvcs
      ENCODED_SLASH = '@'
      SLASH = '/'
      ENCODED_ROUTE_REGEX = /[a-zA-Z0-9_\-\.#{ENCODED_SLASH}]+/.freeze

      def self.encode_slash(path)
        path.gsub(SLASH, ENCODED_SLASH)
      end

      def self.decode_slash(path)
        path.gsub(ENCODED_SLASH, SLASH)
      end

      # To present two types of projects stored by Jira,
      # Type 1 are projects imported prior to nested group support,
      # those project names are not full_path, so they are presented differently
      # to maintain backwards compatibility.
      # Type 2 are projects imported after nested group support,
      # those project names are encoded full path
      #
      # @param [Project] project
      def self.encode_project_name(project)
        if project.namespace.has_parent?
          encode_slash(project.full_path)
        else
          project.path
        end
      end

      # To interpret two types of project names stored by Jira (see `encode_project_name`)
      #
      # @param [String] project
      #  Either an encoded full path, or just project name
      # @param [String] namespace
      def self.restore_full_path(namespace:, project:)
        if project.include?(ENCODED_SLASH)
          project.gsub(ENCODED_SLASH, SLASH)
        else
          "#{namespace}/#{project}"
        end
      end
    end
  end
end