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

threadPullRequest.ts

137 lines5.4 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 /** Checks still pending when required ones passed early, owed one wake once all settle. */
92 owedChecks: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
93 /** Approval holds keyed by workflow run URL, or check name when no run URL is known. */
94 awaitingApproval: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
95 /** The agent was told checks await approval on this head, so later ones stay quiet. */
96 approvalAnnounced: Schema.optional(Schema.Boolean),
97 remarksThrough: IsoDateTime,
98 /** Reported remarks at remarksThrough, so late arrivals at that timestamp still count. */
99 remarkIds: Schema.Array(TrimmedNonEmptyString),
100 conflicting: Schema.Boolean,
101 rebaseRequired: Schema.optional(Schema.Boolean),
102 /** Last removal seen; null after an empty read, absent before the first read. */
103 mergeQueueRemovalId: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
104 /** Consecutive comment-only wakes; limited to prevent bot loops. */
105 wakes: NonNegativeInt,
106 /**
107 * What is already on the pull request is recorded, not reported: conflicts on the first read, and
108 * checks on the first read that can be trusted to show them (one with a head and a full check read).
109 */
110 awaitingBaseline: Schema.optional(Schema.Literals(["all", "checks"])),
111 /**
112 * When the head was first read without any check, until a check shows up or the agent is told
113 * none did. Null once either happened; absent on watches saved before it existed.
114 */
115 checksAwaitedSince: Schema.optional(Schema.NullOr(IsoDateTime)),
116 /**
117 * Whether the host was still running checks on the head at the last read. Only then does the
118 * watch keep its thread waiting; absent on watches not read since it existed.
119 */
120 checksPending: Schema.optional(Schema.Boolean),
121});
122export type ThreadPullRequestWatch = typeof ThreadPullRequestWatch.Type;
123​
124export const ThreadPullRequestLink = Schema.Struct({
125 ...ThreadPullRequestKey.fields,
126 url: TrimmedNonEmptyString,
127 /** An actual browser or clone URL; older agent display URLs may be synthesized. */
128 repositoryWebUrl: Schema.optional(TrimmedNonEmptyString),
129 source: ThreadPullRequestLinkSource,
130 linkedAt: IsoDateTime,
131 snapshot: Schema.NullOr(ThreadPullRequestSnapshot),
132 stack: Schema.NullOr(ThreadPullRequestStack),
133 watch: Schema.optional(ThreadPullRequestWatch),
134 /** Resume from the ended watch to avoid duplicate notifications. */
135 endedWatch: Schema.optional(ThreadPullRequestWatch),
136});
137export type ThreadPullRequestLink = typeof ThreadPullRequestLink.Type;