Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to block specific pushes with github webhooks?

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?

like image 402
Bidhan Roy Avatar asked Sep 27 '22 19:09

Bidhan Roy


1 Answers

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

like image 133
Gaurav Tiwari Avatar answered Oct 06 '22 01:10

Gaurav Tiwari