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

pullRequest.ts

969 lines36.1 KB

1import * as Schema from "effect/Schema";
2import * as Effect from "effect/Effect";
3import * as HttpServerRespondable from "effect/http/HttpServerRespondable";
4import * as HttpServerResponse from "effect/http/HttpServerResponse";
5​
6import {
7 ForwardCompatibleArray,
8 IsoDateTime,
9 NonNegativeInt,
10 PositiveInt,
11 ProjectId,
12 ThreadId,
13 TrimmedNonEmptyString,
14} from "./baseSchemas.ts";
15import { SourceControlProviderKind } from "./sourceControl.ts";
16​
17export const PullRequestInvolvement = Schema.Literals(["all", "reviewing", "authored"]);
18export type PullRequestInvolvement = typeof PullRequestInvolvement.Type;
19​
20export const PullRequestState = Schema.Literals(["open", "closed", "merged"]);
21export type PullRequestState = typeof PullRequestState.Type;
22​
23export const PullRequestListState = Schema.Literals(["all", "open", "closed", "merged"]);
24export type PullRequestListState = typeof PullRequestListState.Type;
25​
26export const PullRequestReviewDecision = Schema.Literals([
27 "approved",
28 "changes-requested",
29 "review-required",
30]);
31export type PullRequestReviewDecision = typeof PullRequestReviewDecision.Type;
32​
33const PullRequestQualifierValue = TrimmedNonEmptyString.check(Schema.isMaxLength(200));
34const PullRequestQualifierValues = Schema.Array(PullRequestQualifierValue).check(
35 Schema.isMaxLength(10),
36);
37​
38export const PullRequestListFilters = Schema.Struct({
39 draft: Schema.optional(Schema.Literals(["only", "hide"])),
40 review: Schema.optional(
41 Schema.Literals(["approved", "changes-requested", "review-required", "none"]),
42 ),
43 checks: Schema.optional(Schema.Literals(["passing", "failing"])),
44 /**
45 * Labels as GitHub's own search reads them: each group is one `label:` qualifier, a row must
46 * satisfy every group, and a group holding several names is satisfied by any one of them —
47 * `label:size:S,size:XS` finds either size.
48 */
49 labels: Schema.optional(Schema.Array(PullRequestQualifierValues).check(Schema.isMaxLength(10))),
50 excludedLabels: Schema.optional(PullRequestQualifierValues),
51 author: Schema.optional(PullRequestQualifierValue),
52});
53export type PullRequestListFilters = typeof PullRequestListFilters.Type;
54​
55export const PullRequestChecksState = Schema.Literals(["passing", "failing", "pending"]);
56export type PullRequestChecksState = typeof PullRequestChecksState.Type;
57​
58export const PullRequestMergeability = Schema.Literals(["mergeable", "conflicting", "unknown"]);
59export type PullRequestMergeability = typeof PullRequestMergeability.Type;
60​
61export const PullRequestMergeMethod = Schema.Literals(["merge", "squash", "rebase"]);
62export type PullRequestMergeMethod = typeof PullRequestMergeMethod.Type;
63​
64export const PullRequestAction = Schema.Literals([
65 "merge",
66 "ready",
67 "draft",
68 "close",
69 "reopen",
70 "delete-branch",
71 "update-branch",
72 "enable-auto-merge",
73 "disable-auto-merge",
74 "revert",
75 "approve-workflows",
76]);
77export type PullRequestAction = typeof PullRequestAction.Type;
78​
79export const PullRequestUpdateMethod = Schema.Literals(["merge", "rebase"]);
80export type PullRequestUpdateMethod = typeof PullRequestUpdateMethod.Type;
81​
82export const PullRequestBaseComparison = Schema.Literals(["up-to-date", "behind", "unknown"]);
83export type PullRequestBaseComparison = typeof PullRequestBaseComparison.Type;
84​
85export const PullRequestActor = Schema.Struct({
86 isBot: Schema.optional(Schema.Boolean),
87 login: TrimmedNonEmptyString,
88 name: Schema.NullOr(Schema.String),
89 avatarUrl: Schema.NullOr(Schema.String),
90});
91export type PullRequestActor = typeof PullRequestActor.Type;
92​
93export const PullRequestLabel = Schema.Struct({
94 name: TrimmedNonEmptyString,
95 color: Schema.NullOr(Schema.String),
96});
97export type PullRequestLabel = typeof PullRequestLabel.Type;
98​
99export const PullRequestCheckStatus = Schema.Literals([
100 "pending",
101 "action-required",
102 "success",
103 "failure",
104 "skipped",
105 "neutral",
106 "cancelled",
107]);
108export type PullRequestCheckStatus = typeof PullRequestCheckStatus.Type;
109​
110export const PullRequestCheck = Schema.Struct({
111 name: TrimmedNonEmptyString,
112 status: PullRequestCheckStatus,
113 description: Schema.NullOr(Schema.String),
114 url: Schema.NullOr(Schema.String),
115 required: Schema.optional(Schema.Boolean),
116});
117export type PullRequestCheck = typeof PullRequestCheck.Type;
118​
119export const PullRequestReactionContent = Schema.Literals([
120 "thumbs-up",
121 "thumbs-down",
122 "laugh",
123 "hooray",
124 "confused",
125 "heart",
126 "rocket",
127 "eyes",
128]);
129export type PullRequestReactionContent = typeof PullRequestReactionContent.Type;
130​
131export const PullRequestReaction = Schema.Struct({
132 content: PullRequestReactionContent,
133 count: PositiveInt,
134 /**
135 * When `viewerHasReacted` is true, the viewer's own login is left out of this list — the
136 * page names them "You" instead — but `count` still counts them along with everyone else.
137 */
138 actors: Schema.Array(TrimmedNonEmptyString),
139 viewerHasReacted: Schema.Boolean,
140});
141export type PullRequestReaction = typeof PullRequestReaction.Type;
142​
143export const PullRequestCommentKind = Schema.Literals([
144 "issue-comment",
145 "review-comment",
146 "review",
147]);
148export type PullRequestCommentKind = typeof PullRequestCommentKind.Type;
149​
150export const PullRequestComment = Schema.Struct({
151 id: TrimmedNonEmptyString,
152 kind: PullRequestCommentKind,
153 author: Schema.NullOr(PullRequestActor),
154 body: Schema.String,
155 createdAt: IsoDateTime,
156 editedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
157 url: Schema.NullOr(Schema.String),
158 path: Schema.NullOr(Schema.String),
159 reviewState: Schema.NullOr(Schema.String),
160 reactions: Schema.optional(Schema.Array(PullRequestReaction)),
161 canEdit: Schema.optional(Schema.Boolean),
162});
163export type PullRequestComment = typeof PullRequestComment.Type;
164​
165export const PullRequestDiffSide = Schema.Literals(["left", "right"]);
166export type PullRequestDiffSide = typeof PullRequestDiffSide.Type;
167​
168export const PullRequestReviewVerdict = Schema.Literals(["comment", "approve", "request-changes"]);
169export type PullRequestReviewVerdict = typeof PullRequestReviewVerdict.Type;
170​
171export const PullRequestThreadComment = Schema.Struct({
172 id: TrimmedNonEmptyString,
173 author: Schema.NullOr(PullRequestActor),
174 body: Schema.String,
175 createdAt: IsoDateTime,
176 editedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
177 url: Schema.NullOr(Schema.String),
178 reactions: Schema.optional(Schema.Array(PullRequestReaction)),
179 canEdit: Schema.optional(Schema.Boolean),
180});
181export type PullRequestThreadComment = typeof PullRequestThreadComment.Type;
182​
183export const PullRequestReviewThread = Schema.Struct({
184 id: TrimmedNonEmptyString,
185 path: TrimmedNonEmptyString,
186 line: Schema.NullOr(PositiveInt),
187 side: PullRequestDiffSide,
188 isResolved: Schema.Boolean,
189 isOutdated: Schema.Boolean,
190 comments: Schema.Array(PullRequestThreadComment),
191 commentCount: Schema.optional(NonNegativeInt),
192 nextCommentsCursor: Schema.optional(TrimmedNonEmptyString),
193 /**
194 * It can only narrow the reader's repository-wide `resolve` permission, never widen
195 * it. Absent where the host doesn't say per thread.
196 */
197 canResolve: Schema.optional(Schema.Boolean),
198});
199export type PullRequestReviewThread = typeof PullRequestReviewThread.Type;
200​
201export const PullRequestReviewerKind = Schema.Literals(["user", "team"]);
202export type PullRequestReviewerKind = typeof PullRequestReviewerKind.Type;
203​
204export const PullRequestReviewerCandidate = Schema.Struct({
205 ...PullRequestActor.fields,
206 id: TrimmedNonEmptyString,
207 kind: PullRequestReviewerKind,
208 isRequested: Schema.Boolean,
209});
210export type PullRequestReviewerCandidate = typeof PullRequestReviewerCandidate.Type;
211​
212export const PullRequestReviewerCandidateList = Schema.Struct({
213 candidates: Schema.Array(PullRequestReviewerCandidate),
214 truncated: Schema.Boolean,
215});
216export type PullRequestReviewerCandidateList = typeof PullRequestReviewerCandidateList.Type;
217​
218export const PullRequestLabelCandidate = Schema.Struct({
219 ...PullRequestLabel.fields,
220 description: Schema.NullOr(Schema.String),
221 isApplied: Schema.Boolean,
222});
223export type PullRequestLabelCandidate = typeof PullRequestLabelCandidate.Type;
224​
225export const PullRequestLabelCandidateList = Schema.Struct({
226 candidates: Schema.Array(PullRequestLabelCandidate),
227 truncated: Schema.Boolean,
228});
229export type PullRequestLabelCandidateList = typeof PullRequestLabelCandidateList.Type;
230​
231export const PullRequestCommit = Schema.Struct({
232 oid: TrimmedNonEmptyString,
233 messageHeadline: Schema.String,
234 committedDate: IsoDateTime,
235 additions: Schema.optional(NonNegativeInt),
236 deletions: Schema.optional(NonNegativeInt),
237 authors: Schema.optional(Schema.Array(PullRequestActor)),
238});
239export type PullRequestCommit = typeof PullRequestCommit.Type;
240​
241export const PullRequestReviewCapabilities = Schema.Struct({
242 inlineComment: Schema.Boolean,
243 /**
244 * An inline comment can cover a range of lines rather than its last one. Absent, as from a
245 * server that predates it, means one line.
246 */
247 rangeComment: Schema.optional(Schema.Boolean),
248 reply: Schema.Boolean,
249 resolve: Schema.Boolean,
250 verdicts: ForwardCompatibleArray(PullRequestReviewVerdict),
251});
252export type PullRequestReviewCapabilities = typeof PullRequestReviewCapabilities.Type;
253​
254export const PullRequestEditCapabilities = Schema.Struct({
255 changeRequest: Schema.Boolean,
256 comment: Schema.Boolean,
257});
258export type PullRequestEditCapabilities = typeof PullRequestEditCapabilities.Type;
259​
260export const PullRequestReviewerCapabilities = Schema.Struct({
261 request: Schema.Boolean,
262 listCandidates: Schema.Boolean,
263});
264export type PullRequestReviewerCapabilities = typeof PullRequestReviewerCapabilities.Type;
265​
266export const PullRequestViewedFilesStore = Schema.Literals(["host", "environment"]);
267export type PullRequestViewedFilesStore = typeof PullRequestViewedFilesStore.Type;
268​
269export const PullRequestCapabilities = Schema.Struct({
270 diff: Schema.Boolean,
271 comment: Schema.Boolean,
272 actions: ForwardCompatibleArray(PullRequestAction),
273 mergeMethods: ForwardCompatibleArray(PullRequestMergeMethod),
274 deleteBranch: Schema.optional(Schema.Boolean),
275 /**
276 * Absent where it cannot at all, which is every host that has not said otherwise — so a
277 * provider that says nothing offers nothing.
278 */
279 updateMethods: Schema.optional(ForwardCompatibleArray(PullRequestUpdateMethod)),
280 search: Schema.Boolean,
281 reactions: Schema.optional(Schema.Boolean),
282 viewedFiles: Schema.optional(PullRequestViewedFilesStore),
283 review: PullRequestReviewCapabilities,
284 reviewers: PullRequestReviewerCapabilities,
285 edit: Schema.optional(PullRequestEditCapabilities),
286 stacks: Schema.optional(Schema.Boolean),
287 stackActions: Schema.optional(Schema.Boolean),
288 labels: Schema.optional(Schema.Boolean),
289 /**
290 * Every head gets at least one check, so a head that has gone a while without any means none
291 * reported rather than that the repository runs none. Absent means an empty list says nothing.
292 */
293 checksAlwaysReport: Schema.optional(Schema.Boolean),
294});
295export type PullRequestCapabilities = typeof PullRequestCapabilities.Type;
296​
297/**
298 * A permission the host reports nothing about is granted rather than withheld.
299 */
300export const PullRequestViewerPermissions = Schema.Struct({
301 stackRebase: Schema.optional(Schema.Boolean),
302 actions: ForwardCompatibleArray(PullRequestAction),
303 comment: Schema.Boolean,
304 resolve: Schema.Boolean,
305 verdicts: ForwardCompatibleArray(PullRequestReviewVerdict),
306 requestReviewers: Schema.Boolean,
307 updateMethods: Schema.optional(ForwardCompatibleArray(PullRequestUpdateMethod)),
308 labels: Schema.optional(Schema.Boolean),
309 editChangeRequest: Schema.optional(Schema.Boolean),
310});
311export type PullRequestViewerPermissions = typeof PullRequestViewerPermissions.Type;
312​
313export const PullRequestMergeCapabilities = Schema.Struct({
314 merge: Schema.Boolean,
315 squash: Schema.Boolean,
316 rebase: Schema.Boolean,
317});
318export type PullRequestMergeCapabilities = typeof PullRequestMergeCapabilities.Type;
319​
320export const PullRequestStackMembership = Schema.Struct({
321 number: PositiveInt,
322 position: PositiveInt,
323 size: PositiveInt,
324 base: TrimmedNonEmptyString,
325});
326export type PullRequestStackMembership = typeof PullRequestStackMembership.Type;
327​
328export const PullRequestListEntry = Schema.Struct({
329 stack: Schema.optional(PullRequestStackMembership),
330 provider: SourceControlProviderKind,
331 host: TrimmedNonEmptyString,
332 projectId: ProjectId,
333 projectTitle: TrimmedNonEmptyString,
334 repository: TrimmedNonEmptyString,
335 number: PositiveInt,
336 title: TrimmedNonEmptyString,
337 url: TrimmedNonEmptyString,
338 author: Schema.NullOr(PullRequestActor),
339 headBranch: TrimmedNonEmptyString,
340 baseBranch: TrimmedNonEmptyString,
341 state: PullRequestState,
342 isDraft: Schema.Boolean,
343 mergeability: PullRequestMergeability,
344 /**
345 * Zero where the host has not been asked for the counts yet, which on GitHub is every row a
346 * listing hands over: they are read afterwards, through `PullRequestListStatsInput`.
347 */
348 additions: NonNegativeInt,
349 deletions: NonNegativeInt,
350 createdAt: IsoDateTime,
351 updatedAt: IsoDateTime,
352 observedAt: Schema.optional(Schema.Finite),
353 viewerReviewRequested: Schema.Boolean,
354 labels: Schema.Array(PullRequestLabel),
355 reviewDecision: Schema.optional(PullRequestReviewDecision),
356 checksState: Schema.optional(PullRequestChecksState),
357});
358export type PullRequestListEntry = typeof PullRequestListEntry.Type;
359​
360export const PullRequestListCursors = Schema.Record(
361 TrimmedNonEmptyString,
362 TrimmedNonEmptyString.check(Schema.isMaxLength(4096)),
363);
364export type PullRequestListCursors = typeof PullRequestListCursors.Type;
365​
366export const PullRequestListInput = Schema.Struct({
367 state: PullRequestListState,
368 involvement: Schema.optional(PullRequestInvolvement),
369 filters: Schema.optional(PullRequestListFilters),
370 projectId: Schema.optional(ProjectId),
371 projectIds: Schema.optional(Schema.Array(ProjectId).check(Schema.isMaxLength(100))),
372 host: Schema.optional(TrimmedNonEmptyString),
373 limit: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 500 }))),
374 cursors: Schema.optional(PullRequestListCursors),
375 query: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(200))),
376});
377export type PullRequestListInput = typeof PullRequestListInput.Type;
378​
379export const PullRequestProviderSummary = Schema.Struct({
380 host: TrimmedNonEmptyString,
381 kind: SourceControlProviderKind,
382 searchesOnHost: Schema.Boolean,
383 actions: Schema.optional(ForwardCompatibleArray(PullRequestAction)),
384 projectCount: PositiveInt,
385 configured: Schema.Boolean,
386 detail: Schema.NullOr(TrimmedNonEmptyString),
387});
388export type PullRequestProviderSummary = typeof PullRequestProviderSummary.Type;
389​
390export const PullRequestListProjectError = Schema.Struct({
391 projectId: ProjectId,
392 projectTitle: TrimmedNonEmptyString,
393 message: TrimmedNonEmptyString,
394});
395export type PullRequestListProjectError = typeof PullRequestListProjectError.Type;
396​
397export const PullRequestListResult = Schema.Struct({
398 /**
399 * A host that could not be read is absent rather than present-and-undefined, because an
400 * open-keyed record cannot carry an optional value through the JSON codec.
401 */
402 viewers: Schema.Record(TrimmedNonEmptyString, TrimmedNonEmptyString),
403 providers: Schema.Array(PullRequestProviderSummary),
404 /**
405 * A page that appends a continuation sorts what it then holds the same way: a repository's
406 * next slice is older than that repository's last row, but can still be newer than another
407 * repository's.
408 */
409 entries: Schema.Array(PullRequestListEntry),
410 errors: Schema.Array(PullRequestListProjectError),
411 truncated: Schema.Boolean,
412 nextCursors: PullRequestListCursors,
413});
414export type PullRequestListResult = typeof PullRequestListResult.Type;
415​
416export const PullRequestRef = Schema.Struct({
417 projectId: ProjectId,
418 host: Schema.optional(TrimmedNonEmptyString),
419 expectedAccountId: Schema.optional(TrimmedNonEmptyString),
420 allowStale: Schema.optional(Schema.Boolean),
421 repository: TrimmedNonEmptyString,
422 number: PositiveInt,
423});
424export type PullRequestRef = typeof PullRequestRef.Type;
425​
426export const PullRequestRoutingIdentityInput = Schema.Struct({
427 host: TrimmedNonEmptyString,
428});
429export type PullRequestRoutingIdentityInput = typeof PullRequestRoutingIdentityInput.Type;
430​
431export const PullRequestRoutingIdentityResult = Schema.Struct({
432 accountId: TrimmedNonEmptyString,
433 host: TrimmedNonEmptyString,
434 provider: SourceControlProviderKind,
435 viewer: TrimmedNonEmptyString,
436});
437export type PullRequestRoutingIdentityResult = typeof PullRequestRoutingIdentityResult.Type;
438​
439export const PullRequestRoutingResult = Schema.Struct({
440 accountId: TrimmedNonEmptyString,
441 host: TrimmedNonEmptyString,
442 provider: SourceControlProviderKind,
443 viewer: TrimmedNonEmptyString,
444 projectTitle: TrimmedNonEmptyString,
445 workspaceRoot: TrimmedNonEmptyString,
446});
447export type PullRequestRoutingResult = typeof PullRequestRoutingResult.Type;
448​
449export const PullRequestLinkedThreadsResult = Schema.Struct({
450 threads: Schema.Array(
451 Schema.Struct({
452 id: ThreadId,
453 projectId: ProjectId,
454 title: Schema.String,
455 archivedAt: Schema.NullOr(IsoDateTime),
456 }),
457 ),
458});
459export type PullRequestLinkedThreadsResult = typeof PullRequestLinkedThreadsResult.Type;
460​
461export const PullRequestPreview = Schema.Struct({
462 projectId: ProjectId,
463 repository: TrimmedNonEmptyString,
464 number: PositiveInt,
465 title: TrimmedNonEmptyString,
466 url: TrimmedNonEmptyString,
467 author: Schema.NullOr(PullRequestActor),
468 state: PullRequestState,
469 isDraft: Schema.Boolean,
470 createdAt: IsoDateTime,
471});
472export type PullRequestPreview = typeof PullRequestPreview.Type;
473​
474export const PullRequestSummary = Schema.Struct({
475 provider: SourceControlProviderKind,
476 projectId: ProjectId,
477 repository: TrimmedNonEmptyString,
478 number: PositiveInt,
479 title: TrimmedNonEmptyString,
480 url: TrimmedNonEmptyString,
481 state: PullRequestState,
482 isDraft: Schema.optional(Schema.Boolean),
483 headBranch: TrimmedNonEmptyString,
484 baseBranch: TrimmedNonEmptyString,
485 closedAt: Schema.optional(Schema.NullOr(Schema.String)),
486 mergedAt: Schema.optional(Schema.NullOr(Schema.String)),
487 updatedAt: IsoDateTime,
488 observedAt: Schema.optional(Schema.Finite),
489 author: Schema.optional(Schema.NullOr(PullRequestActor)),
490 additions: Schema.optional(NonNegativeInt),
491 deletions: Schema.optional(NonNegativeInt),
492 changedFiles: Schema.optional(NonNegativeInt),
493 reviewDecision: Schema.optional(Schema.NullOr(PullRequestReviewDecision)),
494 checksState: Schema.optional(Schema.NullOr(PullRequestChecksState)),
495 mergeability: Schema.optional(PullRequestMergeability),
496 /** Null when the host says the pull request is in no stack; absent when the read did not ask. */
497 stack: Schema.optional(Schema.NullOr(PullRequestStackMembership)),
498});
499export type PullRequestSummary = typeof PullRequestSummary.Type;
500​
501export const PullRequestStack = Schema.Struct({
502 id: TrimmedNonEmptyString,
503 number: PositiveInt,
504 url: TrimmedNonEmptyString,
505 base: TrimmedNonEmptyString,
506 layers: Schema.Array(
507 Schema.Struct({
508 number: PositiveInt,
509 title: Schema.optional(Schema.String),
510 isDraft: Schema.optional(Schema.Boolean),
511 headSha: Schema.optional(TrimmedNonEmptyString),
512 headBranch: TrimmedNonEmptyString,
513 state: PullRequestState,
514 }),
515 ),
516});
517export type PullRequestStack = typeof PullRequestStack.Type;
518​
519export const PullRequestDiffStat = Schema.Struct({
520 projectId: ProjectId,
521 repository: TrimmedNonEmptyString,
522 number: PositiveInt,
523 additions: NonNegativeInt,
524 deletions: NonNegativeInt,
525});
526export type PullRequestDiffStat = typeof PullRequestDiffStat.Type;
527​
528export const PullRequestListStatsInput = Schema.Struct({
529 refs: Schema.Array(PullRequestRef).check(Schema.isMaxLength(500)),
530});
531export type PullRequestListStatsInput = typeof PullRequestListStatsInput.Type;
532​
533export const PullRequestListStatsResult = Schema.Struct({
534 stats: Schema.Array(PullRequestDiffStat),
535});
536export type PullRequestListStatsResult = typeof PullRequestListStatsResult.Type;
537​
538export const PullRequestFilterOptionKind = Schema.Literals(["labels", "authors"]);
539export type PullRequestFilterOptionKind = typeof PullRequestFilterOptionKind.Type;
540​
541/** Scoped like `PullRequestListInput`, so the options come from the repositories it lists. */
542export const PullRequestFilterOptionsInput = Schema.Struct({
543 kind: PullRequestFilterOptionKind,
544 projectId: Schema.optional(ProjectId),
545 projectIds: Schema.optional(Schema.Array(ProjectId).check(Schema.isMaxLength(100))),
546 host: Schema.optional(TrimmedNonEmptyString),
547 query: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(100))),
548});
549export type PullRequestFilterOptionsInput = typeof PullRequestFilterOptionsInput.Type;
550​
551export const PullRequestFilterOptions = Schema.Struct({
552 labels: Schema.Array(PullRequestLabel),
553 authors: Schema.Array(PullRequestActor),
554 truncated: Schema.Boolean,
555});
556export type PullRequestFilterOptions = typeof PullRequestFilterOptions.Type;
557​
558/**
559 * A separate request rather than a flag on the reads, so an explicit "refresh" one person
560 * presses is the only thing that spends host requests — every ordinary read shares.
561 */
562export const PullRequestInvalidateInput = Schema.Struct({
563 reference: Schema.optional(PullRequestRef),
564 filesViewedOnly: Schema.optional(Schema.Boolean),
565});
566export type PullRequestInvalidateInput = typeof PullRequestInvalidateInput.Type;
567​
568export const PullRequestReportStateInput = Schema.Struct({
569 reference: PullRequestRef,
570 state: PullRequestState,
571 isDraft: Schema.optional(Schema.Boolean),
572});
573export type PullRequestReportStateInput = typeof PullRequestReportStateInput.Type;
574​
575export const PullRequestDetail = Schema.Struct({
576 provider: SourceControlProviderKind,
577 capabilities: PullRequestCapabilities,
578 viewerPermissions: PullRequestViewerPermissions,
579 projectId: ProjectId,
580 projectTitle: TrimmedNonEmptyString,
581 workspaceRoot: TrimmedNonEmptyString,
582 repository: TrimmedNonEmptyString,
583 number: PositiveInt,
584 title: TrimmedNonEmptyString,
585 body: Schema.String,
586 url: TrimmedNonEmptyString,
587 author: Schema.NullOr(PullRequestActor),
588 state: PullRequestState,
589 isDraft: Schema.Boolean,
590 mergeability: PullRequestMergeability,
591 additions: NonNegativeInt,
592 deletions: NonNegativeInt,
593 changedFiles: NonNegativeInt,
594 headBranch: TrimmedNonEmptyString,
595 headRepositoryNameWithOwner: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
596 headSha: Schema.optional(TrimmedNonEmptyString),
597 baseBranch: TrimmedNonEmptyString,
598 createdAt: IsoDateTime,
599 updatedAt: IsoDateTime,
600 observedAt: Schema.optional(Schema.Finite),
601 mergedAt: Schema.NullOr(IsoDateTime),
602 closedAt: Schema.NullOr(IsoDateTime),
603 reviewers: Schema.Array(PullRequestActor),
604 labels: Schema.Array(PullRequestLabel),
605 checks: Schema.Array(PullRequestCheck),
606 mergeCapabilities: PullRequestMergeCapabilities,
607 viewer: Schema.optional(TrimmedNonEmptyString),
608 baseComparison: Schema.optional(PullRequestBaseComparison),
609 behindBy: Schema.optional(NonNegativeInt),
610 /**
611 * Whether the host is already armed to merge this on its own. Absent where the host does not
612 * report it, which is not the same as off: a page that reads silence as "not armed" offers to
613 * arm something that is already armed, and a second arming is a write nobody asked for.
614 */
615 autoMergeEnabled: Schema.optional(Schema.Boolean),
616 autoMergeMethod: Schema.optional(PullRequestMergeMethod),
617 workflowApprovalsRequired: Schema.optional(NonNegativeInt),
618});
619export type PullRequestDetail = typeof PullRequestDetail.Type;
620​
621export const PullRequestChecks = Schema.Struct({
622 observedAt: Schema.optional(Schema.Finite),
623 state: PullRequestState,
624 checks: Schema.Array(PullRequestCheck),
625});
626export type PullRequestChecks = typeof PullRequestChecks.Type;
627​
628export const PullRequestActivity = Schema.Struct({
629 author: Schema.optional(Schema.NullOr(PullRequestActor)),
630 reviewers: Schema.optional(Schema.Array(PullRequestActor)),
631 comments: Schema.Array(PullRequestComment),
632 commentCount: NonNegativeInt,
633 commentsTruncated: Schema.Boolean,
634 reviewThreadsTruncated: Schema.optional(Schema.Boolean),
635 reviewThreads: Schema.Array(PullRequestReviewThread),
636 commits: Schema.Array(PullRequestCommit),
637 reactions: Schema.optional(Schema.Array(PullRequestReaction)),
638});
639export type PullRequestActivity = typeof PullRequestActivity.Type;
640​
641export const PullRequestDetailView = Schema.Struct({
642 ...PullRequestDetail.fields,
643 ...PullRequestActivity.fields,
644 author: Schema.NullOr(PullRequestActor),
645 reviewers: Schema.Array(PullRequestActor),
646});
647export type PullRequestDetailView = typeof PullRequestDetailView.Type;
648​
649/**
650 * A diff arrives a slice at a time, because a large change is more than any host will hand over
651 * at once — GitHub refuses outright past 300 files — and more than a viewer can lay out in one
652 * go.
653 */
654export const PullRequestDiffInput = Schema.Struct({
655 ...PullRequestRef.fields,
656 cursor: Schema.optional(TrimmedNonEmptyString),
657 commit: Schema.optional(TrimmedNonEmptyString),
658});
659export type PullRequestDiffInput = typeof PullRequestDiffInput.Type;
660​
661export const PullRequestOmittedFileStat = Schema.Struct({
662 path: TrimmedNonEmptyString,
663 additions: Schema.Number,
664 deletions: Schema.Number,
665});
666export type PullRequestOmittedFileStat = typeof PullRequestOmittedFileStat.Type;
667​
668export const PullRequestDiffResult = Schema.Struct({
669 patch: Schema.String,
670 /**
671 * Something inside this slice could not be shown — a binary file, or a hunk the host declined
672 * to inline. Not the same as there being more slices, which `nextCursor` answers.
673 */
674 truncated: Schema.Boolean,
675 nextCursor: Schema.NullOr(TrimmedNonEmptyString),
676 omittedFileStats: Schema.optional(Schema.Array(PullRequestOmittedFileStat)),
677});
678export type PullRequestDiffResult = typeof PullRequestDiffResult.Type;
679​
680export const PullRequestDiffFileContentsInput = Schema.Struct({
681 ...PullRequestRef.fields,
682 commit: Schema.optional(TrimmedNonEmptyString),
683 changeType: Schema.Literals(["change", "rename-pure", "rename-changed", "new", "deleted"]),
684 oldPath: TrimmedNonEmptyString,
685 newPath: TrimmedNonEmptyString,
686});
687export type PullRequestDiffFileContentsInput = typeof PullRequestDiffFileContentsInput.Type;
688​
689export const PullRequestDiffFileContentsResult = Schema.Struct({
690 oldContents: Schema.String,
691 newContents: Schema.String,
692});
693export type PullRequestDiffFileContentsResult = typeof PullRequestDiffFileContentsResult.Type;
694​
695const MAX_FILE_PATH_LENGTH = 4096;
696/**
697 * Not trimmed: a leading or trailing space is a legal part of a file's name, and the mark is
698 * keyed by the name the host gave, so trimming files it under a name nothing else uses.
699 */
700const FilePath = Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(MAX_FILE_PATH_LENGTH));
701​
702export const PullRequestFileViewedState = Schema.Literals(["unviewed", "viewed", "dismissed"]);
703export type PullRequestFileViewedState = typeof PullRequestFileViewedState.Type;
704​
705export const PullRequestFileViewed = Schema.Struct({
706 path: FilePath,
707 state: PullRequestFileViewedState,
708});
709export type PullRequestFileViewed = typeof PullRequestFileViewed.Type;
710​
711export const PullRequestFilesViewedResult = Schema.Struct({
712 /** Only the files the host reported a state for. A file missing from this list is unviewed. */
713 files: Schema.Array(PullRequestFileViewed),
714 truncated: Schema.Boolean,
715});
716export type PullRequestFilesViewedResult = typeof PullRequestFilesViewedResult.Type;
717​
718const PullRequestLineCount = Schema.Struct({
719 additions: NonNegativeInt,
720 deletions: NonNegativeInt,
721});
722​
723/**
724 * A change's line counts split by what the changed files are, judged from their paths. Null when
725 * the host gives no per-file counts, or has more files than one read covers: a split of part of
726 * the change would not add up to the totals shown beside it.
727 */
728export const PullRequestChangeBreakdown = Schema.NullOr(
729 Schema.Struct({
730 code: PullRequestLineCount,
731 tests: PullRequestLineCount,
732 mocks: PullRequestLineCount,
733 generated: PullRequestLineCount,
734 // Servers from before the docs split send no key; their docs lines sit in `code`.
735 docs: PullRequestLineCount.pipe(
736 Schema.withDecodingDefault(Effect.succeed({ additions: 0, deletions: 0 })),
737 ),
738 }),
739);
740export type PullRequestChangeBreakdown = typeof PullRequestChangeBreakdown.Type;
741​
742const MAX_FILES_VIEWED_PRESSES = 500;
743​
744export const PullRequestSetFilesViewedInput = Schema.Struct({
745 ...PullRequestRef.fields,
746 files: Schema.Array(
747 Schema.Struct({
748 path: FilePath,
749 viewed: Schema.Boolean,
750 }),
751 ).check(Schema.isMaxLength(MAX_FILES_VIEWED_PRESSES)),
752});
753export type PullRequestSetFilesViewedInput = typeof PullRequestSetFilesViewedInput.Type;
754​
755export const PullRequestStackHead = Schema.Struct({
756 number: PositiveInt,
757 headSha: TrimmedNonEmptyString,
758});
759export type PullRequestStackHead = typeof PullRequestStackHead.Type;
760​
761export const PullRequestActionInput = Schema.Struct({
762 /** Native stack scope; only send to environments advertising pullRequestStackActions. */
763 stackNumber: Schema.optional(PositiveInt),
764 expectedStackHeads: Schema.optional(Schema.Array(PullRequestStackHead)),
765 ...PullRequestRef.fields,
766 action: PullRequestAction,
767 mergeMethod: Schema.optional(PullRequestMergeMethod),
768 updateMethod: Schema.optional(PullRequestUpdateMethod),
769});
770export type PullRequestActionInput = typeof PullRequestActionInput.Type;
771​
772// Not trimmed: the body is markdown, where leading spaces open a code block and two trailing
773// spaces are a line break.
774const CommentBody = Schema.String.check(Schema.isNonEmpty()).check(Schema.isMaxLength(65_536));
775​
776export const PullRequestCommentInput = Schema.Struct({
777 ...PullRequestRef.fields,
778 body: CommentBody,
779});
780export type PullRequestCommentInput = typeof PullRequestCommentInput.Type;
781​
782export const PullRequestUpdateInput = Schema.Struct({
783 ...PullRequestRef.fields,
784 title: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(1024))),
785 body: Schema.optional(Schema.String.check(Schema.isMaxLength(65_536))),
786});
787export type PullRequestUpdateInput = typeof PullRequestUpdateInput.Type;
788​
789/**
790 * The kind travels beside the id because an id alone does not say which endpoint
791 * addresses it: GitHub rewrites a comment on the conversation and a comment on a line
792 * through two different mutations.
793 */
794export const PullRequestCommentUpdateInput = Schema.Struct({
795 ...PullRequestRef.fields,
796 commentId: TrimmedNonEmptyString,
797 kind: Schema.Literals(["issue-comment", "review-comment"]),
798 body: CommentBody,
799});
800export type PullRequestCommentUpdateInput = typeof PullRequestCommentUpdateInput.Type;
801​
802export const PullRequestReviewPosition = Schema.Union([
803 Schema.Struct({
804 kind: Schema.Literal("added"),
805 newLine: PositiveInt,
806 }),
807 Schema.Struct({
808 kind: Schema.Literal("deleted"),
809 oldLine: PositiveInt,
810 }),
811 Schema.Struct({
812 kind: Schema.Literal("context"),
813 oldLine: PositiveInt,
814 newLine: PositiveInt,
815 side: PullRequestDiffSide,
816 }),
817]);
818export type PullRequestReviewPosition = typeof PullRequestReviewPosition.Type;
819​
820export const PullRequestReviewCommentDraft = Schema.Struct({
821 path: TrimmedNonEmptyString,
822 /**
823 * GitLab resolves a position against both sides of the diff, so a comment on a renamed file
824 * needs both names; the hosts that address a comment by one path ignore this.
825 */
826 oldPath: Schema.optional(TrimmedNonEmptyString),
827 position: PullRequestReviewPosition,
828 /**
829 * The first line of a comment on a range, which ends at `position`. Sent only to a host whose
830 * capabilities include `review.rangeComment`.
831 */
832 startPosition: Schema.optional(PullRequestReviewPosition),
833 body: CommentBody,
834});
835export type PullRequestReviewCommentDraft = typeof PullRequestReviewCommentDraft.Type;
836​
837export const PullRequestSubmitReviewInput = Schema.Struct({
838 ...PullRequestRef.fields,
839 verdict: PullRequestReviewVerdict,
840 body: Schema.String.check(Schema.isMaxLength(65_536)),
841 comments: Schema.Array(PullRequestReviewCommentDraft),
842});
843export type PullRequestSubmitReviewInput = typeof PullRequestSubmitReviewInput.Type;
844​
845export const PullRequestThreadCommentsInput = Schema.Struct({
846 ...PullRequestRef.fields,
847 threadId: TrimmedNonEmptyString,
848 cursor: TrimmedNonEmptyString,
849});
850export type PullRequestThreadCommentsInput = typeof PullRequestThreadCommentsInput.Type;
851​
852export const PullRequestThreadCommentsResult = Schema.Struct({
853 comments: Schema.Array(PullRequestThreadComment),
854 nextCursor: Schema.NullOr(TrimmedNonEmptyString),
855});
856export type PullRequestThreadCommentsResult = typeof PullRequestThreadCommentsResult.Type;
857​
858export const PullRequestThreadReplyInput = Schema.Struct({
859 ...PullRequestRef.fields,
860 threadId: TrimmedNonEmptyString,
861 body: CommentBody,
862});
863export type PullRequestThreadReplyInput = typeof PullRequestThreadReplyInput.Type;
864​
865export const PullRequestThreadResolutionInput = Schema.Struct({
866 ...PullRequestRef.fields,
867 threadId: TrimmedNonEmptyString,
868 resolved: Schema.Boolean,
869});
870export type PullRequestThreadResolutionInput = typeof PullRequestThreadResolutionInput.Type;
871​
872export const PullRequestReactionInput = Schema.Struct({
873 ...PullRequestRef.fields,
874 subjectId: Schema.optional(TrimmedNonEmptyString),
875 content: PullRequestReactionContent,
876 reacted: Schema.Boolean,
877});
878export type PullRequestReactionInput = typeof PullRequestReactionInput.Type;
879​
880export const PullRequestReviewerRequestInput = Schema.Struct({
881 ...PullRequestRef.fields,
882 reviewers: Schema.Array(
883 Schema.Struct({ id: TrimmedNonEmptyString, kind: PullRequestReviewerKind }),
884 ).check(Schema.isMinLength(1), Schema.isMaxLength(25)),
885 requested: Schema.Boolean,
886});
887export type PullRequestReviewerRequestInput = typeof PullRequestReviewerRequestInput.Type;
888​
889export const PullRequestLabelChangeInput = Schema.Struct({
890 ...PullRequestRef.fields,
891 labels: Schema.Array(TrimmedNonEmptyString).check(Schema.isMinLength(1), Schema.isMaxLength(25)),
892 applied: Schema.Boolean,
893});
894export type PullRequestLabelChangeInput = typeof PullRequestLabelChangeInput.Type;
895​
896/**
897 * The names keep their `cli-` prefix for wire compatibility; for a host read with a credential
898 * rather than a tool they mean "no credential" and "a refused credential".
899 */
900export const PullRequestUnavailableReason = Schema.Literals([
901 "cli-missing",
902 "cli-unauthenticated",
903 "provider-unsupported",
904]);
905export type PullRequestUnavailableReason = typeof PullRequestUnavailableReason.Type;
906​
907/**
908 * `author:me` names whoever is signed in to the host being read, GitHub's `@me` spelled either
909 * way. A host's own search would answer it, but the page and the server both re-check an author
910 * against the row's login, so the name is resolved before either comparison rather than being
911 * matched as the literal login "me".
912 */
913export function resolvePullRequestAuthorFilter(
914 author: string,
915 viewer: string | null | undefined,
916): string {
917 const trimmed = author.trim();
918 if (!/^@?me$/i.test(trimmed)) return trimmed;
919 return viewer === null || viewer === undefined || viewer.trim().length === 0 ? trimmed : viewer;
921​
922export class PullRequestUnavailableError extends Schema.TaggedError<PullRequestUnavailableError>()(
923 "PullRequestUnavailableError",
924 {
925 reason: PullRequestUnavailableReason,
926 provider: Schema.optional(SourceControlProviderKind),
927 /**
928 * What the host needs on the server, in its own words. Absent from older servers, which
929 * shipped no such field, and for a host that names nothing.
930 */
931 requirement: Schema.optional(TrimmedNonEmptyString),
932 cause: Schema.optional(Schema.Defect()),
933 },
934 { httpApiStatus: 503 },
935) {
936 [HttpServerRespondable.symbol]() {
937 return HttpServerResponse.schemaJson(PullRequestUnavailableError)(this, { status: 503 });
938 }
939​
940 override get message(): string {
941 switch (this.reason) {
942 case "cli-missing":
943 return this.requirement ?? "The tool this host is read through is not installed or set up.";
944 case "cli-unauthenticated":
945 return this.requirement ?? "This host has no working credentials.";
946 case "provider-unsupported":
947 return "Change requests cannot be browsed for this project's host yet.";
948 }
949 }
951​
952export class PullRequestOperationError extends Schema.TaggedError<PullRequestOperationError>()(
953 "PullRequestOperationError",
954 {
955 operation: Schema.String,
956 detail: TrimmedNonEmptyString,
957 reason: Schema.optional(Schema.Literal("not-found")),
958 cause: Schema.optional(Schema.Defect()),
959 },
960 { httpApiStatus: 502 },
961) {
962 [HttpServerRespondable.symbol]() {
963 return HttpServerResponse.schemaJson(PullRequestOperationError)(this, { status: 502 });
964 }
965​
966 override get message(): string {
967 return `Pull request operation ${this.operation} failed: ${this.detail}`;
968 }