Compare commits
1 commit
a3eb837ba2
...
718327754a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
718327754a |
1 changed files with 50 additions and 47 deletions
|
|
@ -463,62 +463,65 @@ if [ "$ORPHAN_COUNT" -gt 0 ]; then
|
|||
BLOCKED_BY_INPROGRESS=true
|
||||
fi
|
||||
|
||||
PR_SHA=$(curl -sf -H "Authorization: token ${FORGE_TOKEN}" \
|
||||
"${API}/pulls/${HAS_PR}" | jq -r '.head.sha') || true
|
||||
CI_STATE=$(ci_commit_status "$PR_SHA") || true
|
||||
# Only process PR if not abandoned (stale branch check above)
|
||||
if [ "$BLOCKED_BY_INPROGRESS" = false ]; then
|
||||
PR_SHA=$(curl -sf -H "Authorization: token ${FORGE_TOKEN}" \
|
||||
"${API}/pulls/${HAS_PR}" | jq -r '.head.sha') || true
|
||||
CI_STATE=$(ci_commit_status "$PR_SHA") || true
|
||||
|
||||
# Non-code PRs (docs, formulas, evidence) may have no CI — treat as passed
|
||||
if ! ci_passed "$CI_STATE" && ! ci_required_for_pr "$HAS_PR"; then
|
||||
CI_STATE="success"
|
||||
log "PR #${HAS_PR} has no code files — treating CI as passed"
|
||||
fi
|
||||
|
||||
# Check formal reviews (single fetch to avoid race window)
|
||||
REVIEWS_JSON=$(curl -sf -H "Authorization: token ${FORGE_TOKEN}" \
|
||||
"${API}/pulls/${HAS_PR}/reviews") || true
|
||||
HAS_APPROVE=$(echo "$REVIEWS_JSON" | \
|
||||
jq -r '[.[] | select(.state == "APPROVED") | select(.stale == false)] | length') || true
|
||||
HAS_CHANGES=$(echo "$REVIEWS_JSON" | \
|
||||
jq -r '[.[] | select(.state == "REQUEST_CHANGES") | select(.stale == false)] | length') || true
|
||||
|
||||
if ci_passed "$CI_STATE" && [ "${HAS_APPROVE:-0}" -gt 0 ]; then
|
||||
if try_direct_merge "$HAS_PR" "$ISSUE_NUM"; then
|
||||
BLOCKED_BY_INPROGRESS=true
|
||||
else
|
||||
# Direct merge failed (conflicts?) — fall back to dev-agent
|
||||
log "falling back to dev-agent for PR #${HAS_PR} merge"
|
||||
nohup "${SCRIPT_DIR}/dev-agent.sh" "$ISSUE_NUM" >> "$LOGFILE" 2>&1 &
|
||||
log "started dev-agent PID $! for issue #${ISSUE_NUM} (agent-merge)"
|
||||
BLOCKED_BY_INPROGRESS=true
|
||||
# Non-code PRs (docs, formulas, evidence) may have no CI — treat as passed
|
||||
if ! ci_passed "$CI_STATE" && ! ci_required_for_pr "$HAS_PR"; then
|
||||
CI_STATE="success"
|
||||
log "PR #${HAS_PR} has no code files — treating CI as passed"
|
||||
fi
|
||||
|
||||
# Do NOT gate REQUEST_CHANGES on ci_passed: act immediately even if CI is
|
||||
# pending/unknown. Definitive CI failure is handled by the elif below.
|
||||
elif [ "${HAS_CHANGES:-0}" -gt 0 ] && { ci_passed "$CI_STATE" || [ "$CI_STATE" = "pending" ] || [ "$CI_STATE" = "unknown" ] || [ -z "$CI_STATE" ]; }; then
|
||||
log "issue #${ISSUE_NUM} PR #${HAS_PR} has REQUEST_CHANGES — spawning agent"
|
||||
nohup "${SCRIPT_DIR}/dev-agent.sh" "$ISSUE_NUM" >> "$LOGFILE" 2>&1 &
|
||||
log "started dev-agent PID $! for issue #${ISSUE_NUM} (review fix)"
|
||||
BLOCKED_BY_INPROGRESS=true
|
||||
# Check formal reviews (single fetch to avoid race window)
|
||||
REVIEWS_JSON=$(curl -sf -H "Authorization: token ${FORGE_TOKEN}" \
|
||||
"${API}/pulls/${HAS_PR}/reviews") || true
|
||||
HAS_APPROVE=$(echo "$REVIEWS_JSON" | \
|
||||
jq -r '[.[] | select(.state == "APPROVED") | select(.stale == false)] | length') || true
|
||||
HAS_CHANGES=$(echo "$REVIEWS_JSON" | \
|
||||
jq -r '[.[] | select(.state == "REQUEST_CHANGES") | select(.stale == false)] | length') || true
|
||||
|
||||
elif ci_failed "$CI_STATE"; then
|
||||
if handle_ci_exhaustion "$HAS_PR" "$ISSUE_NUM" "check_only"; then
|
||||
# Fall through to backlog scan instead of exit
|
||||
:
|
||||
else
|
||||
# Increment at actual launch time (not on guard-hit paths)
|
||||
if handle_ci_exhaustion "$HAS_PR" "$ISSUE_NUM"; then
|
||||
BLOCKED_BY_INPROGRESS=true # exhausted between check and launch
|
||||
if ci_passed "$CI_STATE" && [ "${HAS_APPROVE:-0}" -gt 0 ]; then
|
||||
if try_direct_merge "$HAS_PR" "$ISSUE_NUM"; then
|
||||
BLOCKED_BY_INPROGRESS=true
|
||||
else
|
||||
log "issue #${ISSUE_NUM} PR #${HAS_PR} CI failed — spawning agent to fix (attempt ${CI_FIX_ATTEMPTS}/3)"
|
||||
# Direct merge failed (conflicts?) — fall back to dev-agent
|
||||
log "falling back to dev-agent for PR #${HAS_PR} merge"
|
||||
nohup "${SCRIPT_DIR}/dev-agent.sh" "$ISSUE_NUM" >> "$LOGFILE" 2>&1 &
|
||||
log "started dev-agent PID $! for issue #${ISSUE_NUM} (CI fix)"
|
||||
log "started dev-agent PID $! for issue #${ISSUE_NUM} (agent-merge)"
|
||||
BLOCKED_BY_INPROGRESS=true
|
||||
fi
|
||||
fi
|
||||
|
||||
else
|
||||
log "issue #${ISSUE_NUM} has open PR #${HAS_PR} (CI: ${CI_STATE}, waiting)"
|
||||
BLOCKED_BY_INPROGRESS=true
|
||||
# Do NOT gate REQUEST_CHANGES on ci_passed: act immediately even if CI is
|
||||
# pending/unknown. Definitive CI failure is handled by the elif below.
|
||||
elif [ "${HAS_CHANGES:-0}" -gt 0 ] && { ci_passed "$CI_STATE" || [ "$CI_STATE" = "pending" ] || [ "$CI_STATE" = "unknown" ] || [ -z "$CI_STATE" ]; }; then
|
||||
log "issue #${ISSUE_NUM} PR #${HAS_PR} has REQUEST_CHANGES — spawning agent"
|
||||
nohup "${SCRIPT_DIR}/dev-agent.sh" "$ISSUE_NUM" >> "$LOGFILE" 2>&1 &
|
||||
log "started dev-agent PID $! for issue #${ISSUE_NUM} (review fix)"
|
||||
BLOCKED_BY_INPROGRESS=true
|
||||
|
||||
elif ci_failed "$CI_STATE"; then
|
||||
if handle_ci_exhaustion "$HAS_PR" "$ISSUE_NUM" "check_only"; then
|
||||
# Fall through to backlog scan instead of exit
|
||||
:
|
||||
else
|
||||
# Increment at actual launch time (not on guard-hit paths)
|
||||
if handle_ci_exhaustion "$HAS_PR" "$ISSUE_NUM"; then
|
||||
BLOCKED_BY_INPROGRESS=true # exhausted between check and launch
|
||||
else
|
||||
log "issue #${ISSUE_NUM} PR #${HAS_PR} CI failed — spawning agent to fix (attempt ${CI_FIX_ATTEMPTS}/3)"
|
||||
nohup "${SCRIPT_DIR}/dev-agent.sh" "$ISSUE_NUM" >> "$LOGFILE" 2>&1 &
|
||||
log "started dev-agent PID $! for issue #${ISSUE_NUM} (CI fix)"
|
||||
BLOCKED_BY_INPROGRESS=true
|
||||
fi
|
||||
fi
|
||||
|
||||
else
|
||||
log "issue #${ISSUE_NUM} has open PR #${HAS_PR} (CI: ${CI_STATE}, waiting)"
|
||||
BLOCKED_BY_INPROGRESS=true
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# Check assignee before adopting orphaned issue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue