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

pullRequest.ts

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