PRIX / scripts /install-hooks.sh
yamxxx1's picture
Upload 117 files
a2fe16e verified
Raw
History Blame
2.87 kB
#!/bin/bash
# PRIX Pre-commit Hook Installer
# Usage: ./install-hooks.sh
set -e
HOOK_DIR="$(git rev-parse --show-toplevel)/.git/hooks"
PRECOMMIT_HOOK="$HOOK_DIR/pre-commit"
echo "🔧 Installing PRIX pre-commit hook..."
if [ ! -d "$HOOK_DIR" ]; then
echo "❌ Error: .git/hooks directory not found. Are you in a git repository?"
exit 1
fi
if [ -f "$PRECOMMIT_HOOK" ]; then
echo "⚠️ Existing pre-commit hook found. Backing up to pre-commit.bak"
cp "$PRECOMMIT_HOOK" "$HOOK_DIR/pre-commit.bak"
fi
cat > "$PRECOMMIT_HOOK" << 'EOF'
#!/bin/bash
# PRIX AI Code Review - Pre-commit Hook
# Generated by PRIX
# Configuration
PRIX_MIN_SEVERITY="${PRIX_MIN_SEVERITY:-minor}"
PRIX_MIN_CONFIDENCE="${PRIX_MIN_CONFIDENCE:-60}"
PRIX_DISABLE="${PRIX_DISABLE:-false}"
# Colors
RED='\033[0;31m'
YELLOW='\033[0;33m'
GREEN='\033[0;32m'
NC='\033[0m'
if [ "$PRIX_DISABLE" = "true" ]; then
echo "ℹ️ PRIX pre-commit disabled (PRIX_DISABLE=true)"
exit 0
fi
echo "🔍 PRIX: Running AI code review on staged files..."
# Check for required environment variables
if [ -z "$GROQ_API_KEY" ] && [ -z "$AI_API_KEY" ]; then
echo -e "${YELLOW}⚠️ Warning: GROQ_API_KEY or AI_API_KEY not set. Skipping PRIX review.${NC}"
echo " Set these environment variables to enable pre-commit review."
exit 0
fi
# Get staged files
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(ts|tsx|js|jsx|go|py)$' || true)
if [ -z "$STAGED_FILES" ]; then
echo "ℹ️ No supported files staged for review"
exit 0
fi
FILE_COUNT=$(echo "$STAGED_FILES" | wc -l)
echo "📋 Found $FILE_COUNT file(s) to review"
# Run PRIX CLI
npx prix-cli \
--staged \
--min-severity "$PRIX_MIN_SEVERITY" \
--min-confidence "$PRIX_MIN_CONFIDENCE" \
--output console 2>&1
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo -e "${GREEN}✅ PRIX: No critical issues found${NC}"
elif [ $EXIT_CODE -eq 1 ]; then
if [ -n "$CI" ]; then
echo -e "${RED}❌ PRIX: Critical issues found. Commit blocked in CI.${NC}"
echo " To bypass this hook in local development, use: git commit --no-verify"
else
echo -e "${YELLOW}⚠️ PRIX: Issues found. Review recommended but not blocking.${NC}"
EXIT_CODE=0
fi
fi
exit $EXIT_CODE
EOF
chmod +x "$PRECOMMIT_HOOK"
echo -e "${GREEN}✅ PRIX pre-commit hook installed!${NC}"
echo ""
echo "Configuration (environment variables):"
echo " PRIX_MIN_SEVERITY - Minimum severity to report (critical|major|minor|info) [default: minor]"
echo " PRIX_MIN_CONFIDENCE - Minimum confidence threshold 0-100 [default: 60]"
echo " PRIX_DISABLE - Set to 'true' to skip review [default: false]"
echo ""
echo "To bypass this hook locally: git commit --no-verify"