GitHub WebHooks在全球范围内触发,而不是按每个分支触发 [英] GitHub WebHooks triggered globally instead of per branch

查看:259
本文介绍了GitHub WebHooks在全球范围内触发,而不是按每个分支触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的产品在GitHub上创建WebHooks.每个客户项目一个.

Our product creates WebHooks at GitHub. One for each customer project.

每个这样的项目都链接到一个分支.

Each such project, is linked to a single branch.

执行到GitHub的push时,将触发相应的WebHook,这反过来又向我们这一端的端点发出请求以执行特定操作.

When a push to GitHub is performed, the corresponding WebHook is triggered, which in its turn, is making a request to an endpoint on our side to perform a certain action.

一种常见的情况是,客户将有多个项目,这些项目连接到同一存储库的多个不同分支.因此,几个不同的WebHooks连接到同一个存储库.

A common scenario is that a customer would have several projects, connected to several different branches of the same repository. Hence, several different WebHooks are connected to the same repository.

问题在于,当对分支之一执行push时,GitHub会触发所有与存储库相关的WebHooks.

The problem is that when a push is performed to one of the branches, GitHub triggers all repository related WebHooks.

我们希望当推送到某个分支时,只会触发一个对应的WebHook.

We would expect that when a push is made to a certain branch, only a single corresponding WebHook would be triggered.

我发现有两个帖子(其中一个来自2012年)似乎与这个问题有关:

I found two posts (one of them is from 2012) that seem to refer to this problem:

  • Web Hooks - execute only for specified branches
  • Ability to select a specific branch in webhook

一种可能的解决方案是解析在webhook请求中发送的ref参数,并控制何时采取相应的措施(尚未检查该方向,希望ref确实一直存在并保持正确的分支路径/姓名).但这将为时已晚"-因为所有WebHook都将在那时被触发...

A possible solution would be to parse the ref parameter sent inside the webhook request and control when to take action accordingly (haven't checked that direction yet, and hope ref indeed always exists and holds the right branch path/name). But that will be "too late" - cause all WebHooks will have been triggered by then...

但是,似乎GitHub无法以某种方式配置此行为似乎是不合理的.

But seems unreasonable that GitHub wouldn't have a way to configure this behavior somehow.

我们将不胜感激.

推荐答案

我已经获得了GitHub支持.

I've reached out GitHub support.

我希望这篇文章对其他人有帮助,因为他们误解了WebHooks与存储库/分支之间的关系.

I hope this post would help others, who misunderstand the relation between WebHooks and repositories / branches.

这是他们的答案:

您观察到的行为是预期的,没有计划进行更改 在不久的将来.

The behavior you observed is expected and there are no plans to change it in the near future.

在存储库上创建Webhook并将其订阅到推送时 事件-当任何分支或标签被推入时,webhook将触发, 如此处记录:

When you create a webhook on a repository and subscribe it to the push event -- the webhook will trigger when any branch or tag is pushed to, as documented here:

https://developer.github.com/v3/activity/events /types/#pushevent

没有分支机构的网络钩子.

There are no per-branch webhooks.

因此,与其创建在推送事件中订阅的多个Webhooks,不如 在同一存储库上,您应该只创建一个,然后检查哪个 分支已从您收到的有效负载中推送到(如您所注意到的, 分支的名称是通过有效负载中的ref字段传递的.

So, instead of creating multiple webhooks subscribed on the push event on the same repository, you should create only one, and check which branch was pushed to from the payload you receive (as you noticed, the name of the branch is passed via the ref field in the payload).

这个答案使我们意识到我们的想法是错误的.

This answer made us realize our conception was wrong.

分支未映射到Webhooks. 每个WebHook都链接到一个存储库,当对分支进行提交时,该分支在WebHook Web请求内的ref属性中声明,如下所示:

Branches are not mapped to webhooks. Each WebHook is linked to a repository, and when a commit to a branch is made, the branch is stated inside the ref attribute inside the WebHook web request, like this:

 {
  "ref": "refs/heads/branch_name",
  ...

要注意的另一件事是,GitHub限制了每个存储库事件要创建的WebHook的数量:

Another thing to note is that GitHub limits the number of WebHooks to be created per Repository-Event:

每个安装中的每个事件最多可以创建20个Webhooks 目标(特定组织或特定存储库).

You can create up to 20 webhooks for each event on each installation target (specific organization or specific repository).

它是从这里取来的:

https://developer.github.com/webhooks/

在这种情况下很重要,这会导致为push事件的每个分支创建一个WebHook,使我们达到20个WebHooks的限制,从而在尝试创建其他WebHooks时导致错误.

That's important in this context, cause the creation of a WebHook per branch for the push event, made us reach that limit of 20 WebHooks, thus causing errors when trying to create additional WebHooks.

将每个存储库保留在一个WebHook上将消除该问题.

Keeping it at one WebHook per repository would eliminate that problem.

这篇关于GitHub WebHooks在全球范围内触发,而不是按每个分支触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆