Skip to content

Commit

Permalink
feat: add husky
Browse files Browse the repository at this point in the history
Signed-off-by: sarthakjdev <[email protected]>
  • Loading branch information
sarthakjdev committed Jun 1, 2024
1 parent 1e8f98b commit 064b39f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
32 changes: 14 additions & 18 deletions .husky/hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# # Check for conventional commit format
# commit_msg=$(cat "$1")
# # Modified regex to allow for more valid formats
# conventional_commit_regex='^(feat|fix|chore|docs|test|style|refactor|perf|build|ci|revert)(\(.+\))?(!)?(:)(\s.*)?$'

# check for conventional commit format
commit_msg=$(cat "$1")
# Regex to match Conventional Commit format
conventional_commit_regex='^(feat|fix|chore|docs|test|style|refactor|perf|build|ci|revert)(\(.+?\))?: .{1,}$'

if ! [[ "$commit_msg" =~ $conventional_commit_regex ]]; then
echo "ERROR: Commit message does not adhere to Conventional Commits format:"
echo "$commit_msg"
exit 1
fi
# echo "$conventional_commit_regex"

# if ! [[ "$commit_msg" =~ $conventional_commit_regex ]]; then
# echo "ERROR: Commit message does not adhere to Conventional Commits format:"
# echo "$commit_msg"
# echo "$($commit_msg =~ $conventional_commit_regex )"
# exit 1
# fi

# If not a merge commit, require commit to be signed off
if [ ! -e .git/MERGE_MSG ] && ! grep -q "^Signed-off-by: " "$1"; then
echo >&2 "Commit message must be signed off with your user name and email."
echo >&2 "To sign off your commit, add the -s flag to the git commit command."
exit 1
echo >&2 "Commit message must be signed off with your user name and email."
echo >&2 "To sign off your commit, add the -s flag to the git commit command."
exit 1
fi




7 changes: 3 additions & 4 deletions .husky/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

branch=`git symbolic-ref HEAD`
branch=$(git symbolic-ref HEAD)

if [ "$branch" = "refs/heads/master" ]; then
echo "\\033[31mDirect commit to master is not allowed.\\033[0m"
exit 1
echo "\\033[31mDirect commit to master is not allowed.\\033[0m"
exit 1
fi

go fmt ./...
3 changes: 1 addition & 2 deletions .husky/hooks/pre-push
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

branch=`git symbolic-ref HEAD`
branch=$(git symbolic-ref HEAD)

if [ "$branch" = "refs/heads/master" ]; then
echo "\\033[31mDirect push to master is not allowed.\\033[0m"
Expand Down

0 comments on commit 064b39f

Please sign in to comment.