如果提交格式不正确,是否可以拒绝 Github 上的提交?

Bob*_*ijt 7 git github webhooks

正如这个答案中提到的,可以在 Github 提交中引用一个问题。

是否可以拒绝提交不是这样格式化的?

示例:
fix gh-12 foo bar正确
foo bar就会错误

更新:

快到了,这仍然不起作用......有什么想法吗?

我现在有以下内容: .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
Run Code Online (Sandbox Code Playgroud)

ras*_*ani 4

Python 版本可能如下所示:

#!/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)
Run Code Online (Sandbox Code Playgroud)

通常它的第一行应该与预定义的格式匹配,但这只是我个人的意见。