From 7fb1660c3047104d68ae602514d031abe2b952bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20De=20la=20Torre=20Vico?= Date: Tue, 7 Apr 2026 18:21:49 +0200 Subject: [PATCH] chore: update setup-git-hooks.sh to use prek Detect prek from PATH first (brew, npm global, pipx), then fall back to Poetry. This allows UI-only contributors to use prek without needing Poetry installed. --- scripts/setup-git-hooks.sh | 59 +++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/scripts/setup-git-hooks.sh b/scripts/setup-git-hooks.sh index ab7c01479d..04becd6f6b 100755 --- a/scripts/setup-git-hooks.sh +++ b/scripts/setup-git-hooks.sh @@ -1,7 +1,8 @@ #!/bin/bash # Setup Git Hooks for Prowler -# This script installs pre-commit hooks using the project's Poetry environment +# This script installs prek hooks using the project's Poetry environment +# or a system-wide prek installation set -e @@ -23,43 +24,43 @@ if ! git rev-parse --git-dir >/dev/null 2>&1; then exit 1 fi -# Check if Poetry is installed -if ! command -v poetry &>/dev/null; then - echo -e "${RED}โŒ Poetry is not installed${NC}" - echo -e "${YELLOW} Install Poetry: https://python-poetry.org/docs/#installation${NC}" - exit 1 -fi - -# Check if pyproject.toml exists -if [ ! -f "pyproject.toml" ]; then - echo -e "${RED}โŒ pyproject.toml not found${NC}" - echo -e "${YELLOW} Please run this script from the repository root${NC}" - exit 1 -fi - -# Check if dependencies are already installed -if ! poetry run python -c "import pre_commit" 2>/dev/null; then - echo -e "${YELLOW}๐Ÿ“ฆ Installing project dependencies (including pre-commit)...${NC}" - poetry install --with dev -else - echo -e "${GREEN}โœ“${NC} Dependencies already installed" -fi - -echo "" -# Clear any existing core.hooksPath to avoid pre-commit conflicts +# Clear any existing core.hooksPath to avoid conflicts if git config --get core.hooksPath >/dev/null 2>&1; then echo -e "${YELLOW}๐Ÿงน Clearing existing core.hooksPath configuration...${NC}" git config --unset-all core.hooksPath fi -echo -e "${YELLOW}๐Ÿ”— Installing pre-commit hooks...${NC}" -poetry run pre-commit install +echo "" + +# Try to find prek: system-wide first, then Poetry +if command -v prek &>/dev/null; then + echo -e "${GREEN}โœ“${NC} prek found in PATH" + echo -e "${YELLOW}๐Ÿ”— Installing prek hooks...${NC}" + prek install --overwrite +elif command -v poetry &>/dev/null && [ -f "pyproject.toml" ]; then + if poetry run prek --version &>/dev/null 2>&1; then + echo -e "${GREEN}โœ“${NC} prek found via Poetry" + else + echo -e "${YELLOW}๐Ÿ“ฆ Installing project dependencies (including prek)...${NC}" + poetry install --with dev + fi + echo -e "${YELLOW}๐Ÿ”— Installing prek hooks...${NC}" + poetry run prek install --overwrite +else + echo -e "${RED}โŒ prek is not installed${NC}" + echo -e "${YELLOW} Install prek using one of these methods:${NC}" + echo -e " โ€ข brew install prek" + echo -e " โ€ข pnpm add -g @j178/prek" + echo -e " โ€ข pip install prek" + echo -e " โ€ข See https://prek.j178.dev/installation/ for more options" + exit 1 +fi echo "" echo -e "${GREEN}โœ… Git hooks successfully configured!${NC}" echo "" -echo -e "${YELLOW}๐Ÿ“‹ Pre-commit system:${NC}" -echo -e " โ€ข Python pre-commit manages all git hooks" +echo -e "${YELLOW}๐Ÿ“‹ Prek hook system:${NC}" +echo -e " โ€ข Prek manages all git hooks" echo -e " โ€ข API files: Python checks (black, flake8, bandit, etc.)" echo -e " โ€ข UI files: UI checks (TypeScript, ESLint, Claude Code validation)" echo ""