From e708043bbab331196baa4fb90619417811b3c0fe Mon Sep 17 00:00:00 2001 From: sohitkumar Date: Mon, 7 Oct 2024 18:06:25 +0530 Subject: [PATCH] chore(DEV-106): added git hooks and setup.sh script. --- hooks/commit-msg | 20 ++++++++++++++++++++ setup.sh | 6 ++++++ 2 files changed, 26 insertions(+) create mode 100755 hooks/commit-msg create mode 100755 setup.sh diff --git a/hooks/commit-msg b/hooks/commit-msg new file mode 100755 index 00000000..a58c2666 --- /dev/null +++ b/hooks/commit-msg @@ -0,0 +1,20 @@ +#!/bin/bash + +# Retrieve the commit message from the file specified as the first argument +commit_msg=$(cat "$1") +echo "Commit message: '$commit_msg'" + +# Define a regular expression for the commit message format +commit_regex="^(feat|fix|chore|refactor|docs|test|style|ci|perf|build)\([A-Z]+-[0-9]+\): .+" + +# Check if the commit message matches the required format +if [[ ! "$commit_msg" =~ $commit_regex ]]; then + echo "Error: Invalid commit message format." + echo "Your commit message must follow the format: TYPE(PROJECT-123): description." + echo "Valid types: feat, fix, chore, refactor, docs, test, style, ci, perf, build" + echo "Example: feat(PROJECT-123): add authentication module" + exit 1 +fi + +# If the commit message matches, allow the commit +exit 0 diff --git a/setup.sh b/setup.sh new file mode 100755 index 00000000..3128d90f --- /dev/null +++ b/setup.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Set up the custom Git hooks directory +git config core.hooksPath ./hooks + +echo "Git hooks directory set to ./hooks" \ No newline at end of file