Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.
Merged
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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


Expand All @@ -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
Expand Down Expand Up @@ -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.

Expand All @@ -179,4 +182,3 @@ Requires `ruby` to be installed.
bundle install
bundle exec rspec
```

2 changes: 2 additions & 0 deletions assets/lib/commands/in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
21 changes: 13 additions & 8 deletions spec/commands/in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand All @@ -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' })
Expand All @@ -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 })

Expand All @@ -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 })
Expand All @@ -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 })

Expand All @@ -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 })
Expand All @@ -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 })
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down