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