简体   繁体   English

如何使用github webhooks阻止特定的推送?

[英]How to block specific pushes with github webhooks?

I am trying to protect my github repo from some specific pushes (eg pushes with conflict markers like <<<<< ). 我试图保护我的github repo免受某些特定推送(例如推送冲突标记,如<<<<< )。

At first, I tried to write a pre-commit git hook to block those specific commits. 起初,我尝试编写一个pre-commit git hook来阻止那些特定的提交。 Then realized github repositories doesn't accept pre-commit hooks and I have to install them on client side for every contributor. 然后实现github存储库不接受预提交挂钩,我必须在客户端为每个贡献者安装它们。

This is not a neat solution because someone might forget to install hooks after clone. 这不是一个简洁的解决方案,因为有人可能忘记在克隆后安装钩子。 It is also possible to override pre-commit hooks. 也可以覆盖预提交挂钩。

Then I learned about github webhooks . 然后我了解了github webhooks They can notify via payloads during pushes on the repository. 他们可以在推送存储库期间通过有效负载通知。

Is it possible to examine and block pushesh through webhooks? 是否有可能通过webhook检查和阻止推送?

Github does not support placing server side hooks so you cannot run validations on remote repositories there. Github不支持放置服务器端钩子,因此您无法在远程存储库上运行验证。 However it is technically possible as a hack where you can setup another intermediate staging repository with all these hooks you want which is sort of a writeable mirror before github. 但是在技术上可以作为一个hack,你可以在其中设置另一个中间登台存储库,其中包含你想要的所有这些钩子,这是github之前的一种可写镜像。 People push their changes to this intermediate repository that validates them via hooks and pushes the same changes to the github repository. 人们将他们的更改推送到这个中间存储库,通过钩子验证它们并将相同的更改推送到github存储库。 IMHO I will advise against adding such repository unless your developers break your stuff like this too often. 恕我直言我会建议不要添加这样的存储库,除非你的开发人员经常打破这样的东西。

On another note, if you go ahead with such implementation, use the update hook instead of pre-commit as it runs for each ref that is pushed 另一方面,如果你继续这样的实现,使用update钩子而不是pre-commit,因为它为每个被推送的ref运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM