Commit message hook on github

烂漫一生 提交于 2019-12-07 04:37:28

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/27893052/commit-message-hook-on-github

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!