Skip to content

Commit

Permalink
git hooks updated
Browse files Browse the repository at this point in the history
  • Loading branch information
cophilot committed Nov 30, 2023
1 parent 13aa675 commit dcdcd42
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
56 changes: 43 additions & 13 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
echo "🚨 Checking commit message..."
echo "Checking commit message..."
message="$(cat $1)"
requiredPattern="^(add|cut|fix|bump|make|start|stop|refactor|reformat|optimise|document|merge|configured) .*$"
if ! [[ $message =~ $requiredPattern ]];
then
echo "-"
echo "-"
echo "-"

#requiredPattern="^(add|cut|fix|bump|make|start|stop|refactor|reformat|optimise|document|merge|configured) .*$"
#if ! [[ $message =~ $requiredPattern ]];
#then
# echo "-"
# echo "-"
# echo "-"
# echo "🚨 Wrong commit message! πŸ˜•"
# echo "The commit message must have this format:"
# echo "<verb in imperative mood> <what was done>"
# echo "Allowed verbs in imperative mood: add, cut, fix, bump, make, start, stop, refactor, reformat, optimise, document, merge"
# echo "Example: add login button"
# echo "-"
# echo "Your commit message was:"
# echo $message
# echo "-"
# echo "For more information, check script in .husky/commit-msg"
# echo "-"
# exit 1
#fi


# Check if the string has at least 9 characters
if [ ${#message} -lt 9 ]; then
echo "🚨 Wrong commit message! πŸ˜•"
echo "The commit message must have this format:"
echo "<verb in imperative mood> <what was done>"
echo "Allowed verbs in imperative mood: add, cut, fix, bump, make, start, stop, refactor, reformat, optimise, document, merge"
echo "Example: add login button"
echo "-"
echo "Error: Commit message should have at least 9 characters."
echo "Your commit message was:"
echo $message
echo "-"
echo "For more information, check script in .husky/commit-msg"
exit 1
fi

# Check if the string contains 2 words
wordCount=$(echo "$message" | wc -w)
echo "wordCount: $wordCount"
if [ $wordCount -lt 2 ]; then
echo "🚨 Wrong commit message! πŸ˜•"
echo "Error: Commit message should contain at least 2 words."
echo "Your commit message was:"
echo $message
echo "-"
echo "For more information, check script in .husky/commit-msg"
exit 1
fi
fi

echo "βœ… Commit message is valid!"

echo "βœ… commit-msg hook finished successfully"
4 changes: 3 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ npm run lint
npm run comment:check

# run tests
npm test
npm run test

echo "βœ… pre-commit hook finished successfully"

0 comments on commit dcdcd42

Please sign in to comment.