Search code examples
githubgithub-api

GitHub API: Does a webhook fire on a pull request approval event?


I need the ability to kick-off a process via a webhook whenever a pull request review is marked 'approved'. I know there's a way to query a pull request via the API to determine state, number of approvals, etc., but that doesn't help. I am looking for a way to invoke a process as soon as, and every time, someone approves a request. It doesn't appear this particular event triggers a webhook though. Is that correct? Is there a way to accomplish this otherwise?

Thank you in advance!


Solution

  • For your use-case, there is an option on GitHub to send Webhook events on Pull request reviews.

    On a GitHub repo, if you go to Settings -> Webhooks -> Add a webhook, and over there select the option shown below

    enter image description here

    You can select the webhook to be triggered on Pull request reviews as below

    enter image description here

    Once you have the webhook set up, whenever a pull request review is submitted, edited or dismissed, a PullRequestReviewEvent is triggered (sample webhook payload in the web-link provided), and the webhook payload will have the state of the review. In case the review is approved, the state value would be approved as shown in the payload snapshot below.

    enter image description here

    You can then have the logic of triggering any event/process based on the state value in the webhook payload.