Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

threadPullRequest.ts

146 lines5.9 KB

1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3​
4import {
5 IsoDateTime,
6 NonNegativeInt,
7 PositiveInt,
8 ProjectId,
9 TrimmedNonEmptyString,
10} from "./baseSchemas.ts";
11import {
12 PullRequestActor,
13 PullRequestChecksState,
14 PullRequestMergeability,
15 PullRequestReviewDecision,
16 PullRequestState,
17} from "./pullRequest.ts";
18​
19export const ThreadLinkedPullRequest = Schema.Struct({
20 projectId: ProjectId,
21 repository: TrimmedNonEmptyString,
22 number: PositiveInt,
23 url: TrimmedNonEmptyString,
24});
25export type ThreadLinkedPullRequest = typeof ThreadLinkedPullRequest.Type;
26​
27/** stack-dismissed hides an unlinked native member and prevents sync from re-adding it. */
28export const ThreadPullRequestLinkSource = Schema.Literals([
29 "manual",
30 "created",
31 "agent",
32 "stack",
33 "stack-dismissed",
34]);
35export type ThreadPullRequestLinkSource = typeof ThreadPullRequestLinkSource.Type;
36​
37export const ThreadPullRequestSnapshot = Schema.Struct({
38 state: PullRequestState,
39 title: TrimmedNonEmptyString,
40 headBranch: TrimmedNonEmptyString,
41 baseBranch: TrimmedNonEmptyString,
42 isDraft: Schema.Boolean,
43 updatedAt: Schema.NullOr(IsoDateTime),
44 syncedAt: IsoDateTime,
45 closedAt: Schema.optional(Schema.NullOr(Schema.String)),
46 mergedAt: Schema.optional(Schema.NullOr(Schema.String)),
47 author: Schema.optional(Schema.NullOr(PullRequestActor)),
48 additions: Schema.optional(NonNegativeInt),
49 deletions: Schema.optional(NonNegativeInt),
50 changedFiles: Schema.optional(NonNegativeInt),
51 reviewDecision: Schema.optional(Schema.NullOr(PullRequestReviewDecision)),
52 checksState: Schema.optional(Schema.NullOr(PullRequestChecksState)),
53 mergeability: Schema.optional(PullRequestMergeability),
54 rebaseRequired: Schema.optional(Schema.Boolean),
55});
56export type ThreadPullRequestSnapshot = typeof ThreadPullRequestSnapshot.Type;
57​
58export const ThreadPullRequestStackLayer = Schema.Struct({
59 number: PositiveInt,
60 headBranch: TrimmedNonEmptyString,
61 state: PullRequestState,
62});
63export type ThreadPullRequestStackLayer = typeof ThreadPullRequestStackLayer.Type;
64​
65/** Layers run bottom to top. */
66export const ThreadPullRequestStack = Schema.Struct({
67 kind: Schema.Literal("native"),
68 id: TrimmedNonEmptyString,
69 number: PositiveInt,
70 url: TrimmedNonEmptyString,
71 base: TrimmedNonEmptyString,
72 layers: Schema.Array(ThreadPullRequestStackLayer),
73});
74export type ThreadPullRequestStack = typeof ThreadPullRequestStack.Type;
75​
76export const ThreadPullRequestKey = Schema.Struct({
77 host: TrimmedNonEmptyString,
78 repository: TrimmedNonEmptyString,
79 number: PositiveInt,
80});
81export type ThreadPullRequestKey = typeof ThreadPullRequestKey.Type;
82​
83export const ThreadPullRequestWatch = Schema.Struct({
84 startedAt: IsoDateTime,
85 headSha: Schema.NullOr(TrimmedNonEmptyString),
86 failedChecks: Schema.Array(TrimmedNonEmptyString),
87 passed: Schema.Boolean,
88 passedChecks: Schema.Array(TrimmedNonEmptyString).pipe(
89 Schema.withDecodingDefault(Effect.succeed([])),
90 ),
91 /**
92 * Marks one wake owed once every check has finished: the checks still pending when the required
93 * ones passed early, or the failed ones while a failure keeps the required ones from passing.
94 */
95 owedChecks: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
96 /** Approval holds keyed by workflow run URL, or check name when no run URL is known. */
97 awaitingApproval: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
98 /** The agent was told checks await approval on this head, so later ones stay quiet. */
99 approvalAnnounced: Schema.optional(Schema.Boolean),
100 remarksThrough: IsoDateTime,
101 /** Reported remarks at remarksThrough, so late arrivals at that timestamp still count. */
102 remarkIds: Schema.Array(TrimmedNonEmptyString),
103 conflicting: Schema.Boolean,
104 rebaseRequired: Schema.optional(Schema.Boolean),
105 /** Last removal seen; null after an empty read, absent before the first read. */
106 mergeQueueRemovalId: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
107 /** Consecutive comment-only wakes; limited to prevent bot loops. */
108 wakes: NonNegativeInt,
109 /**
110 * What is already on the pull request is recorded, not reported: conflicts on the first read, and
111 * checks on the first read that can be trusted to show them (one with a head and a full check read).
112 */
113 awaitingBaseline: Schema.optional(Schema.Literals(["all", "checks"])),
114 /**
115 * When the head was first read without any check, until a check shows up or the agent is told
116 * none did. Null once either happened; absent on watches saved before it existed.
117 */
118 checksAwaitedSince: Schema.optional(Schema.NullOr(IsoDateTime)),
119 /**
120 * Whether the host was still running checks on the head at the last read. Only then does the
121 * watch keep its thread waiting; absent on watches not read since it existed.
122 */
123 checksPending: Schema.optional(Schema.Boolean),
124 /** How long the watch holds its thread. Absent means until every check finished. */
125 until: Schema.optional(Schema.Literal("merged")),
126});
127export type ThreadPullRequestWatch = typeof ThreadPullRequestWatch.Type;
128​
129/** `merged` also ends when the PR closes or the agent unwatches it. */
130export const PullRequestWatchUntil = Schema.Literals(["checks", "merged"]);
131export type PullRequestWatchUntil = typeof PullRequestWatchUntil.Type;
132​
133export const ThreadPullRequestLink = Schema.Struct({
134 ...ThreadPullRequestKey.fields,
135 url: TrimmedNonEmptyString,
136 /** An actual browser or clone URL; older agent display URLs may be synthesized. */
137 repositoryWebUrl: Schema.optional(TrimmedNonEmptyString),
138 source: ThreadPullRequestLinkSource,
139 linkedAt: IsoDateTime,
140 snapshot: Schema.NullOr(ThreadPullRequestSnapshot),
141 stack: Schema.NullOr(ThreadPullRequestStack),
142 watch: Schema.optional(ThreadPullRequestWatch),
143 /** Resume from the ended watch to avoid duplicate notifications. */
144 endedWatch: Schema.optional(ThreadPullRequestWatch),
145});
146export type ThreadPullRequestLink = typeof ThreadPullRequestLink.Type;