fix(review): harden ce-review base resolution (#452)
This commit is contained in:
@@ -34,7 +34,7 @@ Spawned when the orchestrator identifies relevant patterns in the diff. The orch
|
||||
| `data-migrations` | `compound-engineering:review:data-migrations-reviewer` | Migration files, schema changes, backfill scripts, data transformations |
|
||||
| `reliability` | `compound-engineering:review:reliability-reviewer` | Error handling, retry logic, circuit breakers, timeouts, background jobs, async handlers, health checks |
|
||||
| `adversarial` | `compound-engineering:review:adversarial-reviewer` | Diff has >=50 changed non-test, non-generated, non-lockfile lines, OR touches auth, payments, data mutations, external API integrations, or other high-risk domains |
|
||||
| `previous-comments` | `compound-engineering:review:previous-comments-reviewer` | Reviewing a PR that has existing review comments or review threads from prior review rounds |
|
||||
| `previous-comments` | `compound-engineering:review:previous-comments-reviewer` | **PR-only.** Reviewing a PR that has existing review comments or review threads from prior review rounds. Skip entirely when no PR metadata was gathered in Stage 1. |
|
||||
|
||||
## Stack-Specific Conditional (5 personas)
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ set -euo pipefail
|
||||
|
||||
REVIEW_BASE_BRANCH=""
|
||||
PR_BASE_REPO=""
|
||||
PR_BASE_REMOTE=""
|
||||
BASE_REF=""
|
||||
|
||||
# Step 1: Try PR metadata (handles fork workflows)
|
||||
@@ -51,19 +52,37 @@ if [ -n "$REVIEW_BASE_BRANCH" ]; then
|
||||
if [ -n "$PR_BASE_REPO" ]; then
|
||||
PR_BASE_REMOTE=$(git remote -v | awk "index(\$2, \"github.com:$PR_BASE_REPO\") || index(\$2, \"github.com/$PR_BASE_REPO\") {print \$1; exit}")
|
||||
if [ -n "$PR_BASE_REMOTE" ]; then
|
||||
git rev-parse --verify "$PR_BASE_REMOTE/$REVIEW_BASE_BRANCH" >/dev/null 2>&1 || git fetch --no-tags "$PR_BASE_REMOTE" "$REVIEW_BASE_BRANCH" 2>/dev/null || true
|
||||
git rev-parse --verify "$PR_BASE_REMOTE/$REVIEW_BASE_BRANCH" >/dev/null 2>&1 || git fetch --no-tags "$PR_BASE_REMOTE" "$REVIEW_BASE_BRANCH:refs/remotes/$PR_BASE_REMOTE/$REVIEW_BASE_BRANCH" 2>/dev/null || git fetch --no-tags "$PR_BASE_REMOTE" "$REVIEW_BASE_BRANCH" 2>/dev/null || true
|
||||
BASE_REF=$(git rev-parse --verify "$PR_BASE_REMOTE/$REVIEW_BASE_BRANCH" 2>/dev/null || true)
|
||||
fi
|
||||
fi
|
||||
if [ -z "$BASE_REF" ]; then
|
||||
git rev-parse --verify "origin/$REVIEW_BASE_BRANCH" >/dev/null 2>&1 || git fetch --no-tags origin "$REVIEW_BASE_BRANCH" 2>/dev/null || true
|
||||
BASE_REF=$(git rev-parse --verify "origin/$REVIEW_BASE_BRANCH" 2>/dev/null || git rev-parse --verify "$REVIEW_BASE_BRANCH" 2>/dev/null || true)
|
||||
# Only try origin if it exists as a remote; otherwise skip to avoid
|
||||
# confusing errors in fork setups where origin points at the user's fork.
|
||||
if git remote get-url origin >/dev/null 2>&1; then
|
||||
git rev-parse --verify "origin/$REVIEW_BASE_BRANCH" >/dev/null 2>&1 || git fetch --no-tags origin "$REVIEW_BASE_BRANCH:refs/remotes/origin/$REVIEW_BASE_BRANCH" 2>/dev/null || git fetch --no-tags origin "$REVIEW_BASE_BRANCH" 2>/dev/null || true
|
||||
BASE_REF=$(git rev-parse --verify "origin/$REVIEW_BASE_BRANCH" 2>/dev/null || true)
|
||||
fi
|
||||
# Fall back to a bare local ref only if remote resolution failed
|
||||
if [ -z "$BASE_REF" ]; then
|
||||
BASE_REF=$(git rev-parse --verify "$REVIEW_BASE_BRANCH" 2>/dev/null || true)
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Compute merge-base
|
||||
if [ -n "$BASE_REF" ]; then
|
||||
BASE=$(git merge-base HEAD "$BASE_REF" 2>/dev/null) || BASE=""
|
||||
if [ -z "$BASE" ] && [ "$(git rev-parse --is-shallow-repository 2>/dev/null || echo false)" = "true" ]; then
|
||||
if git remote get-url origin >/dev/null 2>&1; then
|
||||
git fetch --no-tags --unshallow origin 2>/dev/null || true
|
||||
BASE=$(git merge-base HEAD "$BASE_REF" 2>/dev/null) || BASE=""
|
||||
fi
|
||||
if [ -z "$BASE" ] && [ -n "$PR_BASE_REMOTE" ] && [ "$PR_BASE_REMOTE" != "origin" ]; then
|
||||
git fetch --no-tags --unshallow "$PR_BASE_REMOTE" 2>/dev/null || true
|
||||
BASE=$(git merge-base HEAD "$BASE_REF" 2>/dev/null) || BASE=""
|
||||
fi
|
||||
fi
|
||||
else
|
||||
BASE=""
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user