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

threadPullRequest.ts

103 lines3.6 KB

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​
95export const ThreadPullRequestLink = Schema.Struct({
96 ...ThreadPullRequestKey.fields,
97 url: TrimmedNonEmptyString,
98 source: ThreadPullRequestLinkSource,
99 linkedAt: IsoDateTime,
100 snapshot: Schema.NullOr(ThreadPullRequestSnapshot),
101 stack: Schema.NullOr(ThreadPullRequestStack),
102});
103export type ThreadPullRequestLink = typeof ThreadPullRequestLink.Type;