@heznpc/anvil
Advanced tools
+39
-2
@@ -52,4 +52,13 @@ import { execa } from "execa"; | ||
| ]); | ||
| step("gh pr checks --watch"); | ||
| await execa("gh", ["pr", "checks", "--watch"]); | ||
| // Wait for CI to register before calling --watch. Otherwise gh exits 1 | ||
| // with "no checks reported" on a brand-new PR and the pipeline dies | ||
| // even though CI is about to start. | ||
| const hasChecks = await waitForChecksToRegister(); | ||
| if (hasChecks) { | ||
| step("gh pr checks --watch"); | ||
| await execa("gh", ["pr", "checks", "--watch"]); | ||
| } | ||
| else { | ||
| step("(no CI configured on this repo — skipping check wait)"); | ||
| } | ||
| step(`gh pr merge --${strategy} --delete-branch`); | ||
@@ -68,1 +77,29 @@ await execa("gh", ["pr", "merge", `--${strategy}`, "--delete-branch"]); | ||
| } | ||
| async function waitForChecksToRegister() { | ||
| // PRs take a moment to index on GitHub after `gh pr create`, and CI | ||
| // takes additional time to register checks. Poll up to 45s. Returns | ||
| // true if checks appear, false if the final attempt confirms no CI at | ||
| // all. Tolerates transient gh failures during the window. | ||
| const maxAttempts = 9; | ||
| const intervalMs = 5000; | ||
| await new Promise((r) => setTimeout(r, 3000)); | ||
| let lastResult = {}; | ||
| for (let i = 0; i < maxAttempts; i++) { | ||
| const result = await execa("gh", ["pr", "checks"], { reject: false }); | ||
| lastResult = result; | ||
| if (result.exitCode === 0 && result.stdout.trim()) | ||
| return true; | ||
| // On non-final attempts, any failure (no checks, transient API, PR not | ||
| // yet indexed) simply waits and retries. | ||
| if (i < maxAttempts - 1) { | ||
| await new Promise((r) => setTimeout(r, intervalMs)); | ||
| continue; | ||
| } | ||
| // Final attempt: "no checks reported" = the repo has no CI; anything | ||
| // else = something genuinely wrong. | ||
| if (/no checks reported/i.test(result.stderr ?? "")) | ||
| return false; | ||
| } | ||
| const msg = lastResult.stderr || lastResult.stdout || "no output"; | ||
| throw new Error(`gh pr checks never produced a result after ${maxAttempts} attempts: ${msg.trim()}`); | ||
| } |
+1
-1
| { | ||
| "name": "@heznpc/anvil", | ||
| "version": "0.1.1", | ||
| "version": "0.1.3", | ||
| "description": "Atomic workflow recipes for Claude Code. One MCP tool call runs the whole commit → push → PR → CI-wait → merge pipeline.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
15471
12.82%244
17.87%