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