Last active
September 1, 2022 01:25
-
-
Save scott0228/0b494026faaf505ebd71f80b7d186456 to your computer and use it in GitHub Desktop.
git commit 檢查是否有包含 jira issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
HOOK_FILE=$1 | |
COMMIT_MSG=`head -n1 $HOOK_FILE` | |
PATTERN="([A-Z]+-[0-9]+)|(Merge branch)" | |
if [[ ! ${COMMIT_MSG} =~ $PATTERN ]]; then | |
echo "" | |
echo "'$COMMIT_MSG' is missing JIRA Ticket Number." | |
echo " example: 'JIRA-1234: my commit'" | |
echo "" | |
exit 1 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
zero_commit='0000000000000000000000000000000000000000' | |
msg_regex="([A-Z]+-[0-9]+)|(Merge branch)" | |
while read -r oldrev newrev refname; do | |
# Branch or tag got deleted, ignore the push | |
[ "$newrev" = "$zero_commit" ] && continue | |
# Calculate range for new branch/updated branch | |
[ "$oldrev" = "$zero_commit" ] && range="$newrev" || range="$oldrev..$newrev" | |
for commit in $(git rev-list "$range" --not --all); do | |
if ! git log --max-count=1 --format=%B $commit | grep -iqE "$msg_regex"; then | |
echo "ERROR:" | |
echo "ERROR: 你的推送被退回,因為 commit $commit" | |
echo "ERROR: 在 ${refname#refs/heads/} 缺少了 JIRA Issue" | |
echo "ERROR:" | |
echo "ERROR: 請參依以下連結來修正commit message 然後再重新推送。" | |
echo "ERROR: https://help.github.com/en/articles/changing-a-commit-message" | |
echo "ERROR" | |
exit 1 | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/a/71593942
https://github.com/github/platform-samples/blob/master/pre-receive-hooks/require-jira-issue.sh
https://medium.com/@trivedevops/commit-strategy-implementation-with-gitlab-pre-receive-hook-and-jira-for-project-management-3720d44d4b5e