- 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>
72 lines
1.6 KiB
Bash
Executable File
72 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# Create a PR in Gitea for the current branch
|
|
# Usage: gitea-pr.sh [title] [body]
|
|
# Runs validation before creating PR
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
GITEA_URL="https://gitea-http.taildb3494.ts.net"
|
|
REPO="will/claude-code"
|
|
TOKEN_FILE="$HOME/.config/gitea-token"
|
|
|
|
if [[ ! -f "$TOKEN_FILE" ]]; then
|
|
echo "Error: Gitea token not found at $TOKEN_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
TOKEN=$(cat "$TOKEN_FILE")
|
|
|
|
# Get current branch
|
|
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
|
|
|
if [[ "$BRANCH" == "main" ]]; then
|
|
echo "Error: Cannot create PR from main branch" >&2
|
|
exit 1
|
|
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
|
|
TITLE="${1:-$BRANCH}"
|
|
BODY="${2:-Auto-generated PR for $BRANCH}"
|
|
|
|
# Create PR via API
|
|
RESPONSE=$(curl -s -X POST \
|
|
-H "Authorization: token $TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"title\": \"$TITLE\",
|
|
\"body\": \"$BODY\",
|
|
\"head\": \"$BRANCH\",
|
|
\"base\": \"main\"
|
|
}" \
|
|
"$GITEA_URL/api/v1/repos/$REPO/pulls")
|
|
|
|
# Extract PR URL or error
|
|
PR_URL=$(echo "$RESPONSE" | python3 -c "
|
|
import sys, json
|
|
d = json.load(sys.stdin)
|
|
if 'html_url' in d:
|
|
print(d['html_url'])
|
|
elif 'message' in d:
|
|
print(f\"Error: {d['message']}\", file=sys.stderr)
|
|
sys.exit(1)
|
|
else:
|
|
print(f'Unexpected response: {d}', file=sys.stderr)
|
|
sys.exit(1)
|
|
" 2>&1)
|
|
|
|
if [[ $? -eq 0 ]]; then
|
|
echo "PR created: $PR_URL"
|
|
else
|
|
echo "$PR_URL" >&2
|
|
exit 1
|
|
fi
|