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

GitGithubPull RequestWebhooksGithub Enterprise

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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).

Solution 2 - Git

I don't see any way to customize the conditions of the trigger.

I would suggest to rather write code on the receiving end to trigger your action only when you detect that the push fits your conditions, e.g :

  • payload.ref == "refs/head/master"
  • payload.commits[0] matches the structure of a merged pull request (<- this may require getting some extra info from the commits API)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbrentonstrineView Question on Stackoverflow
Solution 1 - GitpmnView Answer on Stackoverflow
Solution 2 - GitLeGECView Answer on Stackoverflow