预提交钩子以检查 Jira 问题密钥

Hel*_*red 9 svn windows pre-commit-hook

我正在寻找一些帮助来在 Windows 上编写一个预提交钩子以在提交时检查 Jira 问题密钥。如果 Jira 密钥不存在,则不允许提交。我找不到任何方法。我是脚本的新手。任何帮助都会受到高度赞赏。

Mr.*_*. T 9

我假设您正在谈论 Git 存储库中的钩子。

  • 导航到本地 Git 存储库并进入文件夹 .git\hooks
  • 创建一个名为 commit-msg 的文件
  • 插入以下内容(不知道如何正确格式化)
#!/bin/bash
# The script below adds the branch name automatically to
# every one of your commit messages. The regular expression
# below searches for JIRA issue key's. The issue key will
# be extracted out of your branch name

REGEX_ISSUE_ID="[a-zA-Z0-9,\.\_\-]+-[0-9]+"

# Find current branch name
BRANCH_NAME=$(git symbolic-ref --short HEAD)

if [[ -z "$BRANCH_NAME" ]]; then
    echo "No branch name... "; exit 1
fi

# Extract issue id from branch name
ISSUE_ID=$(echo "$BRANCH_NAME" | grep -o -E "$REGEX_ISSUE_ID")

echo "$ISSUE_ID"': '$(cat "$1") > "$1"
Run Code Online (Sandbox Code Playgroud)

如果您现在有一个名为 feature/MYKEY-1234-That-a-branch-name 的分支并添加为提交消息“添加新功能”,您的最终提交消息将如下所示 MYKEY-1234: Add a new feature

使用 Git 2.9 时,您可以全局放置钩子。请在此处找到更多有用的信息:

https://andy-carter.com/blog/automating-git-commit-messages-with-git-hooks

Git hooks:应用`git config core.hooksPath`