Skip to content

Instantly share code, notes, and snippets.

@scott0228
Last active September 1, 2022 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scott0228/0b494026faaf505ebd71f80b7d186456 to your computer and use it in GitHub Desktop.
Save scott0228/0b494026faaf505ebd71f80b7d186456 to your computer and use it in GitHub Desktop.
git commit 檢查是否有包含 jira issue
#!/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
#!/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