diff --git a/scripts/review.sh b/scripts/review.sh index 41ca4bf..fda5e42 100755 --- a/scripts/review.sh +++ b/scripts/review.sh @@ -73,15 +73,35 @@ echo "::endgroup::" # ─── Phase 2: Generate diff ─────────────────────────────────────────────────── echo "::group::Generate diff" -# Ensure we have full history (runner may have done a shallow checkout) -git fetch --unshallow --filter=blob:none origin 2>/dev/null || true -git fetch origin main 2>/dev/null || git fetch origin master 2>/dev/null || true +# actions/checkout for PRs only fetches the PR ref (refs/pull/N/head). +# It does NOT create remote tracking branches like origin/main. +# We must explicitly fetch the base branch. -BASE="origin/main" -if ! git rev-parse --verify "$BASE" >/dev/null 2>&1; then +# Unshallow if needed (fetch-depth: 0 already does this, but be safe) +git fetch --unshallow origin 2>/dev/null || true + +# Fetch base branch with explicit refspec to ensure origin/main exists +if git fetch origin refs/heads/main:refs/remotes/origin/main 2>/dev/null; then + BASE="origin/main" +elif git fetch origin refs/heads/master:refs/remotes/origin/master 2>/dev/null; then BASE="origin/master" +else + # Fallback: try Gitea/GitHub event context for the target branch + TARGET_BRANCH="${GITEA_BASE_REF:-${GITHUB_BASE_REF:-}}" + if [ -n "${TARGET_BRANCH}" ] && git fetch origin "refs/heads/${TARGET_BRANCH}:refs/remotes/origin/${TARGET_BRANCH}" 2>/dev/null; then + BASE="origin/${TARGET_BRANCH}" + else + echo "::warning::Could not fetch base branch. Trying origin/HEAD." + git fetch origin 2>/dev/null || true + BASE="origin/HEAD" + fi fi +echo "Base ref: ${BASE} -> $(git rev-parse --short "${BASE}" 2>/dev/null || echo 'NOT FOUND')" +echo "HEAD: $(git rev-parse --short HEAD)" +echo "Files changed:" +git diff --stat "${BASE}...HEAD" 2>/dev/null | tail -3 || echo "(could not stat diff)" + # Build exclude pathspecs EXCLUDE_ARGS="" for pattern in $PI_EXCLUDE; do