Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions scripts/review-one-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ echo "==> $PR_URL"
# NEUTRAL covers informational checks that don't gate merging.
# failing — anything else (FAILURE, ACTION_REQUIRED, TIMED_OUT, CANCELLED,
# STALE, STARTUP_FAILURE, or unknown conclusions)
PR_SNAPSHOT=$(gh pr view "$PR_URL" --json headRefOid,statusCheckRollup)
PR_SNAPSHOT=$(gh pr view "$PR_URL" --json headRefOid,statusCheckRollup,reviewDecision,reviews)
PR_HEAD_SHA=$(echo "$PR_SNAPSHOT" | jq -r '.headRefOid')
export PR_HEAD_SHA
echo " head SHA: $PR_HEAD_SHA"
Expand All @@ -61,9 +61,12 @@ CI_STATUS=$(echo "$PR_SNAPSHOT" | jq -r '
')
echo " CI status: $CI_STATUS"

REVIEW_DECISION=$(echo "$PR_SNAPSHOT" | jq -r '.reviewDecision // ""')
echo " review decision: $REVIEW_DECISION"

# Exit code 100 is the skip sentinel: the caller treats any 100 exit as a
# no-op and does not count it against the MAX_PRS review budget.
# Reasons that produce a skip: already-reviewed-at-head, ci-failing, ci-pending.
# Reasons that produce a skip: already-reviewed-at-head, ci-failing, ci-pending, changes-requested.
if [ "$CI_STATUS" = "failing" ]; then
echo " skip: CI checks are failing — will re-evaluate after fixes are pushed"
echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"ci-failing\"}"
Expand All @@ -74,6 +77,24 @@ if [ "$CI_STATUS" = "pending" ]; then
echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"ci-pending\"}"
exit 100
fi
# Skip when a human has requested changes, with two guards:
# 1. FORCE_REVIEW bypasses the skip — mention-triggered runs always proceed so
# authors can request a re-review after addressing feedback.
# 2. Only skip when a CHANGES_REQUESTED review targets the current head SHA.
# On repos that don't dismiss stale reviews, reviewDecision can stay
# CHANGES_REQUESTED after the author pushes new commits; in that case the
# review is stale and the cascade should re-engage with the updated code.
if [ "$REVIEW_DECISION" = "CHANGES_REQUESTED" ] && [ "${FORCE_REVIEW:-false}" != "true" ]; then
CHANGES_REQUESTED_AT_HEAD=$(echo "$PR_SNAPSHOT" | jq -r --arg sha "$PR_HEAD_SHA" '
[.reviews[] | select(.state == "CHANGES_REQUESTED" and .commit.oid == $sha)]
| if length > 0 then "true" else "false" end
')
if [ "$CHANGES_REQUESTED_AT_HEAD" = "true" ]; then
echo " skip: changes requested at current head — awaiting author response before reviewing"
echo "{\"pr\":\"$PR_URL\",\"sha\":\"$PR_HEAD_SHA\",\"decision\":\"skip\",\"reason\":\"changes-requested\"}"
exit 100
fi
fi

# 2. Idempotency: look for our marker at this SHA in existing reviews+comments.
# We tag every review/comment with reviews' submittedAt / comments' createdAt,
Expand Down
Loading