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>
This commit is contained in:
@@ -98,6 +98,14 @@ Notes:
|
|||||||
- Stash uncommitted state files before switching branches
|
- Stash uncommitted state files before switching branches
|
||||||
- Delete feature branches after merge
|
- Delete feature branches after merge
|
||||||
- Gitea token stored at `~/.config/gitea-token`
|
- Gitea token stored at `~/.config/gitea-token`
|
||||||
|
- PRs show as "closed" (not "merged") after rebase - expected
|
||||||
|
|
||||||
|
### PR Review Policy
|
||||||
|
|
||||||
|
| Repo Type | Review Process |
|
||||||
|
|-----------|----------------|
|
||||||
|
| ~/.claude | Linting/validation only (shellcheck, JSON/YAML syntax, Python syntax) |
|
||||||
|
| Code repos | Full review via code-reviewer agent before user approval |
|
||||||
|
|
||||||
## Component Formats
|
## Component Formats
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Create a PR in Gitea for the current branch
|
# Create a PR in Gitea for the current branch
|
||||||
# Usage: gitea-pr.sh [title] [body]
|
# Usage: gitea-pr.sh [title] [body]
|
||||||
|
# Runs validation before creating PR
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
GITEA_URL="https://gitea-http.taildb3494.ts.net"
|
GITEA_URL="https://gitea-http.taildb3494.ts.net"
|
||||||
REPO="will/claude-code"
|
REPO="will/claude-code"
|
||||||
TOKEN_FILE="$HOME/.config/gitea-token"
|
TOKEN_FILE="$HOME/.config/gitea-token"
|
||||||
@@ -23,6 +25,14 @@ if [[ "$BRANCH" == "main" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Run validation
|
||||||
|
echo "Running pre-PR validation..."
|
||||||
|
if ! "$SCRIPT_DIR/validate-pr.sh"; then
|
||||||
|
echo "Error: Validation failed. Fix issues before creating PR." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
# Default title from branch name
|
# Default title from branch name
|
||||||
TITLE="${1:-$BRANCH}"
|
TITLE="${1:-$BRANCH}"
|
||||||
BODY="${2:-Auto-generated PR for $BRANCH}"
|
BODY="${2:-Auto-generated PR for $BRANCH}"
|
||||||
|
|||||||
82
automation/validate-pr.sh
Executable file
82
automation/validate-pr.sh
Executable file
@@ -0,0 +1,82 @@
|
|||||||
|
#!/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
|
||||||
Reference in New Issue
Block a user