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

pullRequest.ts

1,034 lines40.1 KB

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