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)
|
2017-06-15 20:03:54 -04:00
|
|
|
wiki = false
|
2018-05-11 07:49:52 -04:00
|
|
|
project_path = repo_path.sub(/\.git\z/, '').sub(%r{\A/}, '')
|
|
|
|
|
2017-06-15 20:03:54 -04:00
|
|
|
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-04-28 12:52:09 -04:00
|
|
|
wiki = true
|
|
|
|
end
|
|
|
|
|
2017-06-15 20:03:54 -04:00
|
|
|
redirected_path = project_path if was_redirected
|
|
|
|
|
|
|
|
[project, wiki, redirected_path]
|
2017-04-28 12:52:09 -04:00
|
|
|
end
|
|
|
|
|
2017-06-15 20:03:54 -04:00
|
|
|
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-03-24 11:54:22 -04:00
|
|
|
end
|
|
|
|
end
|