summaryrefslogtreecommitdiff
path: root/lib/gitlab/repository_url_builder.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 15:09:30 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 15:09:30 +0000
commitc6b3ec3f56fa32a0e0ed3de0d0878d25f1adaddf (patch)
tree967afee9a510ff9dd503ebd83706dc760ec2e3ed /lib/gitlab/repository_url_builder.rb
parent903ccf7c93eb9490c76857bffe744249cc07de09 (diff)
downloadgitlab-ce-c6b3ec3f56fa32a0e0ed3de0d0878d25f1adaddf.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/repository_url_builder.rb')
-rw-r--r--lib/gitlab/repository_url_builder.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/gitlab/repository_url_builder.rb b/lib/gitlab/repository_url_builder.rb
new file mode 100644
index 00000000000..2b88af1f77c
--- /dev/null
+++ b/lib/gitlab/repository_url_builder.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module RepositoryUrlBuilder
+ class << self
+ def build(path, protocol: :ssh)
+ # TODO: See https://gitlab.com/gitlab-org/gitlab/-/issues/213021
+ path = path.sub('@snippets', 'snippets')
+
+ case protocol
+ when :ssh
+ ssh_url(path)
+ when :http
+ http_url(path)
+ else
+ raise NotImplementedError.new("No URL builder defined for protocol #{protocol}")
+ end
+ end
+
+ private
+
+ def ssh_url(path)
+ Gitlab.config.gitlab_shell.ssh_path_prefix + "#{path}.git"
+ end
+
+ def http_url(path)
+ root = Gitlab::CurrentSettings.custom_http_clone_url_root.presence || Gitlab::Routing.url_helpers.root_url
+
+ Gitlab::Utils.append_path(root, "#{path}.git")
+ end
+ end
+ end
+end