Skip to content

Commit

Permalink
chore(Project): enforce branch name policy
Browse files Browse the repository at this point in the history
  • Loading branch information
dgonzalezr committed Jun 25, 2024
1 parent 91f2c61 commit d7a04eb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions .husky/branch-name.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

# Colors
RED='\033[0;31m'
YELLOW='\033[0;33m'
CLEARCOLOR='\033[0m'

local_branch_name="$(git rev-parse --abbrev-ref HEAD)"
allowed_branch_names="feat|fix|test|docs|style|chore|perf|refactor|revert|ci|build"

message="${RED}There is something wrong with your branch name${CLEARCOLOR}\\n\
Branch names in this project must adhere to this contract:\\n\
<prefix>/<name>\\n\
where prefix is one of:
$allowed_branch_names\\n\
${YELLOW}Please, rename your branch to a valid name and try again.${CLEARCOLOR}\\n"

branch_name_check="^(($allowed_branch_names)\/[a-zA-Z0-9\-]+)$"
if [[ ! $local_branch_name =~ $branch_name_check ]]; then
echo "$message"
exit 1
fi

exit 0
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
"build:wrappers": "nx run-many -t build -p tag:wrapper --output-style=stream-without-prefixes",
"build:storybook": "nx run beeq:storybook-build --output-style=stream-without-prefixes",
"lint": "npx nx affected -t lint --exclude='*,!tag:publishable' --output-style=stream-without-prefixes",
"lint:branch-name": "chmod 755 .husky/branch-name.sh && sh .husky/branch-name.sh",
"lint:staged": "lint-staged --verbose",
"test": "run-s test:*",
"test:spec": "npx nx affected -t test --exclude='*,!tag:publishable' --output-style=stream-without-prefixes",
"test:e2e": "npx nx affected -t e2e --exclude='*,!tag:core' --output-style=stream-without-prefixes",
"clean": "run-s clean:*",
"clean:build": "rimraf dist packages/beeq/.stencil",
"clean:modules": "rimraf node_modules .nx packages/**/node_modules",
"pre-commit": "lint-staged --verbose",
"pre-commit": "run-s lint:branch-name lint:staged",
"prepare": "husky",
"postinstall": "node node_modules/puppeteer/install.mjs",
"g": "plop --cwd tools/src/generators/plop"
Expand Down

0 comments on commit d7a04eb

Please sign in to comment.