diff --git a/README.md b/README.md index 33842a9..6f8bbfa 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/assets/lib/commands/in.rb b/assets/lib/commands/in.rb index 26eadab..ac8ffea 100755 --- a/assets/lib/commands/in.rb +++ b/assets/lib/commands/in.rb @@ -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 diff --git a/spec/commands/in_spec.rb b/spec/commands/in_spec.rb index 314993d..960c999 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', 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 @@ -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