From 59d49f70c3b36e633b78e82fe3bd85b53f06900b Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 13 Feb 2018 23:35:45 +0800 Subject: Rename Git::Repository::Location to Git::Location --- qa/qa/git/location.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 qa/qa/git/location.rb (limited to 'qa/qa/git/location.rb') diff --git a/qa/qa/git/location.rb b/qa/qa/git/location.rb new file mode 100644 index 00000000000..fa3f5721d7a --- /dev/null +++ b/qa/qa/git/location.rb @@ -0,0 +1,39 @@ +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 self.parse(git_uri) + if git_uri.start_with?('ssh://') + new(git_uri, 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') + new(git_uri, URI.parse("ssh://#{user_host}/#{path}")) + end + end + + def initialize(git_uri, uri) + @git_uri = git_uri + @uri = uri + end + + def scheme + uri.scheme || 'ssh' + end + + def port + uri.port || 22 + end + end + end +end -- cgit v1.2.1 From de484c6ba035a4b0ed0c0a42212aaedf9788c45c Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 13 Feb 2018 23:37:36 +0800 Subject: Just use initialize and remove scheme we're not using --- qa/qa/git/location.rb | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'qa/qa/git/location.rb') diff --git a/qa/qa/git/location.rb b/qa/qa/git/location.rb index fa3f5721d7a..55f7213972d 100644 --- a/qa/qa/git/location.rb +++ b/qa/qa/git/location.rb @@ -11,26 +11,18 @@ module QA # See: config/initializers/1_settings.rb # Settings#build_gitlab_shell_ssh_path_prefix - def self.parse(git_uri) - if git_uri.start_with?('ssh://') - new(git_uri, URI.parse(git_uri)) + 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') - new(git_uri, URI.parse("ssh://#{user_host}/#{path}")) + URI.parse("ssh://#{user_host}/#{path}") end end - def initialize(git_uri, uri) - @git_uri = git_uri - @uri = uri - end - - def scheme - uri.scheme || 'ssh' - end - def port uri.port || 22 end -- cgit v1.2.1 From 36c76ec6f2f72d48319e1dc2050850cb393c4959 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 14 Feb 2018 15:27:18 +0800 Subject: Indent as Rubocop like --- qa/qa/git/location.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'qa/qa/git/location.rb') diff --git a/qa/qa/git/location.rb b/qa/qa/git/location.rb index 55f7213972d..30538388530 100644 --- a/qa/qa/git/location.rb +++ b/qa/qa/git/location.rb @@ -13,14 +13,15 @@ module QA # 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 + @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 -- cgit v1.2.1