From 566e7f132af0a87a44f82f53416f4f47dbda07f4 Mon Sep 17 00:00:00 2001 From: AUTIN Tristan Date: Wed, 7 Jan 2026 15:04:56 +0100 Subject: [PATCH] feat : Ajout d'un commit linter --- commit-msg | 31 +++++++++++++++++++++++++++++++ makefile | 2 ++ 2 files changed, 33 insertions(+) create mode 100644 commit-msg diff --git a/commit-msg b/commit-msg new file mode 100644 index 0000000..901d964 --- /dev/null +++ b/commit-msg @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -euo pipefail + +MSG_FILE="${1}" +FIRST_LINE="$(head -n 1 "$MSG_FILE" | tr -d '\r')" + +# Autoriser commits auto-générés par git +if [[ "$FIRST_LINE" =~ ^Merge\ ]]; then + exit 0 +fi + +# Types autorisés (MINUSCULES uniquement) +# Optionnel: scope => feat(auth) : ... +REGEX='^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z0-9._-]+\))?\ :\ .+' + +if [[ ! "$FIRST_LINE" =~ $REGEX ]]; then + echo "❌ Message de commit invalide." + echo "" + echo "➡️ Format attendu : () : " + echo "➡️ Types autorisés (minuscules uniquement) :" + echo " build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test" + echo "" + echo "✅ Exemples :" + echo " feat : add login page" + echo " fix(auth) : prevent null token crash" + echo " docs : update README" + echo "" + echo "❌ Exemple refusé :" + echo " Feat : add login page" + exit 1 +fi diff --git a/makefile b/makefile index 6ecf6d9..b22c4b2 100644 --- a/makefile +++ b/makefile @@ -87,7 +87,9 @@ cache-clear: copy-git-hook: $(EXEC_PHP) cp pre-commit .git/hooks/ + $(EXEC_PHP) cp commit-msg .git/hooks/ $(EXEC_PHP) chmod a+x .git/hooks/pre-commit + $(EXEC_PHP) chmod a+x .git/hooks/commit-msg shell: $(EXEC_PHP_INTERACTIVE) bash