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

Commit eaba166

Browse files
authored
Merge pull request #107 from NuclearNic/expose-branch-commit-hash
populate file with latest commit hash of PR branch
2 parents 75f409a + 37d1cd7 commit eaba166

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ git config --get pullrequest.userlogin # returns the github user login for the
128128

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

131+
* `.git/head_sha`: the latest commit hash of the branch associated with the pull request
132+
131133
#### Parameters
132134

133135
* `git.depth`: *Optional.* If a positive integer is given, *shallow* clone the

assets/lib/commands/in.rb

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def output
3131
echo "#{pr['head']['ref']}" > branch
3232
echo "#{pr['base']['ref']}" > base_branch
3333
echo "#{pr['base']['user']['login']}" > userlogin
34+
echo "#{pr['head']['sha']}" > head_sha
3435
BASH
3536
end
3637

spec/commands/in_spec.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def dest_dir
5252
end
5353

5454
before(:all) do
55-
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' } })
55+
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' } })
5656
@output = get('version' => { 'ref' => @ref, 'pr' => '1' }, 'source' => { 'uri' => git_uri, 'repo' => 'jtarchie/test' })
5757
end
5858

@@ -113,6 +113,11 @@ def dest_dir
113113
expect(value).to eq 'master'
114114
end
115115

116+
it 'creates a file that includes the hash of the branch in the .git folder' do
117+
value = File.read(File.join(dest_dir,'.git','head_sha')).strip()
118+
expect(value).to eq 'hash'
119+
end
120+
116121
end
117122

118123
context 'when the git clone fails' do

0 commit comments

Comments
 (0)