I am trying to protect my github repo from some specific pushes (e.g. pushes with conflict markers like <<<<<
).
At first, I tried to write a pre-commit git hook to block those specific commits. Then realized github repositories doesn't accept pre-commit hooks and I have to install them on client side for every contributor.
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. They can notify via payloads during pushes on the repository.
Is it possible to examine and block pushesh through webhooks?
Github does not support placing server side hooks so you cannot run validations on remote repositories there. 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. People push their changes to this intermediate repository that validates them via hooks and pushes the same changes to the github repository. 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With