Open History to see the last commit
1import * as Schema from "effect/Schema";
2
3import {
4 IsoDateTime,
5 NonNegativeInt,
6 PositiveInt,
7 ProjectId,
8 TrimmedNonEmptyString,
9} from "./baseSchemas.ts";
10import {
11 PullRequestActor,
12 PullRequestChecksState,
13 PullRequestMergeability,
14 PullRequestReviewDecision,
15 PullRequestState,
16} from "./pullRequest.ts";
17
18/**
19 * Legacy single-PR link. Still emitted as the thread's derived current pull
20 * request (see `@t3tools/shared/threadPullRequests`) so clients from before
21 * `pullRequests` keep working independently of their release schedule.
22 */
23export const ThreadLinkedPullRequest = Schema.Struct({
24 projectId: ProjectId,
25 repository: TrimmedNonEmptyString,
26 number: PositiveInt,
27 url: TrimmedNonEmptyString,
28});
29export type ThreadLinkedPullRequest = typeof ThreadLinkedPullRequest.Type;
30
31/** Who created a thread ↔ pull request link. `stack-dismissed` is a tombstone
32 * for a native-stack member the user unlinked, so the sync reactor does not
33 * re-add it; clients hide it. */
34export const ThreadPullRequestLinkSource = Schema.Literals([
35 "manual",
36 "created",
37 "agent",
38 "stack",
39 "stack-dismissed",
40]);
41export type ThreadPullRequestLinkSource = typeof ThreadPullRequestLinkSource.Type;
42
43/**
44 * Host state persisted on a link by the sync reactor; null until first sync. The overview
45 * fields are optional: a host whose cheap read lacks them leaves them out, and snapshots
46 * written before they existed still decode.
47 */
48export const ThreadPullRequestSnapshot = Schema.Struct({
49 state: PullRequestState,
50 title: TrimmedNonEmptyString,
51 headBranch: TrimmedNonEmptyString,
52 baseBranch: TrimmedNonEmptyString,
53 isDraft: Schema.Boolean,
54 updatedAt: Schema.NullOr(IsoDateTime),
55 syncedAt: IsoDateTime,
56 closedAt: Schema.optional(Schema.NullOr(Schema.String)),
57 mergedAt: Schema.optional(Schema.NullOr(Schema.String)),
58 author: Schema.optional(Schema.NullOr(PullRequestActor)),
59 additions: Schema.optional(NonNegativeInt),
60 deletions: Schema.optional(NonNegativeInt),
61 changedFiles: Schema.optional(NonNegativeInt),
62 reviewDecision: Schema.optional(Schema.NullOr(PullRequestReviewDecision)),
63 checksState: Schema.optional(Schema.NullOr(PullRequestChecksState)),
64 mergeability: Schema.optional(PullRequestMergeability),
65});
66export type ThreadPullRequestSnapshot = typeof ThreadPullRequestSnapshot.Type;
67
68export const ThreadPullRequestStackLayer = Schema.Struct({
69 number: PositiveInt,
70 headBranch: TrimmedNonEmptyString,
71 state: PullRequestState,
72});
73export type ThreadPullRequestStackLayer = typeof ThreadPullRequestStackLayer.Type;
74
75/** A host-native stack the pull request belongs to. Layers run bottom to top. */
76export const ThreadPullRequestStack = Schema.Struct({
77 kind: Schema.Literal("native"),
78 id: TrimmedNonEmptyString,
79 number: PositiveInt,
80 url: TrimmedNonEmptyString,
81 base: TrimmedNonEmptyString,
82 layers: Schema.Array(ThreadPullRequestStackLayer),
83});
84export type ThreadPullRequestStack = typeof ThreadPullRequestStack.Type;
85
86/** Identity of a pull request as a thread link sees it: host-level, so the
87 * same PR linked from two projects (or two environments) compares equal. */
88export const ThreadPullRequestKey = Schema.Struct({
89 host: TrimmedNonEmptyString,
90 repository: TrimmedNonEmptyString,
91 number: PositiveInt,
92});
93export type ThreadPullRequestKey = typeof ThreadPullRequestKey.Type;
94
95/**
96 * Present while the server watches the pull request for its thread. The server wakes the
97 * thread's agent when checks finish on the head commit, someone else comments, or the branch
98 * starts to conflict. The other fields record what the agent was last told, so each change is
99 * reported once.
100 */
101export const ThreadPullRequestWatch = Schema.Struct({
102 startedAt: IsoDateTime,
103 /** Head commit at the last pass; null where the host does not report one. */
104 headSha: Schema.NullOr(TrimmedNonEmptyString),
105 /** Failed checks on that commit the agent was told about; a rerun that fails again is news. */
106 failedChecks: Schema.Array(TrimmedNonEmptyString),
107 /** The agent was told the required checks on that commit passed. */
108 passed: Schema.Boolean,
109 /** Remarks from others created up to this host time were reported. */
110 remarksThrough: IsoDateTime,
111 /** Remarks created exactly at `remarksThrough` that were reported, so a late one still counts. */
112 remarkIds: Schema.Array(TrimmedNonEmptyString),
113 conflicting: Schema.Boolean,
114 /** Comment-only wakes in a row. Watching stops at a limit, so bots cannot loop it. */
115 wakes: NonNegativeInt,
116});
117export type ThreadPullRequestWatch = typeof ThreadPullRequestWatch.Type;
118
119export const ThreadPullRequestLink = Schema.Struct({
120 ...ThreadPullRequestKey.fields,
121 url: TrimmedNonEmptyString,
122 source: ThreadPullRequestLinkSource,
123 linkedAt: IsoDateTime,
124 snapshot: Schema.NullOr(ThreadPullRequestSnapshot),
125 stack: Schema.NullOr(ThreadPullRequestStack),
126 watch: Schema.optional(ThreadPullRequestWatch),
127});
128export type ThreadPullRequestLink = typeof ThreadPullRequestLink.Type;