2017-03-24 11:54:22 -04:00
|
|
|
module Gitlab
|
|
|
|
module RepoPath
|
|
|
|
NotFoundError = Class.new(StandardError)
|
|
|
|
|
2017-04-28 12:52:09 -04:00
|
|
|
def self.parse(repo_path)
|
|
|
|
project_path = strip_storage_path(repo_path.sub(/\.git\z/, ''), fail_on_not_found: false)
|
|
|
|
project = Project.find_by_full_path(project_path)
|
|
|
|
if project_path.end_with?('.wiki') && !project
|
|
|
|
project = Project.find_by_full_path(project_path.chomp('.wiki'))
|
|
|
|
wiki = true
|
|
|
|
else
|
|
|
|
wiki = false
|
|
|
|
end
|
|
|
|
|
|
|
|
[project, wiki]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.strip_storage_path(repo_path, fail_on_not_found: true)
|
|
|
|
result = repo_path
|
2017-03-24 11:54:22 -04:00
|
|
|
|
2017-04-28 12:52:09 -04:00
|
|
|
storage = Gitlab.config.repositories.storages.values.find do |params|
|
|
|
|
repo_path.start_with?(params['path'])
|
2017-03-24 11:54:22 -04:00
|
|
|
end
|
|
|
|
|
2017-04-28 12:52:09 -04:00
|
|
|
if storage
|
|
|
|
result = result.sub(storage['path'], '')
|
|
|
|
elsif fail_on_not_found
|
2017-03-24 11:54:22 -04:00
|
|
|
raise NotFoundError.new("No known storage path matches #{repo_path.inspect}")
|
|
|
|
end
|
|
|
|
|
|
|
|
result.sub(/\A\/*/, '')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|