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

threadPullRequest.ts

114 lines4.0 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` is a tombstone
28 * for a native-stack member the user unlinked, so the sync reactor does not
29 * re-add it; clients hide it. */
30export const ThreadPullRequestLinkSource = Schema.Literals([
31 "manual",
32 "created",
33 "agent",
34 "stack",
35 "stack-dismissed",
36]);
37export type ThreadPullRequestLinkSource = typeof ThreadPullRequestLinkSource.Type;
38​
39export const ThreadPullRequestSnapshot = Schema.Struct({
40 state: PullRequestState,
41 title: TrimmedNonEmptyString,
42 headBranch: TrimmedNonEmptyString,
43 baseBranch: TrimmedNonEmptyString,
44 isDraft: Schema.Boolean,
45 updatedAt: Schema.NullOr(IsoDateTime),
46 syncedAt: IsoDateTime,
47 closedAt: Schema.optional(Schema.NullOr(Schema.String)),
48 mergedAt: Schema.optional(Schema.NullOr(Schema.String)),
49 author: Schema.optional(Schema.NullOr(PullRequestActor)),
50 additions: Schema.optional(NonNegativeInt),
51 deletions: Schema.optional(NonNegativeInt),
52 changedFiles: Schema.optional(NonNegativeInt),
53 reviewDecision: Schema.optional(Schema.NullOr(PullRequestReviewDecision)),
54 checksState: Schema.optional(Schema.NullOr(PullRequestChecksState)),
55 mergeability: Schema.optional(PullRequestMergeability),
56});
57export type ThreadPullRequestSnapshot = typeof ThreadPullRequestSnapshot.Type;
58​
59export const ThreadPullRequestStackLayer = Schema.Struct({
60 number: PositiveInt,
61 headBranch: TrimmedNonEmptyString,
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: TrimmedNonEmptyString,
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 remarksThrough: IsoDateTime,
93 /** Remarks created exactly at `remarksThrough` that were reported, so a late one still counts. */
94 remarkIds: Schema.Array(TrimmedNonEmptyString),
95 conflicting: Schema.Boolean,
96 /** Comment-only wakes in a row. Watching stops at a limit, so bots cannot loop it. */
97 wakes: NonNegativeInt,
98});
99export type ThreadPullRequestWatch = typeof ThreadPullRequestWatch.Type;
100​
101export const ThreadPullRequestLink = Schema.Struct({
102 ...ThreadPullRequestKey.fields,
103 url: TrimmedNonEmptyString,
104 /** An actual browser or clone URL; older agent display URLs may be synthesized. */
105 repositoryWebUrl: Schema.optional(TrimmedNonEmptyString),
106 source: ThreadPullRequestLinkSource,
107 linkedAt: IsoDateTime,
108 snapshot: Schema.NullOr(ThreadPullRequestSnapshot),
109 stack: Schema.NullOr(ThreadPullRequestStack),
110 watch: Schema.optional(ThreadPullRequestWatch),
111 /** The last watch as it ended. Watching again starts from it, so the thread is not told twice. */
112 endedWatch: Schema.optional(ThreadPullRequestWatch),
113});
114export type ThreadPullRequestLink = typeof ThreadPullRequestLink.Type;