From 6a5b6dfc9afb2312fee28b4660be44f27f3039da Mon Sep 17 00:00:00 2001 From: Dr Nic Williams Date: Tue, 5 Sep 2017 10:03:02 +1000 Subject: [PATCH] include PR author user_login in metadata --- README.md | 8 +++++--- assets/lib/commands/in.rb | 2 ++ spec/commands/in_spec.rb | 21 +++++++++++++-------- spec/integration/in_spec.rb | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 56b8179..33842a9 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ git config --get pullrequest.url # returns the URL to the pull request git config --get pullrequest.branch # returns the branch name used for the pull request git config --get pullrequest.id # returns the ID number of the PR git config --get pullrequest.basebranch # returns the base branch used for the pull request +git config --get pullrequest.userlogin # returns the github user login for the pull request author ``` @@ -125,10 +126,12 @@ git config --get pullrequest.basebranch # returns the base branch used for the p * `.git/base_branch`: the base branch of the pull request + * `.git/user_login`: the user login of the pull request author + #### Parameters * `git.depth`: *Optional.* If a positive integer is given, *shallow* clone the - repository using the `--depth` option. + repository using the `--depth` option. * `git.submodules`: *Optional*, default `all`. If `none`, submodules will not be fetched. If specified as a list of paths, only the given paths will be @@ -158,7 +161,7 @@ Set the status message for `concourse-ci` context on specified pull request. This supports the [build environment](http://concourse.ci/implementing-resources.html#resource-metadata) variables provided by concourse. For example, `context: $BUILD_JOB_NAME` will set the context to the job name. -* `comment`: *Optional.* The file path of the comment message. Comment owner is same with the owner of `access_token`. +* `comment`: *Optional.* The file path of the comment message. Comment owner is same with the owner of `access_token`. * `merge.method`: *Optional.* Use this to merge the PR into the target branch of the PR. There are three available merge methods -- `merge`, `squash`, or `rebase`. Please this [doc](https://developer.github.com/changes/2016-09-26-pull-request-merge-api-update/) for more information. @@ -179,4 +182,3 @@ Requires `ruby` to be installed. bundle install bundle exec rspec ``` - diff --git a/assets/lib/commands/in.rb b/assets/lib/commands/in.rb index f561652..26eadab 100755 --- a/assets/lib/commands/in.rb +++ b/assets/lib/commands/in.rb @@ -30,6 +30,7 @@ def output echo "#{pr['number']}" > id echo "#{pr['head']['ref']}" > branch echo "#{pr['base']['ref']}" > base_branch + echo "#{pr['base']['user']['login']}" > userlogin BASH end @@ -42,6 +43,7 @@ def output git config --add pullrequest.id #{pr['number']} 1>&2 git config --add pullrequest.branch #{pr['head']['ref']} 1>&2 git config --add pullrequest.basebranch #{pr['base']['ref']} 1>&2 + git config --add pullrequest.userlogin #{pr['base']['user']['login']} 1>&2 BASH case input.params.git.submodules diff --git a/spec/commands/in_spec.rb b/spec/commands/in_spec.rb index 990a1c1..314993d 100644 --- a/spec/commands/in_spec.rb +++ b/spec/commands/in_spec.rb @@ -52,7 +52,7 @@ def dest_dir end before(:all) 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' }) + 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' } }) @output = get('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'uri' => git_uri, 'repo' => 'jtarchie/test' }) end @@ -88,6 +88,11 @@ def dest_dir expect(value).to eq 'master' end + it 'sets config variable to user_login name' do + value = git('config pullrequest.userlogin', dest_dir) + expect(value).to eq 'jtarchie' + end + it 'creates a file that icludes the id in the .git folder' do value = File.read(File.join(dest_dir,'.git','id')).strip() expect(value).to eq '1' @@ -112,7 +117,7 @@ def dest_dir 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' }) + 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' } }) expect do get('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'uri' => 'invalid_git_uri', 'repo' => 'jtarchie/test' }) @@ -125,7 +130,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' }, mergeable: true) + html_url: 'http://example.com', number: 1, head: { ref: 'foo' }, base: { ref: 'master', user: { login: 'jtarchie' } }, mergeable: true) get('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'uri' => git_uri, 'repo' => 'jtarchie/test' }, 'params' => { 'fetch_merge' => false }) @@ -135,7 +140,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' }, mergeable: true) + html_url: 'http://example.com', number: 1, head: { ref: 'foo' }, base: { ref: 'master', user: { login: 'jtarchie' } }, mergeable: true) expect do get('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'uri' => git_uri, 'repo' => 'jtarchie/test' }, 'params' => { 'fetch_merge' => false }) @@ -146,7 +151,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' }, mergeable: true) + html_url: 'http://example.com', number: 1, head: { ref: 'foo' }, base: { ref: 'master', user: { login: 'jtarchie' } }, mergeable: true) get('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'uri' => git_uri, 'repo' => 'jtarchie/test' }, 'params:' => { 'fetch_merge' => true }) @@ -156,7 +161,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' }, mergeable: true) + html_url: 'http://example.com', number: 1, head: { ref: 'foo' }, base: { ref: 'master', user: { login: 'jtarchie' } }, mergeable: true) expect do get('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'uri' => git_uri, 'repo' => 'jtarchie/test' }, 'params' => { 'fetch_merge' => true }) @@ -169,7 +174,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' }, mergeable: false) + html_url: 'http://example.com', number: 1, head: { ref: 'foo' }, base: { ref: 'master', user: { login: 'jtarchie' } }, mergeable: false) expect do get('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'uri' => git_uri, 'repo' => 'jtarchie/test' }, 'params' => { 'fetch_merge' => true }) @@ -183,7 +188,7 @@ def dest_dir 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' }) + base: { ref: 'master', user: { login: 'jtarchie' } }) end def expect_arg(*args) diff --git a/spec/integration/in_spec.rb b/spec/integration/in_spec.rb index f627d45..2f7a144 100644 --- a/spec/integration/in_spec.rb +++ b/spec/integration/in_spec.rb @@ -35,7 +35,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' } }) + .and_return(json: { html_url: 'http://example.com', number: 1, head: { ref: 'foo' }, base: { ref: 'master', user: { login: 'jtarchie' } } }) end it 'checks out the pull request to dest_dir' do