fix: Dual curl calls for HAS_APPROVE / HAS_CHANGES create a race window (#321)
Each of the three review-check sites (orphan, stuck-PR, backlog) now fetches reviews with a single curl call, storing the JSON response and jq-filtering both HAS_APPROVE and HAS_CHANGES from the cached result. This eliminates the race window where a review submitted between the two calls could cause a transient mismatch. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
305302c20a
commit
70aea63521
1 changed files with 15 additions and 13 deletions
|
|
@ -275,12 +275,12 @@ if [ "$ORPHAN_COUNT" -gt 0 ]; then
|
||||||
log "PR #${HAS_PR} has no code files — treating CI as passed"
|
log "PR #${HAS_PR} has no code files — treating CI as passed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check formal reviews
|
# Check formal reviews (single fetch to avoid race window)
|
||||||
HAS_APPROVE=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
REVIEWS_JSON=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
||||||
"${API}/pulls/${HAS_PR}/reviews" | \
|
"${API}/pulls/${HAS_PR}/reviews") || true
|
||||||
|
HAS_APPROVE=$(echo "$REVIEWS_JSON" | \
|
||||||
jq -r '[.[] | select(.state == "APPROVED") | select(.stale == false)] | length') || true
|
jq -r '[.[] | select(.state == "APPROVED") | select(.stale == false)] | length') || true
|
||||||
HAS_CHANGES=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
HAS_CHANGES=$(echo "$REVIEWS_JSON" | \
|
||||||
"${API}/pulls/${HAS_PR}/reviews" | \
|
|
||||||
jq -r '[.[] | select(.state == "REQUEST_CHANGES")] | length') || true
|
jq -r '[.[] | select(.state == "REQUEST_CHANGES")] | length') || true
|
||||||
|
|
||||||
if ci_passed "$CI_STATE" && [ "${HAS_APPROVE:-0}" -gt 0 ]; then
|
if ci_passed "$CI_STATE" && [ "${HAS_APPROVE:-0}" -gt 0 ]; then
|
||||||
|
|
@ -355,11 +355,12 @@ for i in $(seq 0 $(($(echo "$OPEN_PRS" | jq 'length') - 1))); do
|
||||||
log "PR #${PR_NUM} has no code files — treating CI as passed"
|
log "PR #${PR_NUM} has no code files — treating CI as passed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
HAS_CHANGES=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
# Single fetch to avoid race window between review checks
|
||||||
"${API}/pulls/${PR_NUM}/reviews" | \
|
REVIEWS_JSON=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
||||||
|
"${API}/pulls/${PR_NUM}/reviews") || true
|
||||||
|
HAS_CHANGES=$(echo "$REVIEWS_JSON" | \
|
||||||
jq -r '[.[] | select(.state == "REQUEST_CHANGES")] | length') || true
|
jq -r '[.[] | select(.state == "REQUEST_CHANGES")] | length') || true
|
||||||
HAS_APPROVE=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
HAS_APPROVE=$(echo "$REVIEWS_JSON" | \
|
||||||
"${API}/pulls/${PR_NUM}/reviews" | \
|
|
||||||
jq -r '[.[] | select(.state == "APPROVED") | select(.stale == false)] | length') || true
|
jq -r '[.[] | select(.state == "APPROVED") | select(.stale == false)] | length') || true
|
||||||
|
|
||||||
# Spawn agent to merge if approved + CI green
|
# Spawn agent to merge if approved + CI green
|
||||||
|
|
@ -443,11 +444,12 @@ for i in $(seq 0 $((BACKLOG_COUNT - 1))); do
|
||||||
log "PR #${EXISTING_PR} has no code files — treating CI as passed"
|
log "PR #${EXISTING_PR} has no code files — treating CI as passed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
HAS_APPROVE=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
# Single fetch to avoid race window between review checks
|
||||||
"${API}/pulls/${EXISTING_PR}/reviews" | \
|
REVIEWS_JSON=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
||||||
|
"${API}/pulls/${EXISTING_PR}/reviews") || true
|
||||||
|
HAS_APPROVE=$(echo "$REVIEWS_JSON" | \
|
||||||
jq -r '[.[] | select(.state == "APPROVED") | select(.stale == false)] | length') || true
|
jq -r '[.[] | select(.state == "APPROVED") | select(.stale == false)] | length') || true
|
||||||
HAS_CHANGES=$(curl -sf -H "Authorization: token ${CODEBERG_TOKEN}" \
|
HAS_CHANGES=$(echo "$REVIEWS_JSON" | \
|
||||||
"${API}/pulls/${EXISTING_PR}/reviews" | \
|
|
||||||
jq -r '[.[] | select(.state == "REQUEST_CHANGES")] | length') || true
|
jq -r '[.[] | select(.state == "REQUEST_CHANGES")] | length') || true
|
||||||
|
|
||||||
if ci_passed "$CI_STATE" && [ "${HAS_APPROVE:-0}" -gt 0 ]; then
|
if ci_passed "$CI_STATE" && [ "${HAS_APPROVE:-0}" -gt 0 ]; then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue