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

标签 git github webhooks

this 中所述回答,可以在 Github 提交中引用问题。

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

例子:
修复 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

最佳答案

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)

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

关于git - 如果提交格式不正确,是否可以拒绝 Github 上的提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39764942/

相关文章:

ruby-on-rails - Stripe webhooks : Is there a way to fire the event : customer. source.expiring in test mode?

git - 如何使用不同的电子邮件管理git中的多个项目?

git - 在 git 中重命名 Remote 是否安全?

eclipse - Eclipse中 "Push..."和 "Push to upstream..."有什么区别

webhooks - IFTTT Webhooks - 没有收到电子邮件(但回复说它已发送)

android - Neura 中的事件标识符是什么?

git - 我的工作树是干净的,但 'git pull' 表示有本地文件将被覆盖

windows - 使用 Github for Windows 通过 SSH 使用自己的私有(private) Git

ios - OAuth 2.0 ios 快速实现

ios - 修改 iOS Cordova/PhoneGap 应用程序上的用户代理字符串