Skip to content
Source
Sign inSign up

pullRequestReply.ts

20 lines805 Bytes

1import type { PullRequestState } from "@t3tools/contracts";
2​
3interface ObservedPullRequest {
4 readonly state: PullRequestState;
5 readonly updatedAt?: string | undefined;
6 readonly observedAt?: number | undefined;
7}
8​
9/** Older than what is shown by host update time, then server read time, or a merge undone. */
10export function isStalePullRequestReply(
11 shown: ObservedPullRequest,
12 reply: ObservedPullRequest,
13): boolean {
14 if (shown.state === "merged" && reply.state !== "merged") return true;
15 if (shown.updatedAt !== undefined && reply.updatedAt !== undefined) {
16 const updated = Date.parse(reply.updatedAt) - Date.parse(shown.updatedAt);
17 if (Number.isFinite(updated) && updated !== 0) return updated < 0;
18 }
19 return (reply.observedAt ?? -Infinity) < (shown.observedAt ?? -Infinity);