Humair
Humair

Reputation: 91

Github API Webhook/Notification for All checks passed on PR

I have an app that makes changes to a repo on a new branch and commits it to a repo, then creates a PR. The PR starts two builds - one for travis, and one for jenkins. I was wondering if there's a way I can receive a notification once all the checks have passed on the PR, so that my app can then merge the PR. Currently I only see a way on github to setup a status event that only notifies me when one of the statuses updates.

One way I could do this is to store this information somewhere as each bulid passes one by one, and merge when they all finish. However, I'd like to avoid having to store information somewhere as I'm hoping for an ephemeral implementation.

Another way I was thinking about doing it is: once a status event is received, I could parse the statuses_url for the head commit, and verify the state of the other builds. The problem I think with this is that the statuses_url displays all builds for this head and not necessarily the ones associated with the PR.

I was wondering if there is a way to receive a single notification once all checks have completed and report their status in tandem.

Upvotes: 4

Views: 1895

Answers (1)

jbarrieault
jbarrieault

Reputation: 464

You can accomplish this by setting up a webhook for the PR Status event that makes a call to the combined status endpoint to get the overall status of that particular sha. Then you could perform some action on any pull requests that have that sha as their head.

I recently implemented something like this to conditionally add/remove labels based on the PR status (here).

Upvotes: 2

Related Questions