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

Fix unexpected fetch_merge plus out status interactions #197

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion assets/lib/commands/out.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ def output
version = { 'ref' => sha }
else
pr = PullRequest.from_github(repo: repo, id: id)
if sha == pr.merge_commit_sha
# If the SHA that we have here is the merge commit's SHA,
# we know that the correct SHA is the one at the tip of
# the PR (which might be the same as the merge SHA if
# there's no need for a merge).
sha = pr.sha
end
metadata << { 'name' => 'url', 'value' => pr.url }
version = { 'pr' => id, 'ref' => sha }
end
Expand Down Expand Up @@ -77,7 +84,7 @@ def output
File.read(commit_path, encoding: Encoding::UTF_8)
else
''
end
end
Octokit.merge_pull_request(input.source.repo, id, commit_msg, merge_method: params.merge.method, accept: 'application/vnd.github.polaris-preview+json')
metadata << { 'name' => 'merge', 'value' => params.merge.method }
metadata << { 'name' => 'merge_commit_msg', 'value' => commit_msg }
Expand Down
4 changes: 4 additions & 0 deletions assets/lib/pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def sha
@pr['head']['sha']
end

def merge_commit_sha
@pr['merge_commit_sha']
end

def url
@pr['html_url']
end
Expand Down
17 changes: 17 additions & 0 deletions spec/commands/out_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,23 @@ def stub_json(method, uri, body)
{ 'name' => 'url', 'value' => 'http://example.com' }
])
end
context 'when fetching a merged commit' do
it 'posts the status to the PR\'s SHA instead of the merge SHA.' do
stub_json(:get, 'https://api.github.com:443/repos/jtarchie/test/pulls/1',
html_url: 'http://example.com',
number: 1,
head: { sha: 'abcdef' },
merge_commit_sha: @sha)
stub_request(:post, 'https://api.github.com:443/repos/jtarchie/test/statuses/abcdef')
output, = put('params' => { 'status' => 'failure', 'path' => 'resource' }, 'source' => { 'repo' => 'jtarchie/test' })
expect(output).to eq('version' => { 'ref' => 'abcdef', 'pr' => '1' },
'metadata' => [
{ 'name' => 'status', 'value' => 'failure' },
{ 'name' => 'url', 'value' => 'http://example.com' }
])

end
end
end
end
end
Expand Down