Skip to content

Commit

Permalink
Merge pull request #1491 from kevinchappell/chore/1490
Browse files Browse the repository at this point in the history
chore: add commitlint and husky for git hooks
  • Loading branch information
kevinchappell committed Dec 18, 2023
2 parents f116884 + 3f398d0 commit 23f09c8
Show file tree
Hide file tree
Showing 5 changed files with 1,539 additions and 39 deletions.
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

0 comments on commit 23f09c8

Please sign in to comment.