如果提交格式不正确,是否可以拒绝 Github 上的提交? [英] Is it possible to reject a commit on Github if the commit isn't formatted correctly?
本文介绍了如果提交格式不正确,是否可以拒绝 Github 上的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如这个答案中所述,可以在 Github 提交中引用问题.
As mentioned in this answer, it is possible to reference an issue in a Github commit.
是否可以拒绝其不是格式的提交?
Is it possible to reject a commit of it is not formatted like this?
示例:fix gh-12 foo bar
是正确的foo bar
会出错
Example:
fix gh-12 foo bar
is correct
foo bar
would be wrong
更新:
快到了,这仍然不起作用......有什么想法吗?
Almost there, this still isn't working... Any thoughts?
我现在有以下内容:.git/hooks/commit-msg
#!/bin/bash
commit_regex='(gh-[0-9]+|merge)'
error_msg="Aborting commit. Your commit message is missing either a Github Issue ('gh-1111') or 'Merge'."
if ! grep -E "$commit_regex" <<< "$0"; then
echo "$error_msg" >&2
exit 1
fi
推荐答案
Python 版本可能如下所示:
Python version could look something like this:
#!/usr/bin/python
import sys
import re
ret = 1
try:
with open(sys.argv[1]) as msg:
res = re.match("^fix gh-[0-9]+.*$", msg.readline())
if res != None:
ret = 0
except:
pass
if (ret != 0):
print("error_msg_goeth_here")
sys.exit(ret)
通常它的第一行应该与预定义的格式匹配,但这只是我个人的意见.
Typically its the first row that should match the pre-defined format but thats only my personal opinion.
这篇关于如果提交格式不正确,是否可以拒绝 Github 上的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文