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