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

pullRequest.ts

976 lines37.4 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 /**
255 * Reviewer candidates take a `query` the host matches past the first page. Absent, as from a
256 * server that predates it, means the client narrows the loaded page itself.
257 */
258 searchCandidates: Schema.optional(Schema.Boolean),
259});
260export type PullRequestReviewerCapabilities = typeof PullRequestReviewerCapabilities.Type;
261​
262export const PullRequestViewedFilesStore = Schema.Literals(["host", "environment"]);
263export type PullRequestViewedFilesStore = typeof PullRequestViewedFilesStore.Type;
264​
265/** `#` references issues (and GitHub pull requests); `!` references GitLab merge requests. */
266export const PullRequestReferenceSigil = Schema.Literals(["#", "!"]);
267export type PullRequestReferenceSigil = typeof PullRequestReferenceSigil.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 /** The host searches the repository's users, so composers can complete `@login`. */
290 mentions: Schema.optional(Schema.Boolean),
291 /** The sigils whose issue and change request references composers can complete. */
292 referenceSigils: Schema.optional(ForwardCompatibleArray(PullRequestReferenceSigil)),
293 /**
294 * Every head gets at least one check, so a head that has gone a while without any means none
295 * reported rather than that the repository runs none. Absent means an empty list says nothing.
296 */
297 checksAlwaysReport: Schema.optional(Schema.Boolean),
298});
299export type PullRequestCapabilities = typeof PullRequestCapabilities.Type;
300​
301/** Unreported host permissions are granted. */
302export const PullRequestViewerPermissions = Schema.Struct({
303 stackRebase: Schema.optional(Schema.Boolean),
304 actions: ForwardCompatibleArray(PullRequestAction),
305 comment: Schema.Boolean,
306 resolve: Schema.Boolean,
307 verdicts: ForwardCompatibleArray(PullRequestReviewVerdict),
308 requestReviewers: Schema.Boolean,
309 updateMethods: Schema.optional(ForwardCompatibleArray(PullRequestUpdateMethod)),
310 labels: Schema.optional(Schema.Boolean),
311 editChangeRequest: Schema.optional(Schema.Boolean),
312 maintainerEdits: Schema.optional(Schema.Boolean),
313});
314export type PullRequestViewerPermissions = typeof PullRequestViewerPermissions.Type;
315​
316export const PullRequestMergeCapabilities = Schema.Struct({
317 merge: Schema.Boolean,
318 squash: Schema.Boolean,
319 rebase: Schema.Boolean,
320});
321export type PullRequestMergeCapabilities = typeof PullRequestMergeCapabilities.Type;
322​
323export const PullRequestStackMembership = Schema.Struct({
324 number: PositiveInt,
325 position: PositiveInt,
326 size: PositiveInt,
327 base: TrimmedNonEmptyString,
328});
329export type PullRequestStackMembership = typeof PullRequestStackMembership.Type;
330​
331export const PullRequestListEntry = Schema.Struct({
332 stack: Schema.optional(PullRequestStackMembership),
333 provider: SourceControlProviderKind,
334 host: TrimmedNonEmptyString,
335 projectId: ProjectId,
336 projectTitle: TrimmedNonEmptyString,
337 repository: TrimmedNonEmptyString,
338 number: PositiveInt,
339 title: TrimmedNonEmptyString,
340 url: TrimmedNonEmptyString,
341 author: Schema.NullOr(PullRequestActor),
342 headBranch: TrimmedNonEmptyString,
343 baseBranch: TrimmedNonEmptyString,
344 state: PullRequestState,
345 isDraft: Schema.Boolean,
346 mergeability: PullRequestMergeability,
347 /** Zero until fetched through `PullRequestListStatsInput`; GitHub listings omit counts. */
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 /** Unreadable hosts are absent; JSON codecs reject optional record values. */
399 viewers: Schema.Record(TrimmedNonEmptyString, TrimmedNonEmptyString),
400 providers: Schema.Array(PullRequestProviderSummary),
401 /** Re-sort after appending: one repository's older slice may outrank another's existing rows. */
402 entries: Schema.Array(PullRequestListEntry),
403 errors: Schema.Array(PullRequestListProjectError),
404 truncated: Schema.Boolean,
405 nextCursors: PullRequestListCursors,
406});
407export type PullRequestListResult = typeof PullRequestListResult.Type;
408​
409export const PullRequestRef = Schema.Struct({
410 projectId: ProjectId,
411 host: Schema.optional(TrimmedNonEmptyString),
412 expectedAccountId: Schema.optional(TrimmedNonEmptyString),
413 allowStale: Schema.optional(Schema.Boolean),
414 repository: TrimmedNonEmptyString,
415 number: PositiveInt,
416});
417export type PullRequestRef = typeof PullRequestRef.Type;
418​
419/** `query` asks the host for matches past the first page of candidates. */
420export const PullRequestReviewerCandidatesInput = Schema.Struct({
421 ...PullRequestRef.fields,
422 query: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(100))),
423});
424export type PullRequestReviewerCandidatesInput = typeof PullRequestReviewerCandidatesInput.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 settled: Schema.optionalKey(Schema.Boolean),
457 }),
458 ),
459});
460export type PullRequestLinkedThreadsResult = typeof PullRequestLinkedThreadsResult.Type;
461​
462export const PullRequestPreview = Schema.Struct({
463 projectId: ProjectId,
464 repository: TrimmedNonEmptyString,
465 number: PositiveInt,
466 title: TrimmedNonEmptyString,
467 url: TrimmedNonEmptyString,
468 author: Schema.NullOr(PullRequestActor),
469 state: PullRequestState,
470 isDraft: Schema.Boolean,
471 createdAt: IsoDateTime,
472 updatedAt: Schema.optional(IsoDateTime),
473 observedAt: Schema.optional(Schema.Finite),
474});
475export type PullRequestPreview = typeof PullRequestPreview.Type;
476​
477export const PullRequestSummary = Schema.Struct({
478 provider: SourceControlProviderKind,
479 projectId: ProjectId,
480 repository: TrimmedNonEmptyString,
481 number: PositiveInt,
482 title: TrimmedNonEmptyString,
483 url: TrimmedNonEmptyString,
484 state: PullRequestState,
485 isDraft: Schema.optional(Schema.Boolean),
486 headBranch: TrimmedNonEmptyString,
487 baseBranch: TrimmedNonEmptyString,
488 closedAt: Schema.optional(Schema.NullOr(Schema.String)),
489 mergedAt: Schema.optional(Schema.NullOr(Schema.String)),
490 updatedAt: IsoDateTime,
491 observedAt: Schema.optional(Schema.Finite),
492 author: Schema.optional(Schema.NullOr(PullRequestActor)),
493 additions: Schema.optional(NonNegativeInt),
494 deletions: Schema.optional(NonNegativeInt),
495 changedFiles: Schema.optional(NonNegativeInt),
496 reviewDecision: Schema.optional(Schema.NullOr(PullRequestReviewDecision)),
497 checksState: Schema.optional(Schema.NullOr(PullRequestChecksState)),
498 mergeability: Schema.optional(PullRequestMergeability),
499 /** Null when the host says the pull request is in no stack; absent when the read did not ask. */
500 stack: Schema.optional(Schema.NullOr(PullRequestStackMembership)),
501 headSha: Schema.optional(TrimmedNonEmptyString),
502 /** Absent means the read did not report auto-merge state, not that it is off. */
503 autoMergeEnabled: Schema.optional(Schema.Boolean),
504 autoMergeMethod: Schema.optional(PullRequestMergeMethod),
505});
506export type PullRequestSummary = typeof PullRequestSummary.Type;
507​
508export const PullRequestStack = Schema.Struct({
509 id: TrimmedNonEmptyString,
510 number: PositiveInt,
511 url: TrimmedNonEmptyString,
512 base: TrimmedNonEmptyString,
513 layers: Schema.Array(
514 Schema.Struct({
515 number: PositiveInt,
516 title: Schema.optional(Schema.String),
517 isDraft: Schema.optional(Schema.Boolean),
518 headSha: Schema.optional(TrimmedNonEmptyString),
519 headBranch: TrimmedNonEmptyString,
520 state: PullRequestState,
521 }),
522 ),
523});
524export type PullRequestStack = typeof PullRequestStack.Type;
525​
526export const PullRequestDiffStat = Schema.Struct({
527 projectId: ProjectId,
528 repository: TrimmedNonEmptyString,
529 number: PositiveInt,
530 additions: NonNegativeInt,
531 deletions: NonNegativeInt,
532});
533export type PullRequestDiffStat = typeof PullRequestDiffStat.Type;
534​
535export const PullRequestListStatsInput = Schema.Struct({
536 refs: Schema.Array(PullRequestRef).check(Schema.isMaxLength(500)),
537});
538export type PullRequestListStatsInput = typeof PullRequestListStatsInput.Type;
539​
540export const PullRequestListStatsResult = Schema.Struct({
541 stats: Schema.Array(PullRequestDiffStat),
542});
543export type PullRequestListStatsResult = typeof PullRequestListStatsResult.Type;
544​
545export const PullRequestFilterOptionKind = Schema.Literals(["labels", "authors", "references"]);
546export type PullRequestFilterOptionKind = typeof PullRequestFilterOptionKind.Type;
547​
548/** Scoped like `PullRequestListInput`, so the options come from the repositories it lists. */
549export const PullRequestFilterOptionsInput = Schema.Struct({
550 kind: PullRequestFilterOptionKind,
551 projectId: Schema.optional(ProjectId),
552 projectIds: Schema.optional(Schema.Array(ProjectId).check(Schema.isMaxLength(100))),
553 host: Schema.optional(TrimmedNonEmptyString),
554 query: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(100))),
555 /** For `references`, the sigil typed, so a host can search only what it links. */
556 sigil: Schema.optional(PullRequestReferenceSigil),
557});
558export type PullRequestFilterOptionsInput = typeof PullRequestFilterOptionsInput.Type;
559​
560/** An issue or change request a composer can reference, with the text the host links. */
561export const PullRequestReferenceCandidate = Schema.Struct({
562 reference: TrimmedNonEmptyString,
563 kind: Schema.Literals(["issue", "change-request"]),
564 number: PositiveInt,
565 title: Schema.String,
566 state: Schema.Literals(["open", "closed", "merged"]),
567});
568export type PullRequestReferenceCandidate = typeof PullRequestReferenceCandidate.Type;
569​
570export const PullRequestFilterOptions = Schema.Struct({
571 labels: Schema.Array(PullRequestLabel),
572 authors: Schema.Array(PullRequestActor),
573 // Servers from before reference completion send no key.
574 references: Schema.Array(PullRequestReferenceCandidate).pipe(
575 Schema.withDecodingDefault(Effect.succeed([])),
576 ),
577 truncated: Schema.Boolean,
578});
579export type PullRequestFilterOptions = typeof PullRequestFilterOptions.Type;
580​
581/**
582 * A separate request rather than a flag on the reads, so an explicit "refresh" one person
583 * presses is the only thing that spends host requests — every ordinary read shares.
584 */
585export const PullRequestInvalidateInput = Schema.Struct({
586 reference: Schema.optional(PullRequestRef),
587 filesViewedOnly: Schema.optional(Schema.Boolean),
588});
589export type PullRequestInvalidateInput = typeof PullRequestInvalidateInput.Type;
590​
591export const PullRequestReportStateInput = Schema.Struct({
592 reference: PullRequestRef,
593 state: PullRequestState,
594 isDraft: Schema.optional(Schema.Boolean),
595});
596export type PullRequestReportStateInput = typeof PullRequestReportStateInput.Type;
597​
598export const PullRequestDetail = Schema.Struct({
599 provider: SourceControlProviderKind,
600 capabilities: PullRequestCapabilities,
601 viewerPermissions: PullRequestViewerPermissions,
602 projectId: ProjectId,
603 projectTitle: TrimmedNonEmptyString,
604 workspaceRoot: TrimmedNonEmptyString,
605 repository: TrimmedNonEmptyString,
606 number: PositiveInt,
607 title: TrimmedNonEmptyString,
608 body: Schema.String,
609 url: TrimmedNonEmptyString,
610 author: Schema.NullOr(PullRequestActor),
611 state: PullRequestState,
612 isDraft: Schema.Boolean,
613 mergeability: PullRequestMergeability,
614 additions: NonNegativeInt,
615 deletions: NonNegativeInt,
616 changedFiles: NonNegativeInt,
617 headBranch: TrimmedNonEmptyString,
618 headRepositoryNameWithOwner: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
619 headSha: Schema.optional(TrimmedNonEmptyString),
620 baseBranch: TrimmedNonEmptyString,
621 createdAt: IsoDateTime,
622 updatedAt: IsoDateTime,
623 observedAt: Schema.optional(Schema.Finite),
624 mergedAt: Schema.NullOr(IsoDateTime),
625 closedAt: Schema.NullOr(IsoDateTime),
626 reviewers: Schema.Array(PullRequestActor),
627 labels: Schema.Array(PullRequestLabel),
628 checks: Schema.Array(PullRequestCheck),
629 mergeCapabilities: PullRequestMergeCapabilities,
630 viewer: Schema.optional(TrimmedNonEmptyString),
631 baseComparison: Schema.optional(PullRequestBaseComparison),
632 behindBy: Schema.optional(NonNegativeInt),
633 /** Absent means the host does not report auto-merge state, not that it is off. */
634 autoMergeEnabled: Schema.optional(Schema.Boolean),
635 autoMergeMethod: Schema.optional(PullRequestMergeMethod),
636 workflowApprovalsRequired: Schema.optional(NonNegativeInt),
637 maintainerCanModify: Schema.optional(Schema.Boolean),
638});
639export type PullRequestDetail = typeof PullRequestDetail.Type;
640​
641export const PullRequestChecks = Schema.Struct({
642 observedAt: Schema.optional(Schema.Finite),
643 state: PullRequestState,
644 checks: Schema.Array(PullRequestCheck),
645});
646export type PullRequestChecks = typeof PullRequestChecks.Type;
647​
648export const PullRequestActivity = Schema.Struct({
649 author: Schema.optional(Schema.NullOr(PullRequestActor)),
650 reviewers: Schema.optional(Schema.Array(PullRequestActor)),
651 comments: Schema.Array(PullRequestComment),
652 commentCount: NonNegativeInt,
653 commentsTruncated: Schema.Boolean,
654 reviewThreadsTruncated: Schema.optional(Schema.Boolean),
655 reviewThreads: Schema.Array(PullRequestReviewThread),
656 commits: Schema.Array(PullRequestCommit),
657 reactions: Schema.optional(Schema.Array(PullRequestReaction)),
658});
659export type PullRequestActivity = typeof PullRequestActivity.Type;
660​
661export const PullRequestDetailView = Schema.Struct({
662 ...PullRequestDetail.fields,
663 ...PullRequestActivity.fields,
664 author: Schema.NullOr(PullRequestActor),
665 reviewers: Schema.Array(PullRequestActor),
666});
667export type PullRequestDetailView = typeof PullRequestDetailView.Type;
668​
669/** GitHub refuses diffs past 300 files, so callers must page large changes. */
670export const PullRequestDiffInput = Schema.Struct({
671 ...PullRequestRef.fields,
672 cursor: Schema.optional(TrimmedNonEmptyString),
673 commit: Schema.optional(TrimmedNonEmptyString),
674});
675export type PullRequestDiffInput = typeof PullRequestDiffInput.Type;
676​
677export const PullRequestOmittedFileStat = Schema.Struct({
678 path: TrimmedNonEmptyString,
679 additions: Schema.Number,
680 deletions: Schema.Number,
681});
682export type PullRequestOmittedFileStat = typeof PullRequestOmittedFileStat.Type;
683​
684export const PullRequestDiffResult = Schema.Struct({
685 patch: Schema.String,
686 /** Content omitted within this slice; nextCursor separately indicates more slices. */
687 truncated: Schema.Boolean,
688 nextCursor: Schema.NullOr(TrimmedNonEmptyString),
689 omittedFileStats: Schema.optional(Schema.Array(PullRequestOmittedFileStat)),
690});
691export type PullRequestDiffResult = typeof PullRequestDiffResult.Type;
692​
693export const PullRequestDiffFileContentsInput = Schema.Struct({
694 ...PullRequestRef.fields,
695 commit: Schema.optional(TrimmedNonEmptyString),
696 changeType: Schema.Literals(["change", "rename-pure", "rename-changed", "new", "deleted"]),
697 oldPath: TrimmedNonEmptyString,
698 newPath: TrimmedNonEmptyString,
699});
700export type PullRequestDiffFileContentsInput = typeof PullRequestDiffFileContentsInput.Type;
701​
702export const PullRequestDiffFileContentsResult = Schema.Struct({
703 oldContents: Schema.String,
704 newContents: Schema.String,
705});
706export type PullRequestDiffFileContentsResult = typeof PullRequestDiffFileContentsResult.Type;
707​
708const MAX_FILE_PATH_LENGTH = 4096;
709// Preserve filename whitespace so viewed marks match host paths.
710const FilePath = Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(MAX_FILE_PATH_LENGTH));
711​
712export const PullRequestFileViewedState = Schema.Literals(["unviewed", "viewed", "dismissed"]);
713export type PullRequestFileViewedState = typeof PullRequestFileViewedState.Type;
714​
715export const PullRequestFileViewed = Schema.Struct({
716 path: FilePath,
717 state: PullRequestFileViewedState,
718});
719export type PullRequestFileViewed = typeof PullRequestFileViewed.Type;
720​
721export const PullRequestFilesViewedResult = Schema.Struct({
722 /** Only the files the host reported a state for. A file missing from this list is unviewed. */
723 files: Schema.Array(PullRequestFileViewed),
724 truncated: Schema.Boolean,
725});
726export type PullRequestFilesViewedResult = typeof PullRequestFilesViewedResult.Type;
727​
728const PullRequestLineCount = Schema.Struct({
729 additions: NonNegativeInt,
730 deletions: NonNegativeInt,
731});
732​
733/**
734 * A change's line counts split by what the changed files are, judged from their paths. Null when
735 * the host gives no per-file counts, or has more files than one read covers: a split of part of
736 * the change would not add up to the totals shown beside it.
737 */
738export const PullRequestChangeBreakdown = Schema.NullOr(
739 Schema.Struct({
740 code: PullRequestLineCount,
741 tests: PullRequestLineCount,
742 mocks: PullRequestLineCount,
743 generated: PullRequestLineCount,
744 // Servers from before the docs split send no key; their docs lines sit in `code`.
745 docs: PullRequestLineCount.pipe(
746 Schema.withDecodingDefault(Effect.succeed({ additions: 0, deletions: 0 })),
747 ),
748 }),
749);
750export type PullRequestChangeBreakdown = typeof PullRequestChangeBreakdown.Type;
751​
752const MAX_FILES_VIEWED_PRESSES = 500;
753​
754export const PullRequestSetFilesViewedInput = Schema.Struct({
755 ...PullRequestRef.fields,
756 files: Schema.Array(
757 Schema.Struct({
758 path: FilePath,
759 viewed: Schema.Boolean,
760 }),
761 ).check(Schema.isMaxLength(MAX_FILES_VIEWED_PRESSES)),
762});
763export type PullRequestSetFilesViewedInput = typeof PullRequestSetFilesViewedInput.Type;
764​
765export const PullRequestStackHead = Schema.Struct({
766 number: PositiveInt,
767 headSha: TrimmedNonEmptyString,
768});
769export type PullRequestStackHead = typeof PullRequestStackHead.Type;
770​
771export const PullRequestActionInput = Schema.Struct({
772 /** Native stack scope; only send to environments advertising pullRequestStackActions. */
773 stackNumber: Schema.optional(PositiveInt),
774 expectedStackHeads: Schema.optional(Schema.Array(PullRequestStackHead)),
775 ...PullRequestRef.fields,
776 action: PullRequestAction,
777 mergeMethod: Schema.optional(PullRequestMergeMethod),
778 updateMethod: Schema.optional(PullRequestUpdateMethod),
779 /** Opt-in, because older clients decode the action's success as void and reject a summary. */
780 replyWithSummary: Schema.optional(Schema.Literal(true)),
781});
782export type PullRequestActionInput = typeof PullRequestActionInput.Type;
783​
784// Preserve whitespace because it affects Markdown formatting.
785const CommentBody = Schema.String.check(Schema.isNonEmpty()).check(Schema.isMaxLength(65_536));
786​
787export const PullRequestCommentInput = Schema.Struct({
788 ...PullRequestRef.fields,
789 body: CommentBody,
790});
791export type PullRequestCommentInput = typeof PullRequestCommentInput.Type;
792​
793export const PullRequestUpdateInput = Schema.Struct({
794 ...PullRequestRef.fields,
795 title: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(1024))),
796 body: Schema.optional(Schema.String.check(Schema.isMaxLength(65_536))),
797 maintainerCanModify: Schema.optional(Schema.Boolean),
798});
799export type PullRequestUpdateInput = typeof PullRequestUpdateInput.Type;
800​
801/** Comment kind selects the endpoint; GitHub uses separate mutations for conversation and line comments. */
802export const PullRequestCommentUpdateInput = Schema.Struct({
803 ...PullRequestRef.fields,
804 commentId: TrimmedNonEmptyString,
805 kind: Schema.Literals(["issue-comment", "review-comment"]),
806 body: CommentBody,
807});
808export type PullRequestCommentUpdateInput = typeof PullRequestCommentUpdateInput.Type;
809​
810export const PullRequestReviewPosition = Schema.Union([
811 Schema.Struct({
812 kind: Schema.Literal("added"),
813 newLine: PositiveInt,
814 }),
815 Schema.Struct({
816 kind: Schema.Literal("deleted"),
817 oldLine: PositiveInt,
818 }),
819 Schema.Struct({
820 kind: Schema.Literal("context"),
821 oldLine: PositiveInt,
822 newLine: PositiveInt,
823 side: PullRequestDiffSide,
824 }),
825]);
826export type PullRequestReviewPosition = typeof PullRequestReviewPosition.Type;
827​
828export const PullRequestReviewCommentDraft = Schema.Struct({
829 path: TrimmedNonEmptyString,
830 /** GitLab needs both names for renamed-file comments; hosts using one path ignore this. */
831 oldPath: Schema.optional(TrimmedNonEmptyString),
832 position: PullRequestReviewPosition,
833 /**
834 * The first line of a comment on a range, which ends at `position`. Sent only to a host whose
835 * capabilities include `review.rangeComment`.
836 */
837 startPosition: Schema.optional(PullRequestReviewPosition),
838 body: CommentBody,
839});
840export type PullRequestReviewCommentDraft = typeof PullRequestReviewCommentDraft.Type;
841​
842export const PullRequestSubmitReviewInput = Schema.Struct({
843 ...PullRequestRef.fields,
844 verdict: PullRequestReviewVerdict,
845 body: Schema.String.check(Schema.isMaxLength(65_536)),
846 comments: Schema.Array(PullRequestReviewCommentDraft),
847});
848export type PullRequestSubmitReviewInput = typeof PullRequestSubmitReviewInput.Type;
849​
850export const PullRequestThreadCommentsInput = Schema.Struct({
851 ...PullRequestRef.fields,
852 threadId: TrimmedNonEmptyString,
853 cursor: TrimmedNonEmptyString,
854});
855export type PullRequestThreadCommentsInput = typeof PullRequestThreadCommentsInput.Type;
856​
857export const PullRequestThreadCommentsResult = Schema.Struct({
858 comments: Schema.Array(PullRequestThreadComment),
859 nextCursor: Schema.NullOr(TrimmedNonEmptyString),
860 // Comments the host hid that this page left out; the thread's `commentCount` still counts them.
861 hiddenCount: Schema.optional(NonNegativeInt),
862});
863export type PullRequestThreadCommentsResult = typeof PullRequestThreadCommentsResult.Type;
864​
865export const PullRequestThreadReplyInput = Schema.Struct({
866 ...PullRequestRef.fields,
867 threadId: TrimmedNonEmptyString,
868 body: CommentBody,
869});
870export type PullRequestThreadReplyInput = typeof PullRequestThreadReplyInput.Type;
871​
872export const PullRequestThreadResolutionInput = Schema.Struct({
873 ...PullRequestRef.fields,
874 threadId: TrimmedNonEmptyString,
875 resolved: Schema.Boolean,
876});
877export type PullRequestThreadResolutionInput = typeof PullRequestThreadResolutionInput.Type;
878​
879export const PullRequestReactionInput = Schema.Struct({
880 ...PullRequestRef.fields,
881 subjectId: Schema.optional(TrimmedNonEmptyString),
882 content: PullRequestReactionContent,
883 reacted: Schema.Boolean,
884});
885export type PullRequestReactionInput = typeof PullRequestReactionInput.Type;
886​
887export const PullRequestReviewerRequestInput = Schema.Struct({
888 ...PullRequestRef.fields,
889 reviewers: Schema.Array(
890 Schema.Struct({ id: TrimmedNonEmptyString, kind: PullRequestReviewerKind }),
891 ).check(Schema.isMinLength(1), Schema.isMaxLength(25)),
892 requested: Schema.Boolean,
893});
894export type PullRequestReviewerRequestInput = typeof PullRequestReviewerRequestInput.Type;
895​
896export const PullRequestLabelChangeInput = Schema.Struct({
897 ...PullRequestRef.fields,
898 labels: Schema.Array(TrimmedNonEmptyString).check(Schema.isMinLength(1), Schema.isMaxLength(25)),
899 applied: Schema.Boolean,
900});
901export type PullRequestLabelChangeInput = typeof PullRequestLabelChangeInput.Type;
902​
903/**
904 * The names keep their `cli-` prefix for wire compatibility; for a host read with a credential
905 * rather than a tool they mean "no credential" and "a refused credential".
906 */
907export const PullRequestUnavailableReason = Schema.Literals([
908 "cli-missing",
909 "cli-unauthenticated",
910 "provider-unsupported",
911]);
912export type PullRequestUnavailableReason = typeof PullRequestUnavailableReason.Type;
913​
914/**
915 * `author:me` names whoever is signed in to the host being read, GitHub's `@me` spelled either
916 * way. A host's own search would answer it, but the page and the server both re-check an author
917 * against the row's login, so the name is resolved before either comparison rather than being
918 * matched as the literal login "me".
919 */
920export function resolvePullRequestAuthorFilter(
921 author: string,
922 viewer: string | null | undefined,
923): string {
924 const trimmed = author.trim();
925 if (!/^@?me$/i.test(trimmed)) return trimmed;
926 return viewer === null || viewer === undefined || viewer.trim().length === 0 ? trimmed : viewer;
928​
929export class PullRequestUnavailableError extends Schema.TaggedError<PullRequestUnavailableError>()(
930 "PullRequestUnavailableError",
931 {
932 reason: PullRequestUnavailableReason,
933 provider: Schema.optional(SourceControlProviderKind),
934 /**
935 * What the host needs on the server, in its own words. Absent from older servers, which
936 * shipped no such field, and for a host that names nothing.
937 */
938 requirement: Schema.optional(TrimmedNonEmptyString),
939 cause: Schema.optional(Schema.Defect()),
940 },
941 { httpApiStatus: 503 },
942) {
943 [HttpServerRespondable.symbol]() {
944 return HttpServerResponse.schemaJson(PullRequestUnavailableError)(this, { status: 503 });
945 }
946​
947 override get message(): string {
948 switch (this.reason) {
949 case "cli-missing":
950 return this.requirement ?? "The tool this host is read through is not installed or set up.";
951 case "cli-unauthenticated":
952 return this.requirement ?? "This host has no working credentials.";
953 case "provider-unsupported":
954 return "Change requests cannot be browsed for this project's host yet.";
955 }
956 }
958​
959export class PullRequestOperationError extends Schema.TaggedError<PullRequestOperationError>()(
960 "PullRequestOperationError",
961 {
962 operation: Schema.String,
963 detail: TrimmedNonEmptyString,
964 reason: Schema.optional(Schema.Literal("not-found")),
965 cause: Schema.optional(Schema.Defect()),
966 },
967 { httpApiStatus: 502 },
968) {
969 [HttpServerRespondable.symbol]() {
970 return HttpServerResponse.schemaJson(PullRequestOperationError)(this, { status: 502 });
971 }
972​
973 override get message(): string {
974 return `Pull request operation ${this.operation} failed: ${this.detail}`;
975 }