debian-mirror-gitlab/lib/gitlab/repo_path.rb

44 lines
1.2 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
module Gitlab
module RepoPath
NotFoundError = Class.new(StandardError)
def self.parse(repo_path)
2017-09-10 17:25:29 +05:30
wiki = false
2017-08-17 22:00:37 +05:30
project_path = strip_storage_path(repo_path.sub(/\.git\z/, ''), fail_on_not_found: false)
2017-09-10 17:25:29 +05:30
project, was_redirected = find_project(project_path)
if project_path.end_with?('.wiki') && project.nil?
project, was_redirected = find_project(project_path.chomp('.wiki'))
2017-08-17 22:00:37 +05:30
wiki = true
end
2017-09-10 17:25:29 +05:30
redirected_path = project_path if was_redirected
[project, wiki, redirected_path]
2017-08-17 22:00:37 +05:30
end
def self.strip_storage_path(repo_path, fail_on_not_found: true)
result = repo_path
storage = Gitlab.config.repositories.storages.values.find do |params|
2018-05-09 12:01:36 +05:30
repo_path.start_with?(params.legacy_disk_path)
2017-08-17 22:00:37 +05:30
end
if storage
2018-05-09 12:01:36 +05:30
result = result.sub(storage.legacy_disk_path, '')
2017-08-17 22:00:37 +05:30
elsif fail_on_not_found
raise NotFoundError.new("No known storage path matches #{repo_path.inspect}")
end
2018-03-17 18:26:18 +05:30
result.sub(%r{\A/*}, '')
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
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
2017-08-17 22:00:37 +05:30
end
end