ci: track conventional commits commit-msg hook

This commit is contained in:
2026-07-28 18:52:49 +02:00
parent b79bd2eb1e
commit 3e90d65b44
2 changed files with 39 additions and 0 deletions

35
.githooks/commit-msg Executable file
View File

@ -0,0 +1,35 @@
#!/bin/sh -euC
#
# Reject commit messages that do not conform to Conventional Commits.
#
# Enforces Conventional Commits v1.0.0 at the syntactic level.
# Also enforces a custom list of types.
#
# Upstream: gitea.bp99.eu/bp99/git-hooks
# Updated: 2026-07-28
types='feat|fix|build|chore|ci|docs|style|refactor|test|perf|merge|revert'
subject="$(sed -n 1p "$1")"
second="$(sed -n 2p "$1")"
fail() {
>&2 cat <<EOF
commit-msg: $1
subject: $subject
format: <type>[(<scope>)][!]: <description>
types: $types
Bypass with: git commit --no-verify
EOF
exit 1
}
# type, optional (scope), optional !, terminal ': ', non-emtpy desc
printf '%s' "$subject" | grep -Eq "^($types)(\([^()]+\))?!?: .+" \
|| fail 'subject does not conform to Conventional Commits'
# Body must begin one blank line after description
[ -z "$second" ] || fail 'Line 2 must be blank'

4
Makefile Normal file
View File

@ -0,0 +1,4 @@
setup:
git config core.hooksPath .githooks
.PHONY: setup