Create a GitHub webhook for when a pull request is accepted & merged to master

brentonstrine picture brentonstrine · Nov 13, 2014 · Viewed 16k times · Source

I have a webhook that currently fires on push to any branch. This triggers the webhook far too frequently. Ideally, the webhook would only fire when a pull request is merged into master. I don't see that as an option, though:

enter image description here

Is there a way to get additional webhook options or to customize the webhook somehow?

Answer

pmn picture pmn · Jan 21, 2015

So, you can't customize the conditions of the trigger, but as LeGec mentions you can customize your code to only trigger when the Pull Request is merged.

To do that, make sure your script responds to the PullRequestEvent. The conditions to test are:

  • "action" is "closed"
  • "merged" (inside of "pull_request") is true

This way your script can ignore all the pings it receives when any other activity occurs on the Pull Request (including closing without merging).