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

threadPullRequest.ts

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