在github上提交消息钩子 [英] Commit message hook on github
问题描述
我正在尝试在github中设置一个预先接收的钩子,这是我在STASH上使用的钩子。在STASH中,我有一个预接收钩子,用于强制执行自定义提交消息,该消息中应包含JIRA编号。
现在,我正在尝试了解在github上执行类似操作的最佳方式。如果我将它分解,那将是:
- 需要自定义提交消息。
- 每个承诺应该包括现有的JIRA。
-
-
- 例如:TEST-1添加第一次提交消息。
这里有人能帮助我吗?这怎么办?
解决方案仅GitHub 提供webhooks ,它允许您收听并响应某些事件,包括推送。
但是,这只允许你对推送作出反应(就像后接收挂钩一样),而不是阻止它。
你可以为这个推送事件建立一个监听器:
- 检查刚刚推送的最新提交
- 重置为
HEAD〜1
如果提交不符合预期的策略(push --force
)
但是,对于最初推送该提交的用户来说,这会非常棘手,从GitHub回购。
更好的解决方案是在服务器上设置一个裸回购, - 接收钩:如果提交通过,然后post-receive钩子将它推到预期的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 ?
解决方案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.
这篇关于在github上提交消息钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!