Open History to see the last commit
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 /** Checks still pending when required ones passed early, owed one wake once all settle. */
93 owedChecks: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
94 remarksThrough: IsoDateTime,
95 /** Remarks created exactly at `remarksThrough` that were reported, so a late one still counts. */
96 remarkIds: Schema.Array(TrimmedNonEmptyString),
97 conflicting: Schema.Boolean,
98 /** Comment-only wakes in a row. Watching stops at a limit, so bots cannot loop it. */
99 wakes: NonNegativeInt,
100 /**
101 * When the head was first read without any check, until a check shows up or the agent is told
102 * none did. Null once either happened; absent on watches saved before it existed.
103 */
104 checksAwaitedSince: Schema.optional(Schema.NullOr(IsoDateTime)),
105});
106export type ThreadPullRequestWatch = typeof ThreadPullRequestWatch.Type;
107
108export const ThreadPullRequestLink = Schema.Struct({
109 ...ThreadPullRequestKey.fields,
110 url: TrimmedNonEmptyString,
111 /** An actual browser or clone URL; older agent display URLs may be synthesized. */
112 repositoryWebUrl: Schema.optional(TrimmedNonEmptyString),
113 source: ThreadPullRequestLinkSource,
114 linkedAt: IsoDateTime,
115 snapshot: Schema.NullOr(ThreadPullRequestSnapshot),
116 stack: Schema.NullOr(ThreadPullRequestStack),
117 watch: Schema.optional(ThreadPullRequestWatch),
118 /** The last watch as it ended. Watching again starts from it, so the thread is not told twice. */
119 endedWatch: Schema.optional(ThreadPullRequestWatch),
120});
121export type ThreadPullRequestLink = typeof ThreadPullRequestLink.Type;