Open History to see the last commit
1import type { PullRequestCheck, PullRequestChecks, PullRequestDetail } from "@t3tools/contracts";
2
3export 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 if (!newer) return detail;
14 // Older servers omit the count. Their check rows can still confirm that nothing needs approval.
15 const workflowApprovalsRequired =
16 checks.workflowApprovalsRequired ??
17 (detail.workflowApprovalsRequired !== undefined &&
18 !checks.checks.some((check) => check.status === "action-required")
19 ? 0
20 : detail.workflowApprovalsRequired);
21 return {
22 ...detail,
23 state: detail.state === "merged" ? "merged" : checks.state,
24 checks: checks.checks,
25 ...(workflowApprovalsRequired === undefined ? {} : { workflowApprovalsRequired }),
26 };
27}
28
29/** Checks still running are worth a tighter poll than a settled head. */
30export function pullRequestChecksRefreshIntervalMs(
31 checks: ReadonlyArray<PullRequestCheck>,
32): number {
33 return checks.length === 0 ||
34 checks.some((check) => check.status === "pending" || check.status === "action-required")
35 ? 45_000
36 : 60_000;
37}