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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/repo_path.rb')
-rw-r--r--lib/gitlab/repo_path.rb36
1 files changed, 16 insertions, 20 deletions
diff --git a/lib/gitlab/repo_path.rb b/lib/gitlab/repo_path.rb
index 42b94d5cf3b..a4d1adf7671 100644
--- a/lib/gitlab/repo_path.rb
+++ b/lib/gitlab/repo_path.rb
@@ -13,7 +13,6 @@ module Gitlab
# @returns [HasRepository, Project, String, String]
def self.parse(path)
repo_path = path.delete_prefix('/').delete_suffix('.git')
- redirected_path = nil
# Detect the repo type based on the path, the first one tried is the project
# type, which does not have a suffix.
@@ -26,9 +25,11 @@ module Gitlab
# Removing the suffix (.wiki, .design, ...) from the project path
full_path = repo_path.chomp(type.path_suffix)
- container, project, redirected_path = find_container(type, full_path)
+ container, project = find_container(type, full_path)
+ next unless container
- return [container, project, type, redirected_path] if container
+ redirected_path = repo_path if redirected?(container, repo_path)
+ return [container, project, type, redirected_path]
end
# When a project did not exist, the parsed repo_type would be empty.
@@ -40,32 +41,28 @@ module Gitlab
# Returns an array containing:
# - The repository container
# - The related project (if available)
- # - The original container path (if redirected)
#
# @returns [HasRepository, Project, String]
def self.find_container(type, full_path)
- return [nil, nil, nil] if full_path.blank?
+ return [nil, nil] if full_path.blank?
if type.snippet?
- snippet, redirected_path = find_snippet(full_path)
+ snippet = find_snippet(full_path)
- [snippet, snippet&.project, redirected_path]
+ [snippet, snippet&.project]
elsif type.wiki?
- wiki, redirected_path = find_wiki(full_path)
+ wiki = find_wiki(full_path)
- [wiki, wiki.try(:project), redirected_path]
+ [wiki, wiki.try(:project)]
else
- project, redirected_path = find_project(full_path)
+ project = find_project(full_path)
- [project, project, redirected_path]
+ [project, project]
end
end
def self.find_project(project_path)
- project = Project.find_by_full_path(project_path, follow_redirects: true)
- redirected_path = project_path if redirected?(project, project_path)
-
- [project, redirected_path]
+ Project.find_by_full_path(project_path, follow_redirects: true)
end
def self.redirected?(container, container_path)
@@ -77,11 +74,11 @@ module Gitlab
# - h5bp/html5-boilerplate/snippets/53
def self.find_snippet(snippet_path)
snippet_id, project_path = extract_snippet_info(snippet_path)
- return [nil, nil] unless snippet_id
+ return unless snippet_id
- project, redirected_path = find_project(project_path) if project_path
+ project = find_project(project_path) if project_path
- [Snippet.find_by_id_and_project(id: snippet_id, project: project), redirected_path]
+ Snippet.find_by_id_and_project(id: snippet_id, project: project)
end
# Wiki path can be either:
@@ -93,10 +90,9 @@ module Gitlab
# - group/subgroup
def self.find_wiki(container_path)
container = Routable.find_by_full_path(container_path, follow_redirects: true)
- redirected_path = container_path if redirected?(container, container_path)
# In CE, Group#wiki is not available so this will return nil for a group path.
- [container&.try(:wiki), redirected_path]
+ container&.try(:wiki)
end
def self.extract_snippet_info(snippet_path)