forked from jtarchie/github-pullrequest-resource
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default to SSH clone URI when private_key is set
Fixes jtarchie#205.
- Loading branch information
Lyra Naeseth
committed
Sep 10, 2018
1 parent
37d226d
commit dad7ba3
Showing
2 changed files
with
24 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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' }) | ||
|