repo_path.rb 804 Bytes
Newer Older
1 2
# frozen_string_literal: true

3 4 5 6
module Gitlab
  module RepoPath
    NotFoundError = Class.new(StandardError)

7
    def self.parse(repo_path)
8
      wiki = false
9 10
      project_path = repo_path.sub(/\.git\z/, '').sub(%r{\A/}, '')

11 12 13 14
      project, was_redirected = find_project(project_path)

      if project_path.end_with?('.wiki') && project.nil?
        project, was_redirected = find_project(project_path.chomp('.wiki'))
15 16 17
        wiki = true
      end

18 19 20
      redirected_path = project_path if was_redirected

      [project, wiki, redirected_path]
21 22
    end

23 24 25 26 27 28
    def self.find_project(project_path)
      project = Project.find_by_full_path(project_path, follow_redirects: true)
      was_redirected = project && project.full_path.casecmp(project_path) != 0

      [project, was_redirected]
    end
29 30
  end
end