portfolio/githooks/commit-msg
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

24 lines
945 B
Bash
Executable File

#!/usr/bin/env 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 "[$(tput setaf 1)$(tput bold)error$(tput sgr0)] %s\n" "${@}"
}
message_file="${1}"
message="$(head -n1 "${message_file}")"
regex="^(bugfix|doc|docs|chore|feat|feature|fix|hotfix|perf|refactor|remove|security|style|test)(\([a-zA-Z0-9_-]+\))?!?:[[:space:]]+[[:graph:]]+([[:graph:]]|[[:space:]])*$"
if ! [[ "${message}" =~ ${regex} ]]; then
log "Invalid commit message format please consult CONTRIBUTING for more details on how to write appropriate commit messages"
exit 1
fi