autopilot-code 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autopilot-code",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "private": false,
5
5
  "description": "Repo-issue–driven autopilot runner",
6
6
  "license": "MIT",
@@ -28,6 +28,8 @@ import shutil
28
28
 
29
29
  STATE_DIR = ".autopilot"
30
30
  STATE_FILE = "state.json"
31
+ GLOBAL_CONFIG_DIR = Path.home() / ".config" / "autopilot"
32
+ GLOBAL_STATE_FILE = GLOBAL_CONFIG_DIR / "state.json"
31
33
  DEFAULT_HEARTBEAT_MAX_AGE_SECS = 60 * 60 # 1h
32
34
  DEFAULT_MAX_DEPTH = 3
33
35
  IGNORED_DIRS = {
@@ -621,9 +623,13 @@ def try_merge_pr(cfg: RepoConfig, issue_number: int, pr: dict[str, Any]) -> bool
621
623
  has_failure = any(c.get("conclusion") == "FAILURE" for c in checks)
622
624
  has_pending = any(c.get("conclusion") in ("PENDING", "QUEUED", None) for c in checks)
623
625
 
624
- if has_failure:
626
+ # If all checks are pending/queued and there are more than 0, it's pending
627
+ # But we should also check the rollup state if available
628
+ rollup_state = pr_details.get("statusCheckRollup", {}).get("state") if isinstance(pr_details.get("statusCheckRollup"), dict) else None
629
+
630
+ if has_failure or rollup_state == "FAILURE":
625
631
  check_status = "FAILED"
626
- elif has_pending:
632
+ elif has_pending or rollup_state == "PENDING":
627
633
  check_status = "PENDING"
628
634
  else:
629
635
  check_status = "PASSED"
@@ -207,6 +207,9 @@ if gh pr view --repo "$REPO" --head "$BRANCH" --json url --jq .url >/dev/null 2>
207
207
  gh issue comment "$ISSUE_NUMBER" --repo "$REPO" --body "📋 PR already exists: $PR_URL" || true
208
208
  else
209
209
  PR_URL=$(gh pr create --repo "$REPO" --title "Autopilot: Issue #$ISSUE_NUMBER" --body "Closes #$ISSUE_NUMBER" --base main --head "$BRANCH")
210
+
211
+ # Add short delay after PR creation to allow GitHub to calculate merge state
212
+ sleep 10
210
213
  fi
211
214
 
212
215
  # 8. Comment on issue with PR URL (best-effort)
@@ -406,10 +409,45 @@ I'm monitoring the CI checks and will auto-merge once they pass. This may take a
406
409
  while [[ $POLL_ATTEMPT -lt $MAX_POLL_ATTEMPTS ]]; do
407
410
  POLL_ATTEMPT=$((POLL_ATTEMPT + 1))
408
411
 
409
- # Get PR check status (handle null/empty statusCheckRollup as PASSED - no checks configured)
410
- CHECK_STATUS=$(gh pr view --repo "$REPO" --head "$BRANCH" --json mergeable,mergeStateStatus,statusCheckRollup --jq '.statusCheckRollup | if . == null or length == 0 then "PASSED" elif map(.conclusion) | any(. == "FAILURE") then "FAILED" elif map(.conclusion) | any(. == "PENDING") or any(. == "QUEUED") then "PENDING" else "PASSED" end' 2>/dev/null || echo "PENDING")
412
+ # Get full PR status for debugging and decision making
413
+ PR_STATUS_JSON=$(gh pr view --repo "$REPO" --head "$BRANCH" --json mergeable,mergeStateStatus,statusCheckRollup 2>/dev/null || echo '{"mergeable":"UNKNOWN","mergeStateStatus":"UNKNOWN","statusCheckRollup":null}')
414
+
415
+ # Log raw API response for debugging
416
+ echo "[run_opencode_issue.sh] Debug: Raw PR status = $PR_STATUS_JSON"
417
+
418
+ # Parse mergeStateStatus
419
+ if command -v jq >/dev/null 2>&1; then
420
+ MERGE_STATE_STATUS=$(echo "$PR_STATUS_JSON" | jq -r '.mergeStateStatus')
421
+ else
422
+ MERGE_STATE_STATUS=$(python3 -c 'import json,sys; print(json.load(sys.stdin).get("mergeStateStatus", "UNKNOWN"))' <<<"$PR_STATUS_JSON")
423
+ fi
424
+
425
+ # Determine check status based on both statusCheckRollup and mergeStateStatus
426
+ # If mergeStateStatus is CLEAN or HAS_HOOKS and statusCheckRollup is null/empty → PASSED
427
+ # If mergeStateStatus is UNKNOWN → wait and retry
428
+ if [[ "$MERGE_STATE_STATUS" == "UNKNOWN" ]]; then
429
+ CHECK_STATUS="PENDING"
430
+ echo "[run_opencode_issue.sh] mergeStateStatus is UNKNOWN, waiting for GitHub to calculate..."
431
+ elif [[ "$MERGE_STATE_STATUS" == "CLEAN" || "$MERGE_STATE_STATUS" == "HAS_HOOKS" ]]; then
432
+ # Check statusCheckRollup - if null/empty, no checks configured, so PASSED
433
+ if command -v jq >/dev/null 2>&1; then
434
+ CHECK_STATUS=$(echo "$PR_STATUS_JSON" | jq -r '.statusCheckRollup | if . == null or length == 0 then "PASSED" elif map(.conclusion) | any(. == "FAILURE") then "FAILED" elif map(.conclusion) | any(. == "PENDING") or any(. == "QUEUED") then "PENDING" else "PASSED" end')
435
+ else
436
+ CHECK_STATUS=$(python3 -c 'import json,sys; data=json.load(sys.stdin); scr=data.get("statusCheckRollup"); print("PASSED" if not scr or len(scr)==0 else "FAILED" if any(c.get("conclusion")=="FAILURE" for c in scr) else "PENDING" if any(c.get("conclusion") in ["PENDING","QUEUED"] for c in scr) else "PASSED")' <<<"$PR_STATUS_JSON")
437
+ fi
438
+ elif [[ "$MERGE_STATE_STATUS" == "BLOCKED" ]]; then
439
+ # If mergeStateStatus is BLOCKED, check if it's due to failed checks
440
+ if command -v jq >/dev/null 2>&1; then
441
+ CHECK_STATUS=$(echo "$PR_STATUS_JSON" | jq -r '.statusCheckRollup | if . == null or length == 0 then "PASSED" elif map(.conclusion) | any(. == "FAILURE") then "FAILED" elif map(.conclusion) | any(. == "PENDING") or any(. == "QUEUED") then "PENDING" else "PASSED" end')
442
+ else
443
+ CHECK_STATUS=$(python3 -c 'import json,sys; data=json.load(sys.stdin); scr=data.get("statusCheckRollup"); print("PASSED" if not scr or len(scr)==0 else "FAILED" if any(c.get("conclusion")=="FAILURE" for c in scr) else "PENDING" if any(c.get("conclusion") in ["PENDING","QUEUED"] for c in scr) else "PASSED")' <<<"$PR_STATUS_JSON")
444
+ fi
445
+ else
446
+ # Other states (DRAFT, DIRTY, BEHIND) - mark as FAILED to exit
447
+ CHECK_STATUS="FAILED"
448
+ fi
411
449
 
412
- echo "[run_opencode_issue.sh] Poll attempt $POLL_ATTEMPT/$MAX_POLL_ATTEMPTS: Check status = $CHECK_STATUS"
450
+ echo "[run_opencode_issue.sh] Poll attempt $POLL_ATTEMPT/$MAX_POLL_ATTEMPTS: Check status = $CHECK_STATUS, mergeStateStatus = $MERGE_STATE_STATUS"
413
451
 
414
452
  if [[ "$CHECK_STATUS" == "PASSED" ]]; then
415
453
  echo "[run_opencode_issue.sh] All checks passed. Proceeding with merge..."