gpt4 book ai didi

windows - 预提交 Hook 以检查 Jira 问题 key

转载 作者:可可西里 更新时间:2023-11-01 09:22:50 25 4
gpt4 key购买 nike

我正在寻找帮助在 Windows 上编写预提交 Hook 以在提交时检查 Jira 问题 key 。如果 Jira key 不存在,则不应允许提交。我找不到任何方法。我是脚本编写的新手。任何帮助将不胜感激。

最佳答案

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

  • 导航到您的本地 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"

如果您现在有一个名为 feature/MYKEY-1234-That-a-branch-name 的分支并添加为提交消息“添加新功能”你的最终提交信息看起来像MYKEY-1234:添加新功能

使用 Git 2.9 时,您可以全局放置钩子(Hook)。请在这里找到更多有用的信息:

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

Git hooks : applying `git config core.hooksPath`

关于windows - 预提交 Hook 以检查 Jira 问题 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48170832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com