|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +MAIN=$(git rev-parse --abbrev-ref HEAD) |
| 5 | +NUM=$(echo "$ISSUE_JSON" | jq -r '.number') |
| 6 | +TITLE=$(echo "$ISSUE_JSON" | jq -r '.title') |
| 7 | +BODY=$(echo "$ISSUE_JSON" | jq -r '.body') |
| 8 | +BRANCH="auto-fix/issue-${NUM}" |
| 9 | + |
| 10 | +echo "=== #${NUM}: ${TITLE} ===" |
| 11 | + |
| 12 | +# Rollback label on failure |
| 13 | +cleanup_on_failure() { |
| 14 | + gh issue edit "$NUM" --repo "$REPO" --add-label auto-fix --remove-label auto-fix-in-progress 2>/dev/null || true |
| 15 | +} |
| 16 | +trap cleanup_on_failure ERR |
| 17 | + |
| 18 | +# Skip if PR exists |
| 19 | +if [ "$(gh pr list --repo "$REPO" --head "$BRANCH" --json number --jq 'length')" -gt 0 ]; then |
| 20 | + echo "PR exists, skip" |
| 21 | + gh issue edit "$NUM" --repo "$REPO" --add-label auto-fix-done --remove-label auto-fix-in-progress |
| 22 | + exit 0 |
| 23 | +fi |
| 24 | + |
| 25 | +git checkout -b "$BRANCH" |
| 26 | + |
| 27 | +# Step 1: Generate fix |
| 28 | +evot -p "Fix this issue in databend-docs by modifying files under docs/en/. |
| 29 | +Follow existing doc style. Read related files first. |
| 30 | +
|
| 31 | +The Databend source code is available at _databend/src/ for reference. |
| 32 | +Use it to check actual implementation details (settings, functions, SQL syntax, etc.) |
| 33 | +when writing documentation. |
| 34 | +
|
| 35 | +Issue #${NUM}: ${TITLE} |
| 36 | +${BODY}" \ |
| 37 | + --model "$GENERATOR_MODEL" --env-file "$EVOT_ENV_FILE" \ |
| 38 | + --max-turns 30 --max-duration 600 || true |
| 39 | + |
| 40 | +if git diff --quiet; then |
| 41 | + echo "No changes" |
| 42 | + cleanup_on_failure |
| 43 | + exit 0 |
| 44 | +fi |
| 45 | + |
| 46 | +# Step 2: Review loop (max 2 rounds) |
| 47 | +APPROVED=false |
| 48 | +for round in 1 2; do |
| 49 | + DIFF=$(git diff) |
| 50 | + [ -z "$DIFF" ] && { APPROVED=true; break; } |
| 51 | + |
| 52 | + REVIEW=$(evot -p "Review this diff for issue #${NUM}: ${TITLE} |
| 53 | +${BODY} |
| 54 | +
|
| 55 | +Respond ONLY with JSON: {\"approved\": bool, \"comments\": \"...\"} |
| 56 | +
|
| 57 | +${DIFF}" \ |
| 58 | + --model "$REVIEWER_MODEL" --env-file "$EVOT_ENV_FILE" \ |
| 59 | + --max-turns 1 --max-duration 60 2>&1 || true) |
| 60 | + |
| 61 | + if echo "$REVIEW" | grep -q '"approved"[[:space:]]*:[[:space:]]*true'; then |
| 62 | + APPROVED=true; break |
| 63 | + fi |
| 64 | + |
| 65 | + COMMENTS=$(echo "$REVIEW" | python3 -c " |
| 66 | +import sys,json,re |
| 67 | +t=sys.stdin.read(); m=re.search(r'\{[^}]*\}',t,re.DOTALL) |
| 68 | +try: print(json.loads(m.group())['comments']) if m else print(t[:500]) |
| 69 | +except: print(t[:500])" 2>/dev/null || echo "$REVIEW" | head -10) |
| 70 | + |
| 71 | + evot -p "Address this review for issue #${NUM}: |
| 72 | +${COMMENTS}" \ |
| 73 | + --model "$GENERATOR_MODEL" --env-file "$EVOT_ENV_FILE" \ |
| 74 | + --max-turns 20 --max-duration 300 || true |
| 75 | +done |
| 76 | + |
| 77 | +# Step 3: PR |
| 78 | +git add -A |
| 79 | +git commit -m "docs: auto-fix #${NUM}" || { cleanup_on_failure; exit 0; } |
| 80 | +git push origin "$BRANCH" --force |
| 81 | + |
| 82 | +STATUS=$( [ "$APPROVED" = true ] && echo "✅ Approved" || echo "⚠️ Needs human review" ) |
| 83 | +gh pr create --repo "$REPO" --base "$MAIN" --head "$BRANCH" \ |
| 84 | + --title "docs: auto-fix #${NUM}" \ |
| 85 | + --body "Fixes #${NUM}. ${STATUS} |
| 86 | +Generated by \`${GENERATOR_MODEL}\`, reviewed by \`${REVIEWER_MODEL}\`." \ |
| 87 | + --label auto-fix || true |
| 88 | + |
| 89 | +# Mark done |
| 90 | +gh issue edit "$NUM" --repo "$REPO" --add-label auto-fix-done --remove-label auto-fix-in-progress |
0 commit comments