Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

Default to SSH clone URI when private_key is set #206

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion assets/lib/commands/in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def pr
end

def uri
input.source.uri || "https://github.com/#{input.source.repo}"
return input.source.uri if input.source.uri
return "[email protected]:#{input.source.repo}.git" if input.source.private_key
return "https://github.com/#{input.source.repo}"
end

def ref
Expand Down
24 changes: 21 additions & 3 deletions spec/commands/in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ def git_uri

let(:dest_dir) { Dir.mktmpdir }

def get(payload)
def command(payload)
payload['source']['skip_ssl_verification'] = true
Input.instance(payload: payload)
command = Commands::In.new(destination: dest_dir)
command.output

Commands::In.new(destination: dest_dir)
end

def get(payload)
command(payload).output
end

def stub_json(uri, body)
Expand Down Expand Up @@ -158,6 +162,20 @@ def dest_dir
end
end

context 'when an SSH key is specified' do
it 'defaults to an SSH clone URI' do
cmd = command('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'private_key' => '-----BEGIN', 'repo' => 'jtarchie/test' })
expect(cmd.send(:uri)).to eq '[email protected]:jtarchie/test.git'
end
end

context 'when an SSH key is not specified' do
it 'defaults to an HTTPS clone URI' do
cmd = command('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'repo' => 'jtarchie/test' })
expect(cmd.send(:uri)).to eq 'https://github.com/jtarchie/test'
end
end

context 'when the git clone fails' do
it 'provides a helpful erorr message' do
stub_json('https://api.github.com:443/repos/jtarchie/test/pulls/1', html_url: 'http://example.com', number: 1, head: { ref: 'foo' }, base: { ref: 'master', user: { login: 'jtarchie' } }, user: { login: 'jtarchie-contributor' })
Expand Down