|
1 | | -#!/bin/bash |
2 | | - |
3 | | -# ---- DRY RUN MODE ---- |
4 | | -if [ "$DRY_RUN" = "1" ]; then |
5 | | - echo "[DRY RUN] Hook executed: $(basename "$0")" |
6 | | - exit 0 |
7 | | -fi |
8 | | -# --------------------- |
9 | | -# Step 1: Validate branch naming convention |
10 | | -BRANCH_NAME=$(git symbolic-ref --short HEAD) |
11 | | -echo "Current branch: $BRANCH_NAME" |
12 | | - |
13 | | -# Define the branches to exclude |
14 | | -EXCLUDED_BRANCHES="develop main release" |
15 | | - |
16 | | -# Check if the current branch is in the excluded list |
17 | | -for EXCLUDED_BRANCH in $EXCLUDED_BRANCHES; do |
18 | | - if [ "$BRANCH_NAME" = "$EXCLUDED_BRANCH" ]; then |
19 | | - echo "Skipping pre-commit checks for branch: $BRANCH_NAME" |
20 | | - exit 0 |
21 | | - fi |
22 | | -done |
23 | | - |
24 | | -# Pre-commit checks (e.g., linting, testing, etc.) |
25 | | -echo "Running pre-commit checks for branch: $BRANCH_NAME" |
26 | | - |
27 | | -echo "$BRANCH_NAME" | grep -Eq '^(feature|bugfix|hotfix)/[A-Za-z]+-[0-9]+' |
28 | | -if [ $? -ne 0 ]; then |
29 | | - echo "Error: Branch name '$BRANCH_NAME' is invalid." |
30 | | - echo "Use a valid branch naming convention, e.g., feature/XYZ-123-description." |
31 | | - exit 1 |
32 | | -fi |
33 | | - |
34 | | -# Step 2: Run poetry linting tools |
35 | | -echo "Running poetry linting tools..." |
36 | | -if ! poetry run flake8 .; then |
37 | | - echo "flake8 failed. Aborting commit." |
38 | | - exit 1 |
39 | | -fi |
40 | | - |
41 | | -if ! poetry run black .; then |
42 | | - echo "black failed. Aborting commit." |
43 | | - exit 1 |
44 | | -fi |
45 | | - |
46 | | -#if ! poetry run mypy .; then |
47 | | -# echo "mypy failed. Aborting commit." |
48 | | -# exit 1 |
49 | | -#fi |
50 | | - |
51 | | -echo "Pre-commit checks passed!" |
52 | | -exit 0 |
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# ---- DRY RUN MODE ---- |
| 4 | +if [ "$DRY_RUN" = "1" ]; then |
| 5 | + echo "[DRY RUN] Hook executed: $(basename "$0")" |
| 6 | + exit 0 |
| 7 | +fi |
| 8 | +# --------------------- |
| 9 | +# Step 1: Validate branch naming convention |
| 10 | +BRANCH_NAME=$(git symbolic-ref --short HEAD) |
| 11 | +echo "Current branch: $BRANCH_NAME" |
| 12 | + |
| 13 | +# Define the branches to exclude |
| 14 | +EXCLUDED_BRANCHES="develop main release" |
| 15 | + |
| 16 | +# Check if the current branch is in the excluded list |
| 17 | +for EXCLUDED_BRANCH in $EXCLUDED_BRANCHES; do |
| 18 | + if [ "$BRANCH_NAME" = "$EXCLUDED_BRANCH" ]; then |
| 19 | + echo "Skipping pre-commit checks for branch: $BRANCH_NAME" |
| 20 | + exit 0 |
| 21 | + fi |
| 22 | +done |
| 23 | + |
| 24 | +# Pre-commit checks (e.g., linting, testing, etc.) |
| 25 | +echo "Running pre-commit checks for branch: $BRANCH_NAME" |
| 26 | + |
| 27 | +echo "$BRANCH_NAME" | grep -Eq '^(feature|bugfix|hotfix)/[A-Za-z]+-[0-9]+' |
| 28 | +if [ $? -ne 0 ]; then |
| 29 | + echo "Error: Branch name '$BRANCH_NAME' is invalid." |
| 30 | + echo "Use a valid branch naming convention, e.g., feature/XYZ-123-description." |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | + |
| 34 | +# Step 2: Run poetry linting tools |
| 35 | +echo "Running poetry linting tools..." |
| 36 | +if ! poetry run flake8 .; then |
| 37 | + echo "flake8 failed. Aborting commit." |
| 38 | + exit 1 |
| 39 | +fi |
| 40 | + |
| 41 | +if ! poetry run black .; then |
| 42 | + echo "black failed. Aborting commit." |
| 43 | + exit 1 |
| 44 | +fi |
| 45 | + |
| 46 | +#if ! poetry run mypy .; then |
| 47 | +# echo "mypy failed. Aborting commit." |
| 48 | +# exit 1 |
| 49 | +#fi |
| 50 | + |
| 51 | +echo "Pre-commit checks passed!" |
| 52 | +exit 0 |
0 commit comments