mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-19 01:44:16 +00:00
+23









Josema Camacho
César Arroba
Alan Buscaglia
Claude
Andoni Alonso
Rubén De la Torre Vico
HugoPBrito
Hugo Pereira Brito
Pepe Fagoaga
Copilot Autofix powered by AI
Chandrapal Badshah
Chandrapal Badshah
Adrián Peña
Pedro Martín
KonstGolfi
lydiavilchez
Prowler Bot
prowler-bot
StylusFrost
dependabot[bot]
alejandrobailo
Alejandro Bailo
Víctor Fernández Poyatos
bota4go
Daniel Barranquero
Daniel Barranquero
mchennai
Ryan Nolette
Ulissis Correa
Sergio Garcia
Lee Trout
Sergio Garcia
Alan-TheGentleman
032499c29a
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: César Arroba <19954079+cesararroba@users.noreply.github.com> Co-authored-by: Alan Buscaglia <gentlemanprogramming@gmail.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Andoni Alonso <14891798+andoniaf@users.noreply.github.com> Co-authored-by: Rubén De la Torre Vico <ruben@prowler.com> Co-authored-by: HugoPBrito <hugopbrit@gmail.com> Co-authored-by: Hugo Pereira Brito <101209179+HugoPBrito@users.noreply.github.com> Co-authored-by: Pepe Fagoaga <pepe@prowler.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Chandrapal Badshah <Chan9390@users.noreply.github.com> Co-authored-by: Chandrapal Badshah <12944530+Chan9390@users.noreply.github.com> Co-authored-by: Adrián Peña <adrianjpr@gmail.com> Co-authored-by: Pedro Martín <pedromarting3@gmail.com> Co-authored-by: KonstGolfi <73020281+KonstGolfi@users.noreply.github.com> Co-authored-by: lydiavilchez <114735608+lydiavilchez@users.noreply.github.com> Co-authored-by: Prowler Bot <bot@prowler.com> Co-authored-by: prowler-bot <179230569+prowler-bot@users.noreply.github.com> Co-authored-by: StylusFrost <43682773+StylusFrost@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: alejandrobailo <alejandrobailo94@gmail.com> Co-authored-by: Alejandro Bailo <59607668+alejandrobailo@users.noreply.github.com> Co-authored-by: Víctor Fernández Poyatos <victor@prowler.com> Co-authored-by: bota4go <108249054+bota4go@users.noreply.github.com> Co-authored-by: Daniel Barranquero <74871504+danibarranqueroo@users.noreply.github.com> Co-authored-by: Daniel Barranquero <danielbo2001@gmail.com> Co-authored-by: mchennai <50082780+mchennai@users.noreply.github.com> Co-authored-by: Ryan Nolette <sonofagl1tch@users.noreply.github.com> Co-authored-by: Ulissis Correa <123517149+ulissisc@users.noreply.github.com> Co-authored-by: Sergio Garcia <hello@mistercloudsec.com> Co-authored-by: Lee Trout <ltrout@watchpointlabs.com> Co-authored-by: Sergio Garcia <sergargar1@gmail.com> Co-authored-by: Alan-TheGentleman <alan@thegentleman.dev>
177 lines
6.4 KiB
Bash
Executable File
177 lines
6.4 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
# Prowler UI - Pre-Commit Hook
|
||
# Optionally validates ONLY staged files against AGENTS.md standards using Claude Code
|
||
# Controlled by CODE_REVIEW_ENABLED in .env
|
||
|
||
set -e
|
||
|
||
# Colors
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[1;33m'
|
||
BLUE='\033[0;34m'
|
||
NC='\033[0m' # No Color
|
||
|
||
echo ""
|
||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||
echo "🚀 Prowler UI - Pre-Commit Hook"
|
||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||
echo ""
|
||
|
||
# Load .env file (look in git root directory)
|
||
GIT_ROOT=$(git rev-parse --show-toplevel)
|
||
if [ -f "$GIT_ROOT/ui/.env" ]; then
|
||
CODE_REVIEW_ENABLED=$(grep "^CODE_REVIEW_ENABLED" "$GIT_ROOT/ui/.env" | cut -d'=' -f2 | tr -d ' ')
|
||
elif [ -f "$GIT_ROOT/.env" ]; then
|
||
CODE_REVIEW_ENABLED=$(grep "^CODE_REVIEW_ENABLED" "$GIT_ROOT/.env" | cut -d'=' -f2 | tr -d ' ')
|
||
elif [ -f ".env" ]; then
|
||
CODE_REVIEW_ENABLED=$(grep "^CODE_REVIEW_ENABLED" .env | cut -d'=' -f2 | tr -d ' ')
|
||
else
|
||
CODE_REVIEW_ENABLED="false"
|
||
fi
|
||
|
||
# Normalize the value to lowercase
|
||
CODE_REVIEW_ENABLED=$(echo "$CODE_REVIEW_ENABLED" | tr '[:upper:]' '[:lower:]')
|
||
|
||
echo -e "${BLUE}ℹ️ Code Review Status: ${CODE_REVIEW_ENABLED}${NC}"
|
||
echo ""
|
||
|
||
# Get staged files in the UI folder only (what will be committed)
|
||
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM -- 'ui/**' | grep -E '\.(tsx?|jsx?)$' || true)
|
||
|
||
if [ "$CODE_REVIEW_ENABLED" = "true" ]; then
|
||
if [ -z "$STAGED_FILES" ]; then
|
||
echo -e "${YELLOW}⚠️ No TypeScript/JavaScript files staged to validate${NC}"
|
||
echo ""
|
||
else
|
||
echo -e "${YELLOW}🔍 Running Claude Code standards validation...${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}📋 Files to validate:${NC}"
|
||
echo "$STAGED_FILES" | while IFS= read -r file; do echo " - $file"; done
|
||
echo ""
|
||
|
||
echo -e "${BLUE}📤 Sending to Claude Code for validation...${NC}"
|
||
echo ""
|
||
|
||
# Build prompt with full file contents
|
||
VALIDATION_PROMPT=$(
|
||
cat <<'PROMPT_EOF'
|
||
You are a code reviewer for the Prowler UI project. Analyze the full file contents of changed files below and validate they comply with AGENTS.md standards.
|
||
|
||
**RULES TO CHECK:**
|
||
1. React Imports: NO `import * as React` or `import React, {` → Use `import { useState }`
|
||
2. TypeScript: NO union types like `type X = "a" | "b"` → Use const-based: `const X = {...} as const`
|
||
3. Tailwind: NO `var()` or hex colors in className → Use Tailwind utilities and semantic color classes. Exception: `var()` is allowed when passing colors to chart/graph components that require CSS color strings (not Tailwind classes) for their APIs.
|
||
4. cn(): Use for merging multiple classes or for conditionals (handles Tailwind conflicts with twMerge) → `cn(BUTTON_STYLES.base, BUTTON_STYLES.active, isLoading && "opacity-50")`
|
||
5. React 19: NO `useMemo`/`useCallback` without reason
|
||
6. Zod v4: Use `.min(1)` not `.nonempty()`, `z.email()` not `z.string().email()`. All inputs must be validated with Zod.
|
||
7. File Org: 1 feature = local, 2+ features = shared
|
||
8. Directives: Server Actions need "use server", clients need "use client"
|
||
9. Implement DRY, KISS principles. (example: reusable components, avoid repetition)
|
||
10. Layout must work for all the responsive breakpoints (mobile, tablet, desktop)
|
||
11. ANY types cannot be used - CRITICAL: Check for `: any` in all visible lines
|
||
12. Use the components inside components/shadcn if possible
|
||
13. Check Accessibility best practices (like alt tags in images, semantic HTML, Aria labels, etc.)
|
||
|
||
=== FILES TO REVIEW ===
|
||
PROMPT_EOF
|
||
)
|
||
|
||
# Add full file contents for each staged file
|
||
for file in $STAGED_FILES; do
|
||
VALIDATION_PROMPT="$VALIDATION_PROMPT
|
||
|
||
=== FILE: $file ===
|
||
$(cat "$file" 2>/dev/null || echo "Error reading file")"
|
||
done
|
||
|
||
VALIDATION_PROMPT="$VALIDATION_PROMPT
|
||
|
||
=== END FILES ===
|
||
|
||
**IMPORTANT: Your response MUST start with exactly one of these lines:**
|
||
STATUS: PASSED
|
||
STATUS: FAILED
|
||
|
||
**If FAILED:** List each violation with File, Line Number, Rule Number, and Issue.
|
||
**If PASSED:** Confirm all files comply with AGENTS.md standards.
|
||
|
||
**Start your response now with STATUS:**"
|
||
|
||
# Send to Claude Code
|
||
if VALIDATION_OUTPUT=$(echo "$VALIDATION_PROMPT" | claude 2>&1); then
|
||
echo "$VALIDATION_OUTPUT"
|
||
echo ""
|
||
|
||
# Check result - STRICT MODE: fail if status unclear
|
||
if echo "$VALIDATION_OUTPUT" | grep -q "^STATUS: PASSED"; then
|
||
echo ""
|
||
echo -e "${GREEN}✅ VALIDATION PASSED${NC}"
|
||
echo ""
|
||
elif echo "$VALIDATION_OUTPUT" | grep -q "^STATUS: FAILED"; then
|
||
echo ""
|
||
echo -e "${RED}❌ VALIDATION FAILED${NC}"
|
||
echo -e "${RED}Fix violations before committing${NC}"
|
||
echo ""
|
||
exit 1
|
||
else
|
||
echo ""
|
||
echo -e "${RED}❌ VALIDATION ERROR${NC}"
|
||
echo -e "${RED}Could not determine validation status from Claude Code response${NC}"
|
||
echo -e "${YELLOW}Response must start with 'STATUS: PASSED' or 'STATUS: FAILED'${NC}"
|
||
echo ""
|
||
echo -e "${YELLOW}To bypass validation temporarily, set CODE_REVIEW_ENABLED=false in .env${NC}"
|
||
echo ""
|
||
exit 1
|
||
fi
|
||
else
|
||
echo -e "${YELLOW}⚠️ Claude Code not available${NC}"
|
||
fi
|
||
echo ""
|
||
fi
|
||
else
|
||
echo -e "${YELLOW}⏭️ Code review disabled (CODE_REVIEW_ENABLED=false)${NC}"
|
||
echo ""
|
||
fi
|
||
|
||
# Check if there are any UI files to validate
|
||
if [ -z "$STAGED_FILES" ] && [ "$CODE_REVIEW_ENABLED" = "true" ]; then
|
||
echo -e "${YELLOW}⏭️ No UI files to validate, skipping healthcheck${NC}"
|
||
echo ""
|
||
exit 0
|
||
fi
|
||
|
||
# Run healthcheck (typecheck and lint check) only if there are UI changes
|
||
echo -e "${BLUE}🏥 Running healthcheck...${NC}"
|
||
echo ""
|
||
|
||
cd ui || cd .
|
||
if pnpm run healthcheck; then
|
||
echo ""
|
||
echo -e "${GREEN}✅ Healthcheck passed${NC}"
|
||
echo ""
|
||
else
|
||
echo ""
|
||
echo -e "${RED}❌ Healthcheck failed${NC}"
|
||
echo -e "${RED}Fix type errors and linting issues before committing${NC}"
|
||
echo ""
|
||
exit 1
|
||
fi
|
||
|
||
# Run build
|
||
echo -e "${BLUE}🔨 Running build...${NC}"
|
||
echo ""
|
||
|
||
if pnpm run build; then
|
||
echo ""
|
||
echo -e "${GREEN}✅ Build passed${NC}"
|
||
echo ""
|
||
else
|
||
echo ""
|
||
echo -e "${RED}❌ Build failed${NC}"
|
||
echo -e "${RED}Fix build errors before committing${NC}"
|
||
echo ""
|
||
exit 1
|
||
fi
|