diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2018-02-12 16:43:32 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2018-02-12 16:43:32 +0800 |
commit | bc2739a52ff9a5366d3d668ef0ee07e91974c540 (patch) | |
tree | 3feef5d1f12464d15c8c2140b32fc154f46d89ad | |
parent | 75984534f80b97d2bc7f05c24ce3e0cadb5b85a3 (diff) | |
download | gitlab-ce-bc2739a52ff9a5366d3d668ef0ee07e91974c540.tar.gz |
Adopt Git style URI
-rw-r--r-- | qa/qa/git/repository.rb | 14 | ||||
-rw-r--r-- | qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb | 2 | ||||
-rw-r--r-- | qa/spec/git/repository_spec.rb | 52 |
3 files changed, 67 insertions, 1 deletions
diff --git a/qa/qa/git/repository.rb b/qa/qa/git/repository.rb index 8f999511d58..606fc66b4d5 100644 --- a/qa/qa/git/repository.rb +++ b/qa/qa/git/repository.rb @@ -1,3 +1,4 @@ +require 'cgi' require 'uri' module QA @@ -5,6 +6,19 @@ module QA class Repository include Scenario::Actable + # See: config/initializers/1_settings.rb + # Settings#build_gitlab_shell_ssh_path_prefix + def self.parse_uri(git_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 self.perform(*args) Dir.mktmpdir do |dir| Dir.chdir(dir) { super } diff --git a/qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb b/qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb index 39c600aee87..c1fa8d5b58a 100644 --- a/qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb +++ b/qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb @@ -45,7 +45,7 @@ module QA repository_location end - repository_uri = URI.parse(repository_url) + repository_uri = Git::Repository.parse_uri(repository_url) gitlab_ci = <<~YAML diff --git a/qa/spec/git/repository_spec.rb b/qa/spec/git/repository_spec.rb new file mode 100644 index 00000000000..ae58355d199 --- /dev/null +++ b/qa/spec/git/repository_spec.rb @@ -0,0 +1,52 @@ +describe QA::Git::Repository do + describe '.parse_uri' do + context 'when URI starts with ssh://' do + context 'when URI has port' do + it 'parses correctly' do + uri = described_class + .parse_uri('ssh://git@qa.test:2222/sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.port).to eq(2222) + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + + context 'when URI does not have port' do + it 'parses correctly' do + uri = described_class + .parse_uri('ssh://git@qa.test/sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + end + + context 'when URI does not start with ssh://' do + context 'when host does not have colons' do + it 'parses correctly' do + uri = described_class + .parse_uri('git@qa.test:sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + + context 'when host has a colon' do + it 'parses correctly' do + uri = described_class + .parse_uri('[git@qa:test]:sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa%3Atest') + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + end + end +end |