Jacob
Jacob

Reputation: 689

Using GitHub API to determine if the last commit to master was a result of a merged pull request?

We use GitHub flow as branching strategy which means that anything in master is the result of a merged pull request. It's trivial to get the last commit by doing the following.

GET https://api.github.com/repos/:org/:repo/git/refs/heads/master

However it seems non-trivial to work out the pull request that caused this commit.

Is it possible to find out the pull request that created this commit via the API?

Upvotes: 4

Views: 2016

Answers (1)

VonC
VonC

Reputation: 1323953

The PR should be one of the parents—the second one—of the commit in master, since that commit is the result of a merge of the PR.

You can find that parent with the GitHub commit API

GET /repos/:owner/:repo/git/commits/:sha

GitHub doesn't offer a way to get the branch from a commit, but you could list all the PR and cross-reference the SHA1 found above with said PRs.

Upvotes: 1

Related Questions