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

threadPullRequest.ts

147 lines5.8 KB

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