Skip to content

Commit eea1aa0

Browse files
authored
Merge pull request #1005 from dacadeorg/ft/add-branch-name-check
feat: add branch name check
2 parents 4d694e2 + 1cbeaa7 commit eea1aa0

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
npx lint-staged
4+
npx lint-staged && npm run check-branch-name

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ More on the [Conventional commits](https://www.conventionalcommits.org/en/v1.0.0
88

99
<br>
1010

11-
# Components conventions
11+
## Components conventions
1212

1313
1. Use `functional components` instead of arrow components
1414
2. For typescript, use `interface` for props, and types if needed.

check_branch_name.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
local_branch_name="$(git rev-parse --abbrev-ref HEAD)"
3+
4+
# This regular expression is:
5+
# 1. checking for branch Names: "dev" or "main"
6+
# - ^(dev|main)$)
7+
# 2. checking for branch Name starting with fix,ft,ht,chore or doc follwed by a "/" then the "branch name"
8+
# - ^((fix|ft|ht|chore|doc)\/[a-zA-Z0-9\-]+)$
9+
valid_branch_regex='^(dev|main)$|^((fix|ft|ht|chore|doc)\/[a-zA-Z0-9\-]+)$'
10+
11+
green='\033[0;32m'
12+
red='\033[0;31m'
13+
clear='\033[0m'
14+
15+
message="❌❌❌❌ Error: The branch name $local_branch_name does not adhere to the project guidelines.\nPlease refer to the CONTRIBUTING guide for the correct format.\nYour commit will be rejected. Rename your branch to a valid name and try again."
16+
17+
if [[ ! $local_branch_name =~ $valid_branch_regex ]]; then
18+
echo -e "${red}$message${clear}"
19+
exit 1
20+
fi
21+
22+
echo -e "${green}Branch name check passed ✅${clear}"
23+
exit 0

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"start": "next start",
99
"lint": "eslint --ignore-path .eslintignore \"./**/*.{ts,tsx,js}\"",
1010
"prettier-format": "prettier --config .prettierrc 'src/**/*.{ts,tsx,js,jsx}' --write",
11-
"postinstall": "chmod +x .husky/*"
11+
"check-branch-name": "./check_branch_name.sh",
12+
"prepare": "npx husky install && chmod +x .husky/* && chmod +x ./check_branch_name.sh"
1213
},
1314
"dependencies": {
1415
"@coingecko/cryptoformat": "^0.5.4",

0 commit comments

Comments
 (0)