Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get merge commit SHA for merged pull request?

There is a related question GET pull request merge commit sha from pull request number using github api, yet there is no answer.

According to GitHub API, once Pull Request was merged, it triggers the pull_request event with action: closed. The event is also available from Events API. However, there are only merged (which is true if the pull request was merged) and deprecated merge_commit_sha (SHA of temporary merge commit, not the actual commit by which pull request was merged) fields.

There is also API for dealing with pull requests; yet, according to the documentation, it also will only return whether pull request was merged, and what is the temporary commit SHA (in a deprecated field).

Pull request is clearly associated with the merge commit somehow, as commit SHA is shown on pull request page:

enter image description here

Is there some way to get programmatically SHA of the commit by which pull request was merged to the base, knowing the pull request ID?

like image 331
penartur Avatar asked Oct 29 '14 08:10

penartur


1 Answers

All pull requests are also issues. So you can fetch the Issue Events for any Pull Request. With that, there will be a commit_id. If that attribute is present with a merged attribute then that should be the SHA of the merge commit.

like image 130
Ian Stapleton Cordasco Avatar answered Sep 21 '22 12:09

Ian Stapleton Cordasco