Determining if "status" payload is for a pull request


#1

Given the payload of a status webhook (StatusEvent), is it possible to determine if the status is being set on a pull request? I want to be able to detect the case where a CI system is updating the status of a PR, without picking up commits that are not part of a PR (eg. committing directly to a branch).


#2

@Daniel15 I’m not 100% certain, but I don’t think this is possible using just the payload that is delivered. I think you would need to cache the names of branches with open pull requests and compare this to the list of branches that the StatusEvent sends back.

Another, more expensive, option would be to make a call for each of the branches in the status event payload by calling the List Pull Requests https://developer.github.com/v3/pulls/#list-pull-requests endpoint and filter by “base”.

Lastly, some CI systems have settings that will let you build only if there is an open pull request. Here’s the settings page on Travis CI, that lets you customize this:

That’s all I can think of. Others might have better tricks up their sleeve for you.