Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #107 from NuclearNic/expose-branch-commit-hash
Browse files Browse the repository at this point in the history
populate file with latest commit hash of PR branch
  • Loading branch information
jtarchie committed Sep 17, 2017
2 parents 75f409a + 37d1cd7 commit eaba166
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ git config --get pullrequest.userlogin # returns the github user login for the

* `.git/user_login`: the user login of the pull request author

* `.git/head_sha`: the latest commit hash of the branch associated with the pull request

#### Parameters

* `git.depth`: *Optional.* If a positive integer is given, *shallow* clone the
Expand Down
1 change: 1 addition & 0 deletions assets/lib/commands/in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def output
echo "#{pr['head']['ref']}" > branch
echo "#{pr['base']['ref']}" > base_branch
echo "#{pr['base']['user']['login']}" > userlogin
echo "#{pr['head']['sha']}" > head_sha
BASH
end

Expand Down
7 changes: 6 additions & 1 deletion 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', user: { login: 'jtarchie' } })
stub_json('https://api.github.com:443/repos/jtarchie/test/pulls/1', html_url: 'http://example.com', number: 1, head: { ref: 'foo', sha: 'hash' }, 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 @@ -113,6 +113,11 @@ def dest_dir
expect(value).to eq 'master'
end

it 'creates a file that includes the hash of the branch in the .git folder' do
value = File.read(File.join(dest_dir,'.git','head_sha')).strip()
expect(value).to eq 'hash'
end

end

context 'when the git clone fails' do
Expand Down

0 comments on commit eaba166

Please sign in to comment.