GitHub WebHooks triggered globally instead of per branch

后端 未结 1 701
温柔的废话
温柔的废话 2020-12-29 07:47

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

Each such project, is linked to a single branch.

When a push to GitHub i

相关标签:
1条回答
  • 2020-12-29 08:03

    I've reached out GitHub support.

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

    Here's their answer:

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

    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.

    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.

    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",
      ...
    

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

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

    It was taken from here:

    https://developer.github.com/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.

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

    0 讨论(0)
提交回复
热议问题