portfolio/scripts/commit-msg-check.sh
christiangoeschel d6b2a3e6d9
All checks were successful
Pull Request Checks / commit-message-check (pull_request) Successful in 6s
Pull Request Checks / linting (pull_request) Successful in 1m58s
feat: Add a CI pipeline and fix all code style issues
2025-02-27 00:08:41 -05:00

26 lines
949 B
Bash
Executable File

#!/usr/bin/bash
# This hook helps to enforce a commit message format convention
#
# It can be very frustrating when many commits are squashed for a final PR
# and the latter gets rejected due to incorrect commit message formatting
#
# Another reason for this enforcement is to provide valid input data for the
# automatic changelog generator which relies on the keywords found in the regex below
function log {
# shellcheck disable=2317
printf "[ERROR] %s\n" "${@}"
}
commit_msg="${1}"
regex="^(bugfix|doc|docs|chore|feat|feature|fix|hotfix|perf|refactor|remove|security|style|test)(\([a-zA-Z0-9_-]+\))?!?:[[:space:]]+[[:graph:]]+([[:graph:]]|[[:space:]])*$"
echo "[INFO] Commit message: ${commit_msg}"
if ! [[ "${commit_msg}" =~ ${regex} ]]; then
log "Invalid commit message format please consult CONTRIBUTING for more details on how to write appropriate commit messages."
exit 1
else
echo "[SUCCESS] Valid commit message format!"
fi