I am trying to setup a pre-receive hook in github that I used to use on STASH. In STASH, I had a pre-receive hook that used to enforce "A custom commit message that should have a JIRA number included in it".
Now, I am trying to understand what would be the best way to do something similar on github. If I split it up, it would be:
Eg: TEST-1 Adding the first commit message.
Can anybody here help me, how can this be done ?
GitHub only offers webhooks, which allows you to listen to and react to certain events, including the push.
But that only allows you to react to a push (like a post-receive hook would), not to prevent it.
You could build a listener to that push event which would:
HEAD~1
if the commit doesn't follow the expected policy (push --force
)But that would be tricky for the user who initially pushed that commit to realize that said commit just disappeared from the GitHub repo.
A better solution would be to setup a bare repo in a server where you could setup that pre-receive hook: if that commit passes, then a post-receive hook would push it to the intended GitHub repo.
But depending on your team, it might be difficult to setup a repo which is accessible by everyone.
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