git 为何时接受拉取请求并合并到 master 创建一个 GitHub webhook

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26914819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:33:13  来源:igfitidea点击:

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

gitgithubpull-requestwebhooksgithub-enterprise

提问by brentonstrine

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

我有一个 webhook 目前可以触发push到任何分支。这会过于频繁地触发 webhook。理想情况下,webhook 只会在拉取请求合并master. 不过,我不认为这是一种选择:

enter image description here

在此处输入图片说明

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

有没有办法获得额外的 webhook 选项或以某种方式自定义 webhook?

回答by pmn

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.

因此,您无法自定义触发器的条件,但正如 LeGec 所提到的,您可以自定义代码以仅在合并拉取请求时触发。

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

为此,请确保您的脚本响应PullRequestEvent。测试条件是:

  • "action" is "closed"
  • "merged" (inside of "pull_request") is true
  • “动作”是“关闭
  • “合并”(在“pull_request”内)为

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

这样,当拉取请求上发生任何其他活动(包括关闭而不合并)时,您的脚本可以忽略它收到的所有 ping。

回答by LeGEC

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)
  • payload.ref == "refs/head/master"
  • payload.commits[0] matches the structure of a merged pull request(<- 这可能需要从提交 API 中获取一些额外信息)