Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add commitlint and husky for git hooks #1491

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

if [ "$CI" = true ] ; then
echo 'Skipping commit-msg hook'
exit 0
fi

npx --no -- commitlint --edit "$1"
27 changes: 27 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env sh
set -e

. "$(dirname -- "$0")/_/husky.sh"

if [ "$CI" = true ] ; then
echo 'Skipping pre-commit hook'
exit 0
fi

LOCAL_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
VALID_BRANCH_NAME_REGEX="^(feat|chore|fix)\/[0-9]{1,6}(-[a-z0-9._-]{1,40})?$"

matches=`echo "$LOCAL_BRANCH" | grep -iE "$VALID_BRANCH_NAME_REGEX" | wc -l`

if [ $matches -eq 0 ]; then
echo "There is something wrong with your branch name."
echo "Branch names in this project must adhere to the following pattern:"
echo "--> Regex: $VALID_BRANCH_NAME_REGEX.\n--> Examples: \033[32mfeat/1234-example\033[0m or \033[32mchore/123\033[0m"
echo "\nYour commit was rejected, please rename your branch to a valid name and try again."

exit 1
fi

npm run pre-commit

exit 0
Loading