The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { PullRequestCheck, PullRequestChecks, PullRequestDetail } from "@t3tools/contracts"; |
| 2 | |
| 3 | export function resolvePullRequestDetailChecks( |
| 4 | detail: PullRequestDetail | null, |
| 5 | checks: PullRequestChecks | null, |
| 6 | checksAreNewer: boolean, |
| 7 | ): PullRequestDetail | null { |
| 8 | if (detail === null || checks === null) return detail; |
| 9 | const newer = |
| 10 | detail.observedAt !== undefined && checks.observedAt !== undefined |
| 11 | ? checks.observedAt >= detail.observedAt |
| 12 | : checksAreNewer; |
| 13 | return newer |
| 14 | ? { |
| 15 | ...detail, |
| 16 | state: detail.state === "merged" ? "merged" : checks.state, |
| 17 | checks: checks.checks, |
| 18 | } |
| 19 | : detail; |
| 20 | } |
| 21 | |
| 22 | /** Checks still running are worth a tighter poll than a settled head. */ |
| 23 | export function pullRequestChecksRefreshIntervalMs( |
| 24 | checks: ReadonlyArray<PullRequestCheck>, |
| 25 | ): number { |
| 26 | return checks.length === 0 || |
| 27 | checks.some((check) => check.status === "pending" || check.status === "action-required") |
| 28 | ? 45_000 |
| 29 | : 60_000; |
| 30 | } |