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

pullRequest.ts

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