From dbd4c0e20db9d9698030dfc62e5a322cc021bcb7 Mon Sep 17 00:00:00 2001 From: NuclearNic Date: Wed, 13 Sep 2017 11:34:36 +0200 Subject: [PATCH 1/2] populate file with latest commit hash of PR branch --- README.md | 2 ++ assets/lib/commands/in.rb | 1 + spec/commands/in_spec.rb | 7 ++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 33842a9..8e1c6ff 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/branch_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..b066a39 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']}" > branch_sha BASH end diff --git a/spec/commands/in_spec.rb b/spec/commands/in_spec.rb index 314993d..5cd535b 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','branch_sha')).strip() + expect(value).to eq 'hash' + end + end context 'when the git clone fails' do From 37d1cd779bceca85bdeaf1b33bf55797ef23058c Mon Sep 17 00:00:00 2001 From: NuclearNic Date: Fri, 15 Sep 2017 09:27:54 +0200 Subject: [PATCH 2/2] populate file head_sha instead of branch_sha --- README.md | 2 +- assets/lib/commands/in.rb | 2 +- spec/commands/in_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8e1c6ff..6f8bbfa 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ git config --get pullrequest.userlogin # returns the github user login for the * `.git/user_login`: the user login of the pull request author - * `.git/branch_sha`: the latest commit hash of the branch associated with the pull request + * `.git/head_sha`: the latest commit hash of the branch associated with the pull request #### Parameters diff --git a/assets/lib/commands/in.rb b/assets/lib/commands/in.rb index b066a39..ac8ffea 100755 --- a/assets/lib/commands/in.rb +++ b/assets/lib/commands/in.rb @@ -31,7 +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']}" > branch_sha + echo "#{pr['head']['sha']}" > head_sha BASH end diff --git a/spec/commands/in_spec.rb b/spec/commands/in_spec.rb index 5cd535b..960c999 100644 --- a/spec/commands/in_spec.rb +++ b/spec/commands/in_spec.rb @@ -114,7 +114,7 @@ def dest_dir 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','branch_sha')).strip() + value = File.read(File.join(dest_dir,'.git','head_sha')).strip() expect(value).to eq 'hash' end