From 42e4d10c80d3ed800bbbce74cb06c0896d7ec1f0 Mon Sep 17 00:00:00 2001 From: 2584433 Date: Mon, 6 Oct 2025 08:00:59 +0000 Subject: [PATCH 1/2] style: added automatic hooks --- .githooks/commit-msg | 17 +++++++++++++++++ .githooks/pre-commit | 18 ++++++++++++++++++ .githooks/prepare-commit-msg | 9 +++++++++ README.md | 9 +++++++++ src/App.tsx | 2 +- 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100755 .githooks/commit-msg create mode 100755 .githooks/pre-commit create mode 100755 .githooks/prepare-commit-msg diff --git a/.githooks/commit-msg b/.githooks/commit-msg new file mode 100755 index 0000000..dd14401 --- /dev/null +++ b/.githooks/commit-msg @@ -0,0 +1,17 @@ +#!/bin/sh + +commit_msg_file=$1 +commit_msg=$(cat "$commit_msg_file") + +if echo "$commit_msg" | grep -Eq "^(feat|fix|refactor|perf|style|test|docs|build|chore|revert): .+"; then + if echo "$commit_msg" | grep -Eq "^(ref|close):\sN25B-.+"; then + echo "🎉 commit message is Valid" + exit 0 + else + echo "❌ Commit message invalid! Must end with [ref/close]: N25B-000" + exit 1 + fi +else + echo "❌ Commit message invalid! Must start with : " + exit 1 +fi \ No newline at end of file diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..391d279 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,18 @@ +#!/bin/sh + +# Get current branch +branch=$(git rev-parse --abbrev-ref HEAD) + +if echo "$branch" | grep -Eq "(dev|main)"; then + echo 0 +fi + +# allowed pattern +if echo "$branch" | grep -Eq "^(feat|fix|refactor|perf|style|test|docs|build|chore|revert)\/\w+-\w+-\w+"; then + echo "✅ Branch name valid: $branch" + exit 0 +else + echo "❌ Invalid branch name: $branch" + echo "Branch must be named / (must have 2 stipes - -)" + exit 1 +fi \ No newline at end of file diff --git a/.githooks/prepare-commit-msg b/.githooks/prepare-commit-msg new file mode 100755 index 0000000..5b706c1 --- /dev/null +++ b/.githooks/prepare-commit-msg @@ -0,0 +1,9 @@ +#!/bin/sh + +echo "#: + +#[optional body] + +#[optional footer(s)] + +#[ref/close]: " > $1 \ No newline at end of file diff --git a/README.md b/README.md index 18905eb..14ab2a9 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,12 @@ npm run dev ``` It should automatically reload when you save changes. + +## GitHooks + +To activate automatic commits/branch name checks in Windows run: + +```shell +git config core.hooksPath .githooks +``` + diff --git a/src/App.tsx b/src/App.tsx index fe7cb61..80f6643 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -13,4 +13,4 @@ function App(){ ) } -export default App +export default App \ No newline at end of file From a9f0a8dabd3cf7b6d536eadfc53ad7ee206190c5 Mon Sep 17 00:00:00 2001 From: 2584433 Date: Tue, 7 Oct 2025 14:38:31 +0000 Subject: [PATCH 2/2] readme change --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 14ab2a9..6e97243 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,14 @@ It should automatically reload when you save changes. ## GitHooks -To activate automatic commits/branch name checks in Windows run: +To activate automatic commits/branch name checks run: ```shell -git config core.hooksPath .githooks +git config --local core.hooksPath .githooks ``` +If your commit fails its either: +branch name != /description-of-branch +commit name != : description of the commit. + : N25B-Num's +