Files
claude-code/automation/validate-pr.sh
OpenCode Test 652ceb55f0 Add PR validation before creating PRs
- Create validate-pr.sh: runs shellcheck, JSON/YAML/Python syntax checks
- Update gitea-pr.sh: runs validation before creating PR
- Update CLAUDE.md: document PR review policy
  - ~/.claude repo: linting/validation only
  - Code repos: full code-reviewer agent review

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-04 13:06:31 -08:00

83 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
# Validate changed files before PR creation
# Runs: shellcheck, JSON validation, Python syntax check
set -euo pipefail
ERRORS=0
# Get changed files compared to main
CHANGED_FILES=$(git diff --name-only origin/main 2>/dev/null || git diff --name-only HEAD~1)
echo "Validating changed files..."
for file in $CHANGED_FILES; do
[[ -f "$file" ]] || continue
case "$file" in
*.sh)
if command -v shellcheck &>/dev/null; then
if ! shellcheck -S warning "$file" 2>/dev/null; then
echo "FAIL: shellcheck $file"
((ERRORS++))
else
echo "OK: $file"
fi
else
echo "SKIP: shellcheck not installed"
fi
;;
*.json)
if ! python3 -m json.tool "$file" >/dev/null 2>&1; then
echo "FAIL: invalid JSON $file"
((ERRORS++))
else
echo "OK: $file"
fi
;;
*.yaml|*.yml)
if command -v yamllint &>/dev/null; then
if ! yamllint -d relaxed "$file" 2>/dev/null; then
echo "FAIL: yamllint $file"
((ERRORS++))
else
echo "OK: $file"
fi
elif python3 -c "import yaml" 2>/dev/null; then
if ! python3 -c "import yaml; yaml.safe_load(open('$file'))" 2>/dev/null; then
echo "FAIL: invalid YAML $file"
((ERRORS++))
else
echo "OK: $file"
fi
else
echo "SKIP: no YAML validator"
fi
;;
*.py)
if ! python3 -m py_compile "$file" 2>/dev/null; then
echo "FAIL: Python syntax $file"
((ERRORS++))
else
echo "OK: $file"
fi
;;
*.md)
echo "OK: $file (markdown, no validation)"
;;
*)
echo "SKIP: $file (no validator)"
;;
esac
done
if [[ $ERRORS -gt 0 ]]; then
echo ""
echo "Validation failed with $ERRORS error(s)"
exit 1
fi
echo ""
echo "All validations passed"
exit 0