diff options
Diffstat (limited to 'qa/qa/git/location.rb')
-rw-r--r-- | qa/qa/git/location.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/qa/qa/git/location.rb b/qa/qa/git/location.rb new file mode 100644 index 00000000000..30538388530 --- /dev/null +++ b/qa/qa/git/location.rb @@ -0,0 +1,32 @@ +require 'uri' +require 'forwardable' + +module QA + module Git + class Location + extend Forwardable + + attr_reader :git_uri, :uri + def_delegators :@uri, :user, :host, :path + + # See: config/initializers/1_settings.rb + # Settings#build_gitlab_shell_ssh_path_prefix + def initialize(git_uri) + @git_uri = git_uri + @uri = + if git_uri.start_with?('ssh://') + URI.parse(git_uri) + else + *rest, path = git_uri.split(':') + # Host cannot have : so we'll need to escape it + user_host = rest.join('%3A').sub(/\A\[(.+)\]\z/, '\1') + URI.parse("ssh://#{user_host}/#{path}") + end + end + + def port + uri.port || 22 + end + end + end +end |