Created
July 5, 2023 04:36
-
-
Save tricantivu/589b7f5d92c1098abe9f0267a2f02482 to your computer and use it in GitHub Desktop.
My commit-msg hook
This file contains hidden or 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
#!/usr/bin/env bash | |
readonly MAX_SUBJ_LINE_LEN=75 | |
readonly MAX_BODY_LINE_LEN=72 | |
read -r subject < "$1" | |
if [[ "${subject}" =~ ^Revert ]]; then | |
# Skip checking commit message generated by git-revert(1) | |
exit 0 | |
else | |
# Verify Conventional Commits Specification compliance | |
[[ "${subject}" =~ ^(ci|rm|fix|feat|docs|test|perf|build|chore|style|refactor)\(?.*\)?:' '.+$ ]] || { | |
echo 'Bad message subject' >&2 | |
exit 1 | |
} | |
(( "${#subject}" > MAX_SUBJ_LINE_LEN )) && { | |
echo "Message subject exceeds ${MAX_SUBJ_LINE_LEN} characters" >&2 | |
exit 1 | |
} | |
fi | |
l=1 | |
while read -r line; do | |
[[ "${line}" == "${subject}" ]] && { | |
(( l++ )) | |
continue | |
} | |
(( "${#line}" )) || { | |
(( l++ )) | |
continue | |
} | |
[[ "${line}" =~ ^# ]] && continue | |
(( "${#line}" > MAX_BODY_LINE_LEN )) && { | |
echo "Message line ${l} exceeds ${MAX_BODY_LINE_LEN} characters" | |
exit 1 | |
} | |
done < "$1" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment