Skip to content

Commit

Permalink
feat: add branch name check
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonath-z committed Jan 16, 2024
1 parent 71afd1c commit 9701469
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
npx lint-staged && npm run check-branch-name
23 changes: 23 additions & 0 deletions check_branch_name.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
local_branch_name="$(git rev-parse --abbrev-ref HEAD)"

# This regular expression is:
# 1. checking for branch Names: "dev" or "main"
# - ^(dev|main)$)
# 2. checking for branch Name starting with fix,ft,ht,chore or doc follwed by a "/" then the "branch name"
# - ^((fix|ft|ht|chore|doc)\/[a-zA-Z0-9\-]+)$
valid_branch_regex='^(dev|main)$|^((fix|ft|ht|chore|doc)\/[a-zA-Z0-9\-]+)$'

green='\033[0;32m'
red='\033[0;31m'
clear='\033[0m'

message="❌❌❌❌ There is something wrong with your branch name $local_branch_name.\nBranch names in this project must adhere to the format specified in the CONTRIBUTING guide.\nYour commit will be rejected. You should rename your branch to a valid name and try again"

if [[ ! $local_branch_name =~ $valid_branch_regex ]]; then
echo -e "${red}$message${clear}"
exit 1
fi

echo -e "${green}Branch name check passed ✅${clear}"
exit 0
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"start": "next start",
"lint": "eslint --ignore-path .eslintignore \"./**/*.{ts,tsx,js}\"",
"prettier-format": "prettier --config .prettierrc 'src/**/*.{ts,tsx,js,jsx}' --write",
"postinstall": "chmod +x .husky/*"
"check-branch-name": "./check_branch_name.sh",
"prepare": "chmod +x .husky/* && chmod +x ./check_branch_name.sh"
},
"dependencies": {
"@coingecko/cryptoformat": "^0.5.4",
Expand Down

0 comments on commit 9701469

Please sign in to comment.