style: added automatic hooks

This commit is contained in:
2584433
2025-10-06 08:00:59 +00:00
committed by Kasper Marinus
parent 83e9f28573
commit 42e4d10c80
5 changed files with 54 additions and 1 deletions

17
.githooks/commit-msg Executable file
View File

@@ -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 <type>: <description>"
exit 1
fi

18
.githooks/pre-commit Executable file
View File

@@ -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 <type/>
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 <type>/<description-of-branch> (must have 2 stipes - -)"
exit 1
fi

9
.githooks/prepare-commit-msg Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/sh
echo "#<type>: <description>
#[optional body]
#[optional footer(s)]
#[ref/close]: <issue identifier>" > $1

View File

@@ -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
```

View File

@@ -13,4 +13,4 @@ function App(){
)
}
export default App
export default App