Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commit message hook on github

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:

  • Requiring a custom commit message.
  • Every commit should include an existing JIRA.
  • Enforce this on any pull request as well.

Eg: TEST-1 Adding the first commit message.

Can anybody here help me, how can this be done ?

like image 602
Jason Avatar asked Oct 31 '22 11:10

Jason


1 Answers

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:

  • examine the latest commit just pushed
  • reset to 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.

like image 106
VonC Avatar answered Nov 09 '22 06:11

VonC