Skip to content

Commit

Permalink
Default to SSH clone URI when private_key is set
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyra Naeseth committed Sep 10, 2018
1 parent 37d226d commit dad7ba3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
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

0 comments on commit dad7ba3

Please sign in to comment.