puppet-control-repo/scripts/commit-msg-check.sh
christiangoeschel b345768781
Some checks failed
Pull Request Checks / commit-message-check (pull_request) Successful in 4s
Pull Request Checks / linting (pull_request) Successful in 46s
Post PR Merge Action / integrate (push) Failing after 5s
feat(ci): Add commit message format and squash commit checks
2025-02-12 07:47:32 -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