Skip to content

Commit eefb9f9

Browse files
author
Tim Jones
authored
Merge pull request #6 from ndmckinley/status-and-fetch-merge
Status and fetch merge
2 parents dff56e2 + baefc46 commit eefb9f9

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

assets/lib/commands/out.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ def output
4141
version = { 'ref' => sha }
4242
else
4343
pr = PullRequest.from_github(repo: repo, id: id)
44+
if sha == pr.merge_commit_sha
45+
# If the SHA that we have here is the merge commit's SHA,
46+
# we know that the correct SHA is the one at the tip of
47+
# the PR (which might be the same as the merge SHA if
48+
# there's no need for a merge).
49+
sha = pr.sha
50+
end
4451
metadata << { 'name' => 'url', 'value' => pr.url }
4552
version = { 'pr' => id, 'ref' => sha }
4653
end
@@ -77,7 +84,7 @@ def output
7784
File.read(commit_path, encoding: Encoding::UTF_8)
7885
else
7986
''
80-
end
87+
end
8188
Octokit.merge_pull_request(input.source.repo, id, commit_msg, merge_method: params.merge.method, accept: 'application/vnd.github.polaris-preview+json')
8289
metadata << { 'name' => 'merge', 'value' => params.merge.method }
8390
metadata << { 'name' => 'merge_commit_msg', 'value' => commit_msg }

assets/lib/pull_request.rb

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def sha
4747
@pr['head']['sha']
4848
end
4949

50+
def merge_commit_sha
51+
@pr['merge_commit_sha']
52+
end
53+
5054
def url
5155
@pr['html_url']
5256
end

spec/commands/out_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,23 @@ def stub_json(method, uri, body)
303303
{ 'name' => 'url', 'value' => 'http://example.com' }
304304
])
305305
end
306+
context 'when fetching a merged commit' do
307+
it 'posts the status to the PR\'s SHA instead of the merge SHA.' do
308+
stub_json(:get, 'https://api.github.com:443/repos/jtarchie/test/pulls/1',
309+
html_url: 'http://example.com',
310+
number: 1,
311+
head: { sha: 'abcdef' },
312+
merge_commit_sha: @sha)
313+
stub_request(:post, 'https://api.github.com:443/repos/jtarchie/test/statuses/abcdef')
314+
output, = put('params' => { 'status' => 'failure', 'path' => 'resource' }, 'source' => { 'repo' => 'jtarchie/test' })
315+
expect(output).to eq('version' => { 'ref' => 'abcdef', 'pr' => '1' },
316+
'metadata' => [
317+
{ 'name' => 'status', 'value' => 'failure' },
318+
{ 'name' => 'url', 'value' => 'http://example.com' }
319+
])
320+
321+
end
322+
end
306323
end
307324
end
308325
end

0 commit comments

Comments
 (0)