diff --git a/README.md b/README.md index 92460fe..cc4a304 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,7 @@ git config --get pullrequest.body # returns the PR body git config --get pullrequest.basebranch # returns the base branch used for the pull request git config --get pullrequest.basesha # returns the commit of the base branch used for the pull request git config --get pullrequest.userlogin # returns the github user login for the pull request author +git config --get pullrequest.repo # returns the full name of the source repo of the PR. ``` @@ -146,6 +147,8 @@ git config --get pullrequest.userlogin # returns the github user login for the * `.git/body`: the body of the pull request. + * `.git/repo`: the full name of the source repo of the PR. + #### Parameters * `git.depth`: *Optional.* If a positive integer is given, *shallow* clone the diff --git a/assets/lib/commands/in.rb b/assets/lib/commands/in.rb index 3308c0d..3b8cc2d 100755 --- a/assets/lib/commands/in.rb +++ b/assets/lib/commands/in.rb @@ -35,6 +35,7 @@ def output File.write('base_sha', pr['base']['sha']) File.write('userlogin', pr['user']['login']) File.write('head_sha', pr['head']['sha']) + File.write('repo', pr['head']['repo']['full_name']) end Dir.chdir(destination) do @@ -49,6 +50,7 @@ def output git config --add pullrequest.basebranch #{pr['base']['ref'].to_s.shellescape} 1>&2 git config --add pullrequest.basesha #{pr['base']['sha'].to_s.shellescape} 1>&2 git config --add pullrequest.userlogin #{pr['user']['login'].to_s.shellescape} 1>&2 + git config --add pullrequest.repo #{pr['head']['repo']['full_name'].to_s.shellescape} 1>&2 BASH case input.params.git.submodules diff --git a/spec/commands/in_spec.rb b/spec/commands/in_spec.rb index b40b084..91d267b 100644 --- a/spec/commands/in_spec.rb +++ b/spec/commands/in_spec.rb @@ -59,7 +59,8 @@ def dest_dir number: 1, head: { ref: 'foo', - sha: 'hash' + sha: 'hash', + repo: { full_name: 'repo/name' } }, base: { ref: 'master', @@ -173,7 +174,7 @@ def dest_dir context 'and fetch_merge is false' do it 'checks out as a branch named in the PR' 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' }, mergeable: true) + html_url: 'http://example.com', number: 1, head: { ref: 'foo', repo: { full_name: 'repo/name' } }, base: { ref: 'master', user: { login: 'jtarchie' } }, user: { login: 'jtarchie-contributor' }, mergeable: true) get('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'uri' => git_uri, 'repo' => 'jtarchie/test' }, 'params' => { 'fetch_merge' => false }) @@ -183,7 +184,7 @@ def dest_dir it 'does not fail cloning' 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' }, mergeable: true) + html_url: 'http://example.com', number: 1, head: { ref: 'foo', repo: { full_name: 'repo/name' } }, base: { ref: 'master', user: { login: 'jtarchie' } }, user: { login: 'jtarchie-contributor' }, mergeable: true) expect do get('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'uri' => git_uri, 'repo' => 'jtarchie/test' }, 'params' => { 'fetch_merge' => false }) @@ -194,7 +195,7 @@ def dest_dir context 'and fetch_merge is true' do it 'checks out the branch the PR would be merged into' 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' }, mergeable: true) + html_url: 'http://example.com', number: 1, head: { ref: 'foo', repo: { full_name: 'repo/name' } }, base: { ref: 'master', user: { login: 'jtarchie' } }, user: { login: 'jtarchie-contributor' }, mergeable: true) get('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'uri' => git_uri, 'repo' => 'jtarchie/test' }, 'params:' => { 'fetch_merge' => true }) @@ -204,7 +205,7 @@ def dest_dir it 'does not fail cloning' 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' }, mergeable: true) + html_url: 'http://example.com', number: 1, head: { ref: 'foo', repo: { full_name: 'repo/name' } }, base: { ref: 'master', user: { login: 'jtarchie' } }, user: { login: 'jtarchie-contributor' }, mergeable: true) expect do get('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'uri' => git_uri, 'repo' => 'jtarchie/test' }, 'params' => { 'fetch_merge' => true }) @@ -217,7 +218,7 @@ def dest_dir context 'and fetch_merge is true' do it 'raises a helpful error 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' }, mergeable: false) + html_url: 'http://example.com', number: 1, head: { ref: 'foo', repo: { full_name: 'repo/name' } }, base: { ref: 'master', user: { login: 'jtarchie' } }, user: { login: 'jtarchie-contributor' }, mergeable: false) expect do get('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'uri' => git_uri, 'repo' => 'jtarchie/test' }, 'params' => { 'fetch_merge' => true }) @@ -230,7 +231,7 @@ def dest_dir before do stub_json('https://api.github.com:443/repos/jtarchie/test/pulls/1', html_url: 'http://example.com', number: 1, - head: { ref: 'foo' }, + head: { ref: 'foo', repo: { full_name: 'repo/name' } }, base: { ref: 'master', user: { login: 'jtarchie' } }, user: { login: 'jtarchie-contributor' }) end diff --git a/spec/integration/in_spec.rb b/spec/integration/in_spec.rb index 3d9c1e3..026bef8 100644 --- a/spec/integration/in_spec.rb +++ b/spec/integration/in_spec.rb @@ -37,7 +37,7 @@ def commit(msg) context 'for every PR that is checked out' do before do proxy.stub('https://api.github.com:443/repos/jtarchie/test/pulls/1') - .and_return(json: { html_url: 'http://example.com', number: 1, head: { ref: 'foo' }, base: { ref: 'master', user: { login: 'jtarchie' } }, user: { login: 'jtarchie-contributor' } }) + .and_return(json: { html_url: 'http://example.com', number: 1, head: { ref: 'foo', repo: { full_name: 'repo/name' } }, base: { ref: 'master', user: { login: 'jtarchie' } }, user: { login: 'jtarchie-contributor' } }) end it 'checks out the pull request to dest_dir' do