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

pullRequest.ts

1,318 lines58.1 KB

1import * as Schema from "effect/Schema";
2import * as HttpServerRespondable from "effect/unstable/http/HttpServerRespondable";
3import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
4​
5import {
6 IsoDateTime,
7 NonNegativeInt,
8 PositiveInt,
9 ProjectId,
10 ThreadId,
11 TrimmedNonEmptyString,
12} from "./baseSchemas.ts";
13import { SourceControlProviderKind } from "./sourceControl.ts";
14​
15export const PullRequestInvolvement = Schema.Literals(["all", "reviewing", "authored"]);
16export type PullRequestInvolvement = typeof PullRequestInvolvement.Type;
17​
18export const PullRequestState = Schema.Literals(["open", "closed", "merged"]);
19export type PullRequestState = typeof PullRequestState.Type;
20​
21/**
22 * What a listing asks for, which is the three states a change request can be in plus the option
23 * to span them. Separate from `PullRequestState` because a change request is never "all" — only
24 * a request for one can be.
25 */
26export const PullRequestListState = Schema.Literals(["all", "open", "closed", "merged"]);
27export type PullRequestListState = typeof PullRequestListState.Type;
28​
29/** Where a review stands overall, as a host that summarises its reviews reports it. */
30export const PullRequestReviewDecision = Schema.Literals([
31 "approved",
32 "changes-requested",
33 "review-required",
34]);
35export type PullRequestReviewDecision = typeof PullRequestReviewDecision.Type;
36​
37/** One qualifier's value, bounded because it is written into a host's own search query. */
38const PullRequestQualifierValue = TrimmedNonEmptyString.check(Schema.isMaxLength(200));
39const PullRequestQualifierValues = Schema.Array(PullRequestQualifierValue).check(
40 Schema.isMaxLength(10),
41);
42​
43/**
44 * Narrowings beyond state and involvement, each absent by default — an absent field filters
45 * nothing, which is what every listing did before there were any. Optional as a whole so a page
46 * and a server of different ages still speak to each other.
47 *
48 * `checks` is host-side only: no row carries its own check state, so a host that cannot match it
49 * answers unnarrowed rather than the page pretending to know.
50 */
51export const PullRequestListFilters = Schema.Struct({
52 draft: Schema.optional(Schema.Literals(["only", "hide"])),
53 review: Schema.optional(
54 Schema.Literals(["approved", "changes-requested", "review-required", "none"]),
55 ),
56 checks: Schema.optional(Schema.Literals(["passing", "failing"])),
57 /**
58 * Labels as GitHub's own search reads them: each group is one `label:` qualifier, a row must
59 * satisfy every group, and a group holding several names is satisfied by any one of them —
60 * `label:size:S,size:XS` finds either size. Typed rather than picked, since a project's labels
61 * are its own and no menu can list them. Bounded because each becomes a host search qualifier.
62 */
63 labels: Schema.optional(Schema.Array(PullRequestQualifierValues).check(Schema.isMaxLength(10))),
64 excludedLabels: Schema.optional(PullRequestQualifierValues),
65 /** One login, as `author:` names it. */
66 author: Schema.optional(PullRequestQualifierValue),
67});
68export type PullRequestListFilters = typeof PullRequestListFilters.Type;
69​
70/** The one-glyph summary of a change request's checks, as its list row wears it. */
71export const PullRequestChecksState = Schema.Literals(["passing", "failing", "pending"]);
72export type PullRequestChecksState = typeof PullRequestChecksState.Type;
73​
74export const PullRequestMergeability = Schema.Literals(["mergeable", "conflicting", "unknown"]);
75export type PullRequestMergeability = typeof PullRequestMergeability.Type;
76​
77export const PullRequestMergeMethod = Schema.Literals(["merge", "squash", "rebase"]);
78export type PullRequestMergeMethod = typeof PullRequestMergeMethod.Type;
79​
80export const PullRequestAction = Schema.Literals([
81 "merge",
82 "ready",
83 "draft",
84 "close",
85 "reopen",
86 /** Bring the base branch's commits into this one, which is what unblocks a stale branch. */
87 "update-branch",
88 /**
89 * Hand the merge to the host: it waits for whatever it requires — a green pipeline, the
90 * approvals, an unblocked branch — and merges without anybody coming back. Separate from
91 * `merge` because the two answer different questions. `merge` is refused outright by a host
92 * that is not ready yet, and this one is for exactly that moment.
93 */
94 "enable-auto-merge",
95 /** Take the standing instruction back, which leaves the change request where it was. */
96 "disable-auto-merge",
97 /** Open a new change request that reverses a merged one. */
98 "revert",
99 /** Allow Actions workflows from a fork pull request to begin running. */
100 "approve-workflows",
101]);
102export type PullRequestAction = typeof PullRequestAction.Type;
103​
104/**
105 * How a stale branch catches up with its base: a merge commit, or a rebase onto it. The two are
106 * the host's own choices, not this page's — GitHub offers both and refuses a rebase it cannot
107 * replay, so what is offered comes from the host and what is allowed comes from the viewer.
108 */
109export const PullRequestUpdateMethod = Schema.Literals(["merge", "rebase"]);
110export type PullRequestUpdateMethod = typeof PullRequestUpdateMethod.Type;
111​
112/**
113 * Where the branch stands against the base it would merge into. Separate from `mergeability`,
114 * which answers a different question: a branch can be behind and still merge cleanly, and that
115 * pairing — out of date, no conflicts — is the one an update button exists for.
116 *
117 * "unknown" where the host was not asked or could not say, which is every host but GitHub and
118 * every pull request whose head repository could not be compared.
119 */
120export const PullRequestBaseComparison = Schema.Literals(["up-to-date", "behind", "unknown"]);
121export type PullRequestBaseComparison = typeof PullRequestBaseComparison.Type;
122​
123export const PullRequestActor = Schema.Struct({
124 login: TrimmedNonEmptyString,
125 name: Schema.NullOr(Schema.String),
126 /** Null where a host does not report one, which is what the initials fall back to. */
127 avatarUrl: Schema.NullOr(Schema.String),
128});
129export type PullRequestActor = typeof PullRequestActor.Type;
130​
131export const PullRequestLabel = Schema.Struct({
132 name: TrimmedNonEmptyString,
133 color: Schema.NullOr(Schema.String),
134});
135export type PullRequestLabel = typeof PullRequestLabel.Type;
136​
137export const PullRequestCheckStatus = Schema.Literals([
138 "pending",
139 "action-required",
140 "success",
141 "failure",
142 "skipped",
143 "neutral",
144 "cancelled",
145]);
146export type PullRequestCheckStatus = typeof PullRequestCheckStatus.Type;
147​
148export const PullRequestCheck = Schema.Struct({
149 name: TrimmedNonEmptyString,
150 status: PullRequestCheckStatus,
151 description: Schema.NullOr(Schema.String),
152 url: Schema.NullOr(Schema.String),
153});
154export type PullRequestCheck = typeof PullRequestCheck.Type;
155​
156/**
157 * The reactions a remark can carry. GitHub's eight, which is also what the picker offers: GitLab
158 * accepts any emoji as an award, and the ones outside this set are read as nothing rather than
159 * shown under a name no other host would recognise.
160 */
161export const PullRequestReactionContent = Schema.Literals([
162 "thumbs-up",
163 "thumbs-down",
164 "laugh",
165 "hooray",
166 "confused",
167 "heart",
168 "rocket",
169 "eyes",
170]);
171export type PullRequestReactionContent = typeof PullRequestReactionContent.Type;
172​
173/** One reaction and everyone behind it, which is what the hover on a reaction pill says. */
174export const PullRequestReaction = Schema.Struct({
175 content: PullRequestReactionContent,
176 count: PositiveInt,
177 /**
178 * Who reacted, as far as the host named them. A host that reports fewer names than it counts
179 * leaves the rest out, so this is never longer than `count` and may be shorter. When
180 * `viewerHasReacted` is true, the viewer's own login is left out of this list — the page names
181 * them "You" instead — but `count` still counts them along with everyone else.
182 */
183 actors: Schema.Array(TrimmedNonEmptyString),
184 /** The signed-in account is one of them, so pressing the pill takes the reaction back. */
185 viewerHasReacted: Schema.Boolean,
186});
187export type PullRequestReaction = typeof PullRequestReaction.Type;
188​
189export const PullRequestCommentKind = Schema.Literals([
190 "issue-comment",
191 "review-comment",
192 "review",
193]);
194export type PullRequestCommentKind = typeof PullRequestCommentKind.Type;
195​
196export const PullRequestComment = Schema.Struct({
197 id: TrimmedNonEmptyString,
198 kind: PullRequestCommentKind,
199 author: Schema.NullOr(PullRequestActor),
200 body: Schema.String,
201 createdAt: IsoDateTime,
202 url: Schema.NullOr(Schema.String),
203 path: Schema.NullOr(Schema.String),
204 reviewState: Schema.NullOr(Schema.String),
205 /** Absent from a host with no reactions at all, which is a different thing from none on this. */
206 reactions: Schema.optional(Schema.Array(PullRequestReaction)),
207});
208export type PullRequestComment = typeof PullRequestComment.Type;
209​
210/**
211 * Which file a diff line belongs to: `left` is the version before the change, `right` the
212 * version after. A comment has to name one, because a unified diff shows both at once and the
213 * same line number means two different lines.
214 */
215export const PullRequestDiffSide = Schema.Literals(["left", "right"]);
216export type PullRequestDiffSide = typeof PullRequestDiffSide.Type;
217​
218/** What submitting a review says about the change, beyond the words in it. */
219export const PullRequestReviewVerdict = Schema.Literals(["comment", "approve", "request-changes"]);
220export type PullRequestReviewVerdict = typeof PullRequestReviewVerdict.Type;
221​
222export const PullRequestThreadComment = Schema.Struct({
223 id: TrimmedNonEmptyString,
224 author: Schema.NullOr(PullRequestActor),
225 body: Schema.String,
226 createdAt: IsoDateTime,
227 url: Schema.NullOr(Schema.String),
228 reactions: Schema.optional(Schema.Array(PullRequestReaction)),
229});
230export type PullRequestThreadComment = typeof PullRequestThreadComment.Type;
231​
232/**
233 * A conversation anchored to a line of the diff. The detail carries these alongside `comments`
234 * rather than instead of them: the timeline wants one flat, chronological list, and the diff
235 * wants whole threads pinned to their line — the same remarks, read two different ways.
236 */
237export const PullRequestReviewThread = Schema.Struct({
238 id: TrimmedNonEmptyString,
239 path: TrimmedNonEmptyString,
240 /** Null when the host anchors the thread to a file rather than to a line. */
241 line: Schema.NullOr(PositiveInt),
242 side: PullRequestDiffSide,
243 isResolved: Schema.Boolean,
244 /**
245 * The line the thread was written against is no longer in the diff, so it cannot be shown
246 * against the code. Such a thread is listed separately rather than pinned to the wrong line.
247 */
248 isOutdated: Schema.Boolean,
249 comments: Schema.Array(PullRequestThreadComment),
250 /** Host-reported total, when this thread was read in pages. */
251 commentCount: Schema.optional(NonNegativeInt),
252 /** Opaque cursor for the next comment page. Absent once this thread is whole. */
253 nextCommentsCursor: Schema.optional(TrimmedNonEmptyString),
254});
255export type PullRequestReviewThread = typeof PullRequestReviewThread.Type;
256​
257/**
258 * Whether a reviewer is a person or a group of them the host addresses as one. GitHub is the only
259 * host here that takes a review request for a team; the others name individuals only, so nothing
260 * they report is ever anything but a user.
261 */
262export const PullRequestReviewerKind = Schema.Literals(["user", "team"]);
263export type PullRequestReviewerKind = typeof PullRequestReviewerKind.Type;
264​
265/**
266 * Somebody a review may be asked of. Carries the actor fields so the menu shows the same face and
267 * handle the rest of the page does, and a team wears them too — its slug stands in for a login.
268 */
269export const PullRequestReviewerCandidate = Schema.Struct({
270 ...PullRequestActor.fields,
271 /**
272 * How the host addresses this reviewer when a review is requested, which is not always the
273 * handle it shows: GitHub takes a login or a team slug, GitLab a numeric user id, Bitbucket an
274 * account uuid. Opaque to the page, which sends back whatever the candidate arrived with.
275 */
276 id: TrimmedNonEmptyString,
277 kind: PullRequestReviewerKind,
278 /** A review has already been asked of them, so pressing them takes the request back. */
279 isRequested: Schema.Boolean,
280});
281export type PullRequestReviewerCandidate = typeof PullRequestReviewerCandidate.Type;
282​
283export const PullRequestReviewerCandidateList = Schema.Struct({
284 /** Never includes the author: nobody is asked to review their own change request. */
285 candidates: Schema.Array(PullRequestReviewerCandidate),
286 /**
287 * The host has more people with access than the read asked for, so somebody missing from the
288 * menu may still be somebody this change request can be sent to. Nothing is wrong with the
289 * list; it is simply not all of it.
290 */
291 truncated: Schema.Boolean,
292});
293export type PullRequestReviewerCandidateList = typeof PullRequestReviewerCandidateList.Type;
294​
295/** A label the repository defines, with whether this change request already wears it. */
296export const PullRequestLabelCandidate = Schema.Struct({
297 ...PullRequestLabel.fields,
298 description: Schema.NullOr(Schema.String),
299 isApplied: Schema.Boolean,
300});
301export type PullRequestLabelCandidate = typeof PullRequestLabelCandidate.Type;
302​
303export const PullRequestLabelCandidateList = Schema.Struct({
304 candidates: Schema.Array(PullRequestLabelCandidate),
305 /** The repository defines more labels than the read asked for; the list is not all of them. */
306 truncated: Schema.Boolean,
307});
308export type PullRequestLabelCandidateList = typeof PullRequestLabelCandidateList.Type;
309​
310export const PullRequestCommit = Schema.Struct({
311 oid: TrimmedNonEmptyString,
312 messageHeadline: Schema.String,
313 committedDate: IsoDateTime,
314 /** Per-commit line counts where the host can return them without a request per commit. */
315 additions: Schema.optional(NonNegativeInt),
316 deletions: Schema.optional(NonNegativeInt),
317 /**
318 * Everyone the host attributes the commit to. Optional because older servers and hosts that
319 * do not expose commit authors still produce a useful timeline entry.
320 */
321 authors: Schema.optional(Schema.Array(PullRequestActor)),
322});
323export type PullRequestCommit = typeof PullRequestCommit.Type;
324​
325/**
326 * What a host can do with a review, which is where the four differ most. GitLab has no way to
327 * say "changes requested", and Azure DevOps exposes no diff through its CLI, so it has no lines
328 * to write against at all.
329 */
330export const PullRequestReviewCapabilities = Schema.Struct({
331 /** A new comment can be anchored to a line of the diff. */
332 inlineComment: Schema.Boolean,
333 /** An existing thread can be replied to. */
334 reply: Schema.Boolean,
335 /** A thread can be marked resolved, and unresolved again. */
336 resolve: Schema.Boolean,
337 /** The verdicts a submitted review can carry. Empty means reviews cannot be submitted. */
338 verdicts: Schema.Array(PullRequestReviewVerdict),
339});
340export type PullRequestReviewCapabilities = typeof PullRequestReviewCapabilities.Type;
341​
342/**
343 * What a host lets be rewritten after it has been posted. The two are separate because a host can
344 * take one without the other: Azure DevOps takes a new title and description through the same
345 * command that closes a pull request, and has no way to post a remark here at all — so nothing it
346 * shows in a conversation can be rewritten either.
347 */
348export const PullRequestEditCapabilities = Schema.Struct({
349 /** The change request's own title and description can be rewritten. */
350 changeRequest: Schema.Boolean,
351 /** A remark can be rewritten by whoever wrote it. */
352 comment: Schema.Boolean,
353});
354export type PullRequestEditCapabilities = typeof PullRequestEditCapabilities.Type;
355​
356/**
357 * What a host can do about who reviews. The two are independent: a host can take a request without
358 * publishing who may receive one, which is Azure DevOps.
359 */
360export const PullRequestReviewerCapabilities = Schema.Struct({
361 /** A review can be asked of somebody, and the request taken back. */
362 request: Schema.Boolean,
363 /**
364 * The people who may be asked can be listed. False where the host has no such list to give,
365 * which leaves the page to take a name rather than offer a menu — a guessed list would be worse,
366 * because a name missing from it reads as a name that cannot be asked.
367 */
368 listCandidates: Schema.Boolean,
369});
370export type PullRequestReviewerCapabilities = typeof PullRequestReviewerCapabilities.Type;
371​
372/**
373 * What a provider can actually do, so a surface can hide what is missing rather than offer an
374 * action that would fail. Every provider fills this in for itself; nothing is assumed.
375 *
376 * Hosts differ more than they look: Azure DevOps exposes no patch through its CLI, and
377 * Bitbucket has no endpoint that reopens a declined pull request. Both would otherwise be dead
378 * buttons.
379 */
380export const PullRequestCapabilities = Schema.Struct({
381 /** A unified patch can be fetched for the change request. */
382 diff: Schema.Boolean,
383 /** A comment can be posted, and the conversation read back. */
384 comment: Schema.Boolean,
385 /** The actions this host can carry out; anything absent is never offered. */
386 actions: Schema.Array(PullRequestAction),
387 /** Merge strategies the provider itself offers, before repository settings narrow them. */
388 mergeMethods: Schema.Array(PullRequestMergeMethod),
389 /**
390 * How this host can bring a stale branch up to date. Absent where it cannot at all, which is
391 * every host that has not said otherwise — so a provider that says nothing offers nothing.
392 */
393 updateMethods: Schema.optional(Schema.Array(PullRequestUpdateMethod)),
394 /**
395 * The host can narrow a listing by free text. False means it answers unnarrowed and whoever
396 * asked has to do the narrowing — which is a different promise, so the page is told rather
397 * than left to show every change request on that host as a search result.
398 */
399 search: Schema.Boolean,
400 /**
401 * Reactions can be read from a remark, and added to one or taken back. One flag for both:
402 * neither host here reports reactions it will not also take, and a surface that could show a
403 * pill it may never press is a surface offering nothing. Optional for the same reason as
404 * `updateMethods` and `edit`: a server that says nothing about reactions has none, which is
405 * what every server before this field was.
406 */
407 reactions: Schema.optional(Schema.Boolean),
408 review: PullRequestReviewCapabilities,
409 reviewers: PullRequestReviewerCapabilities,
410 /**
411 * What can be rewritten after the fact. Optional so a page and a server of different ages still
412 * speak to each other: a server that says nothing about rewriting is one that cannot, which is
413 * what every server before this one was.
414 */
415 edit: Schema.optional(PullRequestEditCapabilities),
416 /**
417 * The host keeps stacks of change requests as objects of its own, so a linked thread can show
418 * the stack the host shows. Absent means chains are only ever inferred from base branches.
419 */
420 stacks: Schema.optional(Schema.Boolean),
421 stackActions: Schema.optional(Schema.Boolean),
422 /**
423 * The repository's labels can be listed, and one put on a change request or taken off it.
424 * Optional for the same reason `edit` is: a server that says nothing about labels has no way
425 * to change them, which is what every server before this field was.
426 */
427 labels: Schema.optional(Schema.Boolean),
428});
429export type PullRequestCapabilities = typeof PullRequestCapabilities.Type;
430​
431/**
432 * What the signed-in account may do with this change request, which is a different question from
433 * `capabilities`: that says what the host is able to do at all, and this says whether this viewer
434 * is allowed to ask for it. A host that merges pull requests still will not let a stranger merge
435 * one, so a control belongs on the page only where the two agree.
436 *
437 * A permission the host reports nothing about is granted rather than withheld. Hiding a control
438 * from someone who may in fact use it leaves them no way through and no reason given, while
439 * offering one they may not use ends in the host's own refusal — which at least says why.
440 */
441export const PullRequestViewerPermissions = Schema.Struct({
442 /** May request remote stack rebases, including when this layer is already current. */
443 stackRebase: Schema.optional(Schema.Boolean),
444 /** Which of the actions this viewer may take; anything absent is theirs to look at only. */
445 actions: Schema.Array(PullRequestAction),
446 /** This viewer may write a remark: a comment, a reply, or a note against a line. */
447 comment: Schema.Boolean,
448 /** This viewer may mark a review conversation resolved, and unresolved again. */
449 resolve: Schema.Boolean,
450 /** The verdicts this viewer may submit a review with. Empty means they may not review. */
451 verdicts: Schema.Array(PullRequestReviewVerdict),
452 /** This viewer may ask somebody for a review, and take the request back again. */
453 requestReviewers: Schema.Boolean,
454 /**
455 * The ways this viewer may bring the branch up to date, narrowed from what the host offers.
456 * Absent or empty means they may not, which is also what a host with no such action says.
457 */
458 updateMethods: Schema.optional(Schema.Array(PullRequestUpdateMethod)),
459 /**
460 * This viewer may put a label on the change request, and take one off. Absent is granted, like
461 * every permission here; the capability beside it is what decides whether a label can be
462 * changed on this host at all.
463 */
464 labels: Schema.optional(Schema.Boolean),
465});
466export type PullRequestViewerPermissions = typeof PullRequestViewerPermissions.Type;
467​
468export const PullRequestMergeCapabilities = Schema.Struct({
469 merge: Schema.Boolean,
470 squash: Schema.Boolean,
471 rebase: Schema.Boolean,
472});
473export type PullRequestMergeCapabilities = typeof PullRequestMergeCapabilities.Type;
474​
475export const PullRequestStackMembership = Schema.Struct({
476 number: PositiveInt,
477 position: PositiveInt,
478 size: PositiveInt,
479 base: TrimmedNonEmptyString,
480});
481export type PullRequestStackMembership = typeof PullRequestStackMembership.Type;
482​
483export const PullRequestListEntry = Schema.Struct({
484 stack: Schema.optional(PullRequestStackMembership),
485 provider: SourceControlProviderKind,
486 /**
487 * The host below which `repository` is addressed, so the same provider kind can serve more
488 * than one account — github.com and a GitHub Enterprise install are different identities.
489 */
490 host: TrimmedNonEmptyString,
491 projectId: ProjectId,
492 projectTitle: TrimmedNonEmptyString,
493 repository: TrimmedNonEmptyString,
494 number: PositiveInt,
495 title: TrimmedNonEmptyString,
496 url: TrimmedNonEmptyString,
497 author: Schema.NullOr(PullRequestActor),
498 headBranch: TrimmedNonEmptyString,
499 baseBranch: TrimmedNonEmptyString,
500 state: PullRequestState,
501 isDraft: Schema.Boolean,
502 mergeability: PullRequestMergeability,
503 /**
504 * Zero where the host has not been asked for the counts yet, which on GitHub is every row a
505 * listing hands over: they are read afterwards, through `PullRequestListStatsInput`. Zero is
506 * what a host that reports no counts at all has always sent, and what the page already draws
507 * as no stat rather than as an empty change.
508 */
509 additions: NonNegativeInt,
510 deletions: NonNegativeInt,
511 createdAt: IsoDateTime,
512 updatedAt: IsoDateTime,
513 viewerReviewRequested: Schema.Boolean,
514 labels: Schema.Array(PullRequestLabel),
515 /** Absent where the host does not summarise its reviews, which is every host but GitHub. */
516 reviewDecision: Schema.optional(PullRequestReviewDecision),
517 /** Absent where the host reports no check rollup, or the change request has no checks. */
518 checksState: Schema.optional(PullRequestChecksState),
519});
520export type PullRequestListEntry = typeof PullRequestListEntry.Type;
521​
522/**
523 * Where each repository a listing already reached carries on from, keyed `"<host> <repository>"`
524 * — which is how a listing tells two repositories apart, since the same `owner/repo` exists on
525 * github.com and on an Enterprise install at once.
526 *
527 * Each value is opaque: only the provider that issued one knows what it means, and the page hands
528 * back exactly what it was given rather than composing one.
529 */
530export const PullRequestListCursors = Schema.Record(
531 TrimmedNonEmptyString,
532 // Bounded because it arrives from the page and is unfolded into a host's own filter.
533 TrimmedNonEmptyString.check(Schema.isMaxLength(4096)),
534);
535export type PullRequestListCursors = typeof PullRequestListCursors.Type;
536​
537export const PullRequestListInput = Schema.Struct({
538 state: PullRequestListState,
539 involvement: Schema.optional(PullRequestInvolvement),
540 filters: Schema.optional(PullRequestListFilters),
541 projectId: Schema.optional(ProjectId),
542 /**
543 * Only these projects, for a client that assigns each shared repository to one of its
544 * connections and asks the others to stay quiet about it. Absent means every project, which
545 * is what every listing asked for before there were several connections to spread across.
546 */
547 projectIds: Schema.optional(Schema.Array(ProjectId).check(Schema.isMaxLength(100))),
548 /**
549 * Narrows the listing to one host, named as the host itself rather than as its provider kind:
550 * github.com and a GitHub Enterprise install are two accounts, and a kind cannot tell them
551 * apart. Absent means every host the workspace has.
552 */
553 host: Schema.optional(TrimmedNonEmptyString),
554 /** Rows to return per repository, which with a continuation is rows per slice. */
555 limit: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 500 }))),
556 /**
557 * Carry on from an answer already on the page rather than read the listing again. Only the
558 * repositories named here are read, one slice each — which is what makes a further page cost
559 * one slice rather than every repository over again at a larger size. A repository the page has
560 * enough of is simply left out.
561 *
562 * Absent asks for the listing from the top, which is what raising `limit` alone has always
563 * done and still does.
564 */
565 cursors: Schema.optional(PullRequestListCursors),
566 /**
567 * Free text the hosts themselves are asked to match, rather than a filter over the rows that
568 * have already arrived: a listing only ever holds a page per repository, so a search that
569 * never leaves the client can only find what happened to be loaded. What a match means is the
570 * host's own business — GitHub reads a body, GitLab a description — and a host with no text
571 * filter answers unnarrowed rather than pretending.
572 *
573 * Bounded because it travels into a CLI argument and a query string, and no host makes
574 * anything of a search term this long.
575 */
576 query: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(200))),
577});
578export type PullRequestListInput = typeof PullRequestListInput.Type;
579​
580/**
581 * A host the workspace has projects on, and whether it can be read right now. Drives the host
582 * switcher and explains projects the list leaves out.
583 *
584 * One per host rather than per provider kind, because signing in is a question about the host:
585 * a workspace can hold repositories on github.com and on a GitHub Enterprise install at once,
586 * and the two are separate accounts that succeed and fail independently.
587 */
588export const PullRequestProviderSummary = Schema.Struct({
589 host: TrimmedNonEmptyString,
590 kind: SourceControlProviderKind,
591 /** False where a search has to be applied to the rows after they arrive. */
592 searchesOnHost: Schema.Boolean,
593 projectCount: PositiveInt,
594 /** False when the provider's CLI or credentials are missing, with `detail` saying which. */
595 configured: Schema.Boolean,
596 detail: Schema.NullOr(TrimmedNonEmptyString),
597});
598export type PullRequestProviderSummary = typeof PullRequestProviderSummary.Type;
599​
600/** One project whose repository could not be read; healthy projects still return entries. */
601export const PullRequestListProjectError = Schema.Struct({
602 projectId: ProjectId,
603 projectTitle: TrimmedNonEmptyString,
604 message: TrimmedNonEmptyString,
605});
606export type PullRequestListProjectError = typeof PullRequestListProjectError.Type;
607​
608export const PullRequestListResult = Schema.Struct({
609 /**
610 * The signed-in account per host, which is what involvement filtering compares. Keyed by
611 * host rather than by provider kind: two GitHub hosts are two accounts. A host that could
612 * not be read is absent rather than present-and-undefined, because an open-keyed record
613 * cannot carry an optional value through the JSON codec.
614 */
615 viewers: Schema.Record(TrimmedNonEmptyString, TrimmedNonEmptyString),
616 providers: Schema.Array(PullRequestProviderSummary),
617 /**
618 * By update, newest first, across every repository this answer covers. A page that appends a
619 * continuation sorts what it then holds the same way: a repository's next slice is older than
620 * that repository's last row, but can still be newer than another repository's.
621 */
622 entries: Schema.Array(PullRequestListEntry),
623 errors: Schema.Array(PullRequestListProjectError),
624 /** At least one repository hit the per-repository listing cap. */
625 truncated: Schema.Boolean,
626 /**
627 * Where each repository carries on, to be sent straight back as `cursors`. A repository is
628 * absent from this once it has nothing more to give, and also where its host could not be asked
629 * in an order a continuation means anything in — so an empty record beside `truncated` means
630 * more rows are only reachable by raising `limit`, the way they always were.
631 */
632 nextCursors: PullRequestListCursors,
633});
634export type PullRequestListResult = typeof PullRequestListResult.Type;
635​
636/**
637 * Addresses one pull request for reads and writes. `projectId` picks the checkout the host
638 * CLI runs in and, when its repository matches, the credentials; `host` lets the server
639 * route a pull request from another repository through any project on the same host
640 * (a frontend project's thread linking a backend PR). Absent `host` means "the project's
641 * own host", which is every reference from before thread links became host-level.
642 */
643export const PullRequestRef = Schema.Struct({
644 projectId: ProjectId,
645 host: Schema.optional(TrimmedNonEmptyString),
646 /** Refuse a routed operation unless this GitHub account still owns the active credential. */
647 expectedAccountId: Schema.optional(TrimmedNonEmptyString),
648 /** Let another environment answer when this one's cached response has expired. */
649 allowStale: Schema.optional(Schema.Boolean),
650 repository: TrimmedNonEmptyString,
651 number: PositiveInt,
652});
653export type PullRequestRef = typeof PullRequestRef.Type;
654​
655/** Account discovery never needs the originating project's private repository metadata. */
656export const PullRequestRoutingIdentityInput = Schema.Struct({
657 host: TrimmedNonEmptyString,
658});
659export type PullRequestRoutingIdentityInput = typeof PullRequestRoutingIdentityInput.Type;
660​
661export const PullRequestRoutingIdentityResult = Schema.Struct({
662 accountId: TrimmedNonEmptyString,
663 host: TrimmedNonEmptyString,
664 provider: Schema.Literal("github"),
665 viewer: TrimmedNonEmptyString,
666});
667export type PullRequestRoutingIdentityResult = typeof PullRequestRoutingIdentityResult.Type;
668​
669export const PullRequestRoutingResult = Schema.Struct({
670 accountId: TrimmedNonEmptyString,
671 host: TrimmedNonEmptyString,
672 provider: SourceControlProviderKind,
673 viewer: TrimmedNonEmptyString,
674 projectTitle: TrimmedNonEmptyString,
675 workspaceRoot: TrimmedNonEmptyString,
676});
677export type PullRequestRoutingResult = typeof PullRequestRoutingResult.Type;
678​
679export const PullRequestLinkedThreadsResult = Schema.Struct({
680 threads: Schema.Array(
681 Schema.Struct({
682 id: ThreadId,
683 projectId: ProjectId,
684 title: Schema.String,
685 archivedAt: Schema.NullOr(IsoDateTime),
686 }),
687 ),
688});
689export type PullRequestLinkedThreadsResult = typeof PullRequestLinkedThreadsResult.Type;
690​
691/**
692 * The small live shape a linked thread needs. Keeping it separate from detail means a sidebar
693 * status check never loads permissions, repository settings, checks, or base comparison data.
694 */
695export const PullRequestSummary = Schema.Struct({
696 provider: SourceControlProviderKind,
697 projectId: ProjectId,
698 repository: TrimmedNonEmptyString,
699 number: PositiveInt,
700 title: TrimmedNonEmptyString,
701 url: TrimmedNonEmptyString,
702 state: PullRequestState,
703 /** Present when the host says the open pull request is still a draft. */
704 isDraft: Schema.optional(Schema.Boolean),
705 headBranch: TrimmedNonEmptyString,
706 baseBranch: TrimmedNonEmptyString,
707 closedAt: Schema.optional(Schema.NullOr(Schema.String)),
708 mergedAt: Schema.optional(Schema.NullOr(Schema.String)),
709 updatedAt: IsoDateTime,
710 author: Schema.optional(Schema.NullOr(PullRequestActor)),
711 additions: Schema.optional(NonNegativeInt),
712 deletions: Schema.optional(NonNegativeInt),
713 changedFiles: Schema.optional(NonNegativeInt),
714 reviewDecision: Schema.optional(Schema.NullOr(PullRequestReviewDecision)),
715 checksState: Schema.optional(Schema.NullOr(PullRequestChecksState)),
716 mergeability: Schema.optional(PullRequestMergeability),
717});
718export type PullRequestSummary = typeof PullRequestSummary.Type;
719​
720/** The host-native stack a pull request belongs to, in the thread link's shape. */
721export const PullRequestStack = Schema.Struct({
722 id: TrimmedNonEmptyString,
723 number: PositiveInt,
724 url: TrimmedNonEmptyString,
725 base: TrimmedNonEmptyString,
726 layers: Schema.Array(
727 Schema.Struct({
728 number: PositiveInt,
729 title: Schema.optional(Schema.String),
730 isDraft: Schema.optional(Schema.Boolean),
731 headSha: Schema.optional(TrimmedNonEmptyString),
732 headBranch: TrimmedNonEmptyString,
733 state: PullRequestState,
734 }),
735 ),
736});
737export type PullRequestStack = typeof PullRequestStack.Type;
738​
739/**
740 * One row's line counts, read after the listing rather than inside it. On GitHub the pair is
741 * 40-60% of the wall clock of the search that answers the whole page — measured over twelve
742 * repositories, 7.1s with it and 4.0s without — for two small numbers at the end of a row.
743 *
744 * So the listing answers without them and the page asks for them next, which is what puts the
745 * rows on screen at the speed of everything else on them.
746 */
747export const PullRequestDiffStat = Schema.Struct({
748 projectId: ProjectId,
749 repository: TrimmedNonEmptyString,
750 number: PositiveInt,
751 additions: NonNegativeInt,
752 deletions: NonNegativeInt,
753});
754export type PullRequestDiffStat = typeof PullRequestDiffStat.Type;
755​
756/**
757 * The rows whose line counts are wanted, which is the rows the page is showing.
758 *
759 * Bounded at the largest listing a page can hold, since each ref becomes a lookup of its own on
760 * the host.
761 */
762export const PullRequestListStatsInput = Schema.Struct({
763 refs: Schema.Array(PullRequestRef).check(Schema.isMaxLength(500)),
764});
765export type PullRequestListStatsInput = typeof PullRequestListStatsInput.Type;
766​
767/**
768 * Only the rows that could be answered for. A host with no batched stat read of its own — every
769 * one but GitHub, which all report the counts in the listing itself — is simply absent here, and
770 * the numbers its listing already carried stand.
771 */
772export const PullRequestListStatsResult = Schema.Struct({
773 stats: Schema.Array(PullRequestDiffStat),
774});
775export type PullRequestListStatsResult = typeof PullRequestListStatsResult.Type;
776​
777/**
778 * Forget what the server has cached, so the next read asks the host. With a reference it
779 * forgets that one change request's detail and diff; without one it forgets the listings.
780 * A separate request rather than a flag on the reads, so an explicit "refresh" one person
781 * presses is the only thing that spends host requests — every ordinary read shares.
782 */
783export const PullRequestInvalidateInput = Schema.Struct({
784 reference: Schema.optional(PullRequestRef),
785});
786export type PullRequestInvalidateInput = typeof PullRequestInvalidateInput.Type;
787​
788export const PullRequestDetail = Schema.Struct({
789 provider: SourceControlProviderKind,
790 capabilities: PullRequestCapabilities,
791 /** What this viewer may do, which `capabilities` says nothing about. Both narrow the page. */
792 viewerPermissions: PullRequestViewerPermissions,
793 projectId: ProjectId,
794 projectTitle: TrimmedNonEmptyString,
795 workspaceRoot: TrimmedNonEmptyString,
796 repository: TrimmedNonEmptyString,
797 number: PositiveInt,
798 title: TrimmedNonEmptyString,
799 body: Schema.String,
800 url: TrimmedNonEmptyString,
801 author: Schema.NullOr(PullRequestActor),
802 state: PullRequestState,
803 isDraft: Schema.Boolean,
804 mergeability: PullRequestMergeability,
805 additions: NonNegativeInt,
806 deletions: NonNegativeInt,
807 changedFiles: NonNegativeInt,
808 headBranch: TrimmedNonEmptyString,
809 headRepositoryNameWithOwner: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
810 baseBranch: TrimmedNonEmptyString,
811 createdAt: IsoDateTime,
812 updatedAt: IsoDateTime,
813 mergedAt: Schema.NullOr(IsoDateTime),
814 closedAt: Schema.NullOr(IsoDateTime),
815 reviewers: Schema.Array(PullRequestActor),
816 labels: Schema.Array(PullRequestLabel),
817 checks: Schema.Array(PullRequestCheck),
818 mergeCapabilities: PullRequestMergeCapabilities,
819 /**
820 * Who the host says the reader is, which is the one thing a conversation cannot be read without
821 * to tell the reader's own remarks from everybody else's — and rewriting a remark is offered
822 * only where the two names agree. Absent where the host could not say, which offers nothing
823 * rather than everything.
824 */
825 viewer: Schema.optional(TrimmedNonEmptyString),
826 /**
827 * Where the branch stands against its base. Optional so a host that cannot compare says
828 * nothing rather than claiming the branch is current — the page shows a banner only where the
829 * answer is "behind", and silence is not that answer.
830 */
831 baseComparison: Schema.optional(PullRequestBaseComparison),
832 /** How many commits the base is ahead by, where the host counted them. */
833 behindBy: Schema.optional(NonNegativeInt),
834 /**
835 * Whether the host is already armed to merge this on its own. Absent where the host does not
836 * report it, which is not the same as off: a page that reads silence as "not armed" offers to
837 * arm something that is already armed, and a second arming is a write nobody asked for.
838 */
839 autoMergeEnabled: Schema.optional(Schema.Boolean),
840 /** The strategy the host will use for an armed auto-merge, where it reports one. */
841 autoMergeMethod: Schema.optional(PullRequestMergeMethod),
842 /** GitHub Actions runs on this head commit that are waiting for a maintainer's approval. */
843 workflowApprovalsRequired: Schema.optional(NonNegativeInt),
844});
845export type PullRequestDetail = typeof PullRequestDetail.Type;
846​
847/**
848 * The slower, conversation-shaped half of a change request. It is read independently from the
849 * core detail so a host with a deeply paginated review history cannot hold the title, body,
850 * checks, and actions off screen. `author` and `reviewers` are optional enrichments: GitHub's
851 * conversation query carries avatars and completed reviewers that its basic detail does not.
852 */
853export const PullRequestActivity = Schema.Struct({
854 author: Schema.optional(Schema.NullOr(PullRequestActor)),
855 reviewers: Schema.optional(Schema.Array(PullRequestActor)),
856 comments: Schema.Array(PullRequestComment),
857 /**
858 * How many remarks the host itself counts in the conversation, which is the number a surface
859 * showing a count has to show: `comments` carries what was read, and a reader who can see 225
860 * on the host is not reassured by a page that says 10. Never less than `comments` holds, and
861 * equal to it wherever the host was read to the end.
862 */
863 commentCount: NonNegativeInt,
864 /**
865 * The read stopped at a bound of its own before the host ran out, so `comments` holds less
866 * than `commentCount` counts. Nothing else: a conversation read whole is never truncated,
867 * however long it is.
868 */
869 commentsTruncated: Schema.Boolean,
870 reviewThreads: Schema.Array(PullRequestReviewThread),
871 commits: Schema.Array(PullRequestCommit),
872 /**
873 * The change request's own reactions — the ones on its description, which every host counts
874 * against the change request itself rather than against a remark in the conversation.
875 */
876 reactions: Schema.optional(Schema.Array(PullRequestReaction)),
877});
878export type PullRequestActivity = typeof PullRequestActivity.Type;
879​
880/** The complete detail shape after the independently loaded activity has been applied. */
881export const PullRequestDetailView = Schema.Struct({
882 ...PullRequestDetail.fields,
883 ...PullRequestActivity.fields,
884 // A composed view always has the core identity fields, even when the activity did not enrich
885 // them. Re-declare them as required after the activity's optional overrides.
886 author: Schema.NullOr(PullRequestActor),
887 reviewers: Schema.Array(PullRequestActor),
888});
889export type PullRequestDetailView = typeof PullRequestDetailView.Type;
890​
891/**
892 * A diff arrives a slice at a time, because a large change is more than any host will hand over
893 * at once — GitHub refuses outright past 300 files — and more than a viewer can lay out in one
894 * go. A slice is a whole number of files, never a file cut in half, so each one parses on its
895 * own and the reader can start on the first while the rest is still coming.
896 */
897export const PullRequestDiffInput = Schema.Struct({
898 ...PullRequestRef.fields,
899 /**
900 * Where to carry on from. Absent asks for the first slice. Opaque to the reader: each host
901 * counts its files its own way, and only the provider that issued one knows what it means.
902 */
903 cursor: Schema.optional(TrimmedNonEmptyString),
904 /**
905 * One commit of the change rather than the whole of it. A large pull request is easier to
906 * read a commit at a time, and the author's own commits are the boundaries they chose.
907 */
908 commit: Schema.optional(TrimmedNonEmptyString),
909});
910export type PullRequestDiffInput = typeof PullRequestDiffInput.Type;
911​
912/** Real line counts for a file whose hunks the host withheld from the patch. */
913export const PullRequestOmittedFileStat = Schema.Struct({
914 path: TrimmedNonEmptyString,
915 additions: Schema.Number,
916 deletions: Schema.Number,
917});
918export type PullRequestOmittedFileStat = typeof PullRequestOmittedFileStat.Type;
919​
920export const PullRequestDiffResult = Schema.Struct({
921 patch: Schema.String,
922 /**
923 * Something inside this slice could not be shown — a binary file, or a hunk the host declined
924 * to inline. Not the same as there being more slices, which `nextCursor` answers.
925 */
926 truncated: Schema.Boolean,
927 /** Where the next slice starts, or null once the diff is whole. */
928 nextCursor: Schema.NullOr(TrimmedNonEmptyString),
929 /**
930 * The host's own counts for the files whose hunks it withheld, so a file the patch cannot
931 * show still reports what changed instead of a zero the diff never had.
932 */
933 omittedFileStats: Schema.optional(Schema.Array(PullRequestOmittedFileStat)),
934});
935export type PullRequestDiffResult = typeof PullRequestDiffResult.Type;
936​
937/** The complete old and new files Pierre needs to open omitted context in a host-backed patch. */
938export const PullRequestDiffFileContentsInput = Schema.Struct({
939 ...PullRequestRef.fields,
940 /** One commit's own comparison; absent means the whole change request. */
941 commit: Schema.optional(TrimmedNonEmptyString),
942 changeType: Schema.Literals(["change", "rename-pure", "rename-changed", "new", "deleted"]),
943 oldPath: TrimmedNonEmptyString,
944 newPath: TrimmedNonEmptyString,
945});
946export type PullRequestDiffFileContentsInput = typeof PullRequestDiffFileContentsInput.Type;
947​
948export const PullRequestDiffFileContentsResult = Schema.Struct({
949 oldContents: Schema.String,
950 newContents: Schema.String,
951});
952export type PullRequestDiffFileContentsResult = typeof PullRequestDiffFileContentsResult.Type;
953​
954export const PullRequestStackHead = Schema.Struct({
955 number: PositiveInt,
956 headSha: TrimmedNonEmptyString,
957});
958export type PullRequestStackHead = typeof PullRequestStackHead.Type;
959​
960export const PullRequestActionInput = Schema.Struct({
961 /** Native stack scope; only send to environments advertising pullRequestStackActions. */
962 stackNumber: Schema.optional(PositiveInt),
963 expectedStackHeads: Schema.optional(Schema.Array(PullRequestStackHead)),
964 ...PullRequestRef.fields,
965 action: PullRequestAction,
966 /**
967 * Which strategy the merge uses, read for `merge` and for `enable-auto-merge` alike — a merge
968 * the host performs later is still a merge, and the strategy is chosen when it is armed rather
969 * than at the moment it happens. Absent means the host's own default.
970 */
971 mergeMethod: Schema.optional(PullRequestMergeMethod),
972 /** Only read for `update-branch`, where absent means the host's own default. */
973 updateMethod: Schema.optional(PullRequestUpdateMethod),
974});
975export type PullRequestActionInput = typeof PullRequestActionInput.Type;
976​
977// Not trimmed: the body is markdown, where leading spaces open a code block and two trailing
978// spaces are a line break. GitHub rejects bodies past 65536 characters, so that bound is
979// enforced here to keep oversized payloads off the wire and out of subprocess plumbing; the
980// service rejects a body that is only whitespace.
981const CommentBody = Schema.String.check(Schema.isNonEmpty()).check(Schema.isMaxLength(65_536));
982​
983export const PullRequestCommentInput = Schema.Struct({
984 ...PullRequestRef.fields,
985 body: CommentBody,
986});
987export type PullRequestCommentInput = typeof PullRequestCommentInput.Type;
988​
989/**
990 * A change request's own words rewritten: its title, its description, or both. Each is optional
991 * because the page rewrites them apart — a title corrected on its own must not carry a description
992 * nobody opened — and the service refuses a request that carries neither.
993 *
994 * The title is bounded far past what any host takes, GitHub refusing one past 256 characters, so
995 * an oversized one is turned away before it reaches a subprocess. The body is not trimmed for the
996 * same reason a comment is not: it is markdown, where leading spaces open a code block. An empty
997 * one is allowed, which is how a description is cleared.
998 */
999export const PullRequestUpdateInput = Schema.Struct({
1000 ...PullRequestRef.fields,
1001 title: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(1024))),
1002 body: Schema.optional(Schema.String.check(Schema.isMaxLength(65_536))),
1003});
1004export type PullRequestUpdateInput = typeof PullRequestUpdateInput.Type;
1005​
1006/**
1007 * A remark already posted, rewritten by whoever wrote it. The kind travels beside the id because
1008 * an id alone does not say which endpoint addresses it: GitHub rewrites a comment on the
1009 * conversation and a comment on a line through two different mutations.
1011 * A review's own summary is not among them. The hosts disagree about what one even is — the entry
1012 * Bitbucket shows is a vote this page renders as a remark, with no words behind it to rewrite —
1013 * and a control that worked on one host and failed on another is worse than one that is not there.
1014 */
1015export const PullRequestCommentUpdateInput = Schema.Struct({
1016 ...PullRequestRef.fields,
1017 commentId: TrimmedNonEmptyString,
1018 kind: Schema.Literals(["issue-comment", "review-comment"]),
1019 body: CommentBody,
1020});
1021export type PullRequestCommentUpdateInput = typeof PullRequestCommentUpdateInput.Type;
1022​
1023/** The coordinates of one line in a pull request diff. */
1024export const PullRequestReviewPosition = Schema.Union([
1025 Schema.Struct({
1026 kind: Schema.Literal("added"),
1027 newLine: PositiveInt,
1028 }),
1029 Schema.Struct({
1030 kind: Schema.Literal("deleted"),
1031 oldLine: PositiveInt,
1032 }),
1033 Schema.Struct({
1034 kind: Schema.Literal("context"),
1035 oldLine: PositiveInt,
1036 newLine: PositiveInt,
1037 /** Which copy of an unchanged line the reviewer selected in a split diff. */
1038 side: PullRequestDiffSide,
1039 }),
1040]);
1041export type PullRequestReviewPosition = typeof PullRequestReviewPosition.Type;
1042​
1043/** One remark in a review that has not been sent yet, anchored to a line of the diff. */
1044export const PullRequestReviewCommentDraft = Schema.Struct({
1045 path: TrimmedNonEmptyString,
1046 /**
1047 * What the file was called before the change, sent only when it differs. GitLab resolves a
1048 * position against both sides of the diff, so a comment on a renamed file needs both names;
1049 * the hosts that address a comment by one path ignore this.
1050 */
1051 oldPath: Schema.optional(TrimmedNonEmptyString),
1052 position: PullRequestReviewPosition,
1053 body: CommentBody,
1054});
1055export type PullRequestReviewCommentDraft = typeof PullRequestReviewCommentDraft.Type;
1056​
1057/**
1058 * A whole review, sent in one go. The line comments travel with the verdict rather than being
1059 * posted as they are written, so a half-finished review is never visible to anyone else — and
1060 * so hosts with no notion of a pending review behave the same as the ones that have it.
1061 */
1062export const PullRequestSubmitReviewInput = Schema.Struct({
1063 ...PullRequestRef.fields,
1064 verdict: PullRequestReviewVerdict,
1065 /** The review's own words. May be empty, which is how an approval with no remarks is sent. */
1066 body: Schema.String.check(Schema.isMaxLength(65_536)),
1067 comments: Schema.Array(PullRequestReviewCommentDraft),
1068});
1069export type PullRequestSubmitReviewInput = typeof PullRequestSubmitReviewInput.Type;
1070​
1071export const PullRequestThreadCommentsInput = Schema.Struct({
1072 ...PullRequestRef.fields,
1073 threadId: TrimmedNonEmptyString,
1074 cursor: TrimmedNonEmptyString,
1075});
1076export type PullRequestThreadCommentsInput = typeof PullRequestThreadCommentsInput.Type;
1077​
1078export const PullRequestThreadCommentsResult = Schema.Struct({
1079 comments: Schema.Array(PullRequestThreadComment),
1080 nextCursor: Schema.NullOr(TrimmedNonEmptyString),
1081});
1082export type PullRequestThreadCommentsResult = typeof PullRequestThreadCommentsResult.Type;
1083​
1084export const PullRequestThreadReplyInput = Schema.Struct({
1085 ...PullRequestRef.fields,
1086 threadId: TrimmedNonEmptyString,
1087 body: CommentBody,
1088});
1089export type PullRequestThreadReplyInput = typeof PullRequestThreadReplyInput.Type;
1090​
1091export const PullRequestThreadResolutionInput = Schema.Struct({
1092 ...PullRequestRef.fields,
1093 threadId: TrimmedNonEmptyString,
1094 resolved: Schema.Boolean,
1095});
1096export type PullRequestThreadResolutionInput = typeof PullRequestThreadResolutionInput.Type;
1097​
1098/**
1099 * Reacting and taking the reaction back are one operation with `reacted` turned around, which is
1100 * what pressing the same pill twice is.
1101 */
1102export const PullRequestReactionInput = Schema.Struct({
1103 ...PullRequestRef.fields,
1104 /**
1105 * Which remark to react to, as it arrived in the conversation. Absent reacts to the change
1106 * request itself, which is where its description's reactions live — the id a host uses for
1107 * that is its own to work out.
1108 */
1109 subjectId: Schema.optional(TrimmedNonEmptyString),
1110 content: PullRequestReactionContent,
1111 reacted: Schema.Boolean,
1112});
1113export type PullRequestReactionInput = typeof PullRequestReactionInput.Type;
1114​
1115/**
1116 * Asking for a review and taking the request back are one operation with `requested` turned
1117 * around, and asking again somebody who has already reviewed is what a re-request is — so that is
1118 * the same operation once more rather than a third one.
1119 */
1120export const PullRequestReviewerRequestInput = Schema.Struct({
1121 ...PullRequestRef.fields,
1122 /**
1123 * Who, as the candidate list named them. Bounded because every host bounds it as well — GitHub
1124 * refuses past fifteen — and because these travel into a request body a page composed.
1125 */
1126 reviewers: Schema.Array(
1127 Schema.Struct({ id: TrimmedNonEmptyString, kind: PullRequestReviewerKind }),
1128 ).check(Schema.isMinLength(1), Schema.isMaxLength(25)),
1129 requested: Schema.Boolean,
1130});
1131export type PullRequestReviewerRequestInput = typeof PullRequestReviewerRequestInput.Type;
1132​
1133/**
1134 * Putting a label on and taking it off are one operation with `applied` turned around, which is
1135 * what pressing the same row in the menu twice is. Named by the label's own name, which is how
1136 * GitHub addresses one.
1137 */
1138export const PullRequestLabelChangeInput = Schema.Struct({
1139 ...PullRequestRef.fields,
1140 labels: Schema.Array(TrimmedNonEmptyString).check(Schema.isMinLength(1), Schema.isMaxLength(25)),
1141 applied: Schema.Boolean,
1142});
1143export type PullRequestLabelChangeInput = typeof PullRequestLabelChangeInput.Type;
1144​
1145export const PullRequestUnavailableReason = Schema.Literals([
1146 "cli-missing",
1147 "cli-unauthenticated",
1148 "provider-unsupported",
1149]);
1150export type PullRequestUnavailableReason = typeof PullRequestUnavailableReason.Type;
1151​
1152/**
1153 * What each host needs before it can be read, so a failure names the fix rather than the
1154 * symptom. Bitbucket is credentials on the server rather than a signed-in CLI, which is why
1155 * these are whole sentences instead of a tool name to interpolate.
1156 */
1157const PROVIDER_REQUIREMENT: Partial<
1158 Record<SourceControlProviderKind, { readonly missing: string; readonly unauthenticated: string }>
1159> = {
1160 github: {
1161 missing:
1162 "GitHub CLI (`gh`) is required to browse change requests on this host. Install it from https://cli.github.com/ and reload.",
1163 unauthenticated: "GitHub CLI is not authenticated. Run `gh auth login` and retry.",
1164 },
1165 "github-enterprise": {
1166 missing:
1167 "GitHub CLI (`gh`) is required to browse change requests on this host. Install it from https://cli.github.com/ and reload.",
1168 unauthenticated:
1169 "GitHub CLI is not authenticated for this Enterprise host. Run `gh auth login --hostname <host>` and retry.",
1170 },
1171 forgejo: {
1172 missing:
1173 "Install Forgejo CLI (`fj` 0.6 or later) from https://codeberg.org/forgejo-contrib/forgejo-cli or Gitea CLI (`tea` 0.16 or later) from https://gitea.com/gitea/tea to browse Forgejo pull requests.",
1174 unauthenticated:
1175 "Authenticate your Forgejo or Gitea server with `fj --host <server-url> auth add-token` on the T3 Code server. If fj is missing or unconfigured for that server, use `tea login add`. A configured fj account must be repaired with fj.",
1176 },
1177 gitlab: {
1178 missing:
1179 "GitLab CLI (`glab`) is required to browse change requests on this host. Install it from https://gitlab.com/gitlab-org/cli and reload.",
1180 unauthenticated: "GitLab CLI is not authenticated. Run `glab auth login` and retry.",
1181 },
1182 "azure-devops": {
1183 missing:
1184 "Azure CLI (`az`) with the Azure DevOps extension is required. Install `az`, then run `az extension add --name azure-devops`.",
1185 unauthenticated: "Azure CLI is not signed in. Run `az login` and retry.",
1186 },
1187 bitbucket: {
1188 missing:
1189 "Bitbucket needs API credentials on the server. Set T3CODE_BITBUCKET_EMAIL and T3CODE_BITBUCKET_API_TOKEN, or T3CODE_BITBUCKET_ACCESS_TOKEN.",
1190 unauthenticated:
1191 "Bitbucket rejected the configured credentials. Check T3CODE_BITBUCKET_EMAIL and T3CODE_BITBUCKET_API_TOKEN.",
1192 },
1194​
1195/**
1196 * The host a project's repository is addressed below. `canonicalKey` is the normalized remote,
1197 * `host/owner/repo`, so its first segment is the host; the provider kind stands in when there is
1198 * no key to read, which keeps one bucket per kind for identities recorded before it existed.
1200 * Shared between the server and the page so both bucket a workspace the same way — the page
1201 * knows its hosts before the listing answers, and the two must agree on what they are called.
1202 */
1203export function pullRequestHostOf(
1204 identity:
1205 | {
1206 readonly canonicalKey?: string | undefined;
1207 readonly locator?: { readonly remoteUrl: string } | undefined;
1209 | null
1210 | undefined,
1211 kind: SourceControlProviderKind,
1212): string {
1213 if (kind === "forgejo") {
1214 try {
1215 const remote = new URL(identity?.locator?.remoteUrl ?? "");
1216 if (remote.protocol === "http:" || remote.protocol === "https:")
1217 return remote.host.toLowerCase();
1218 } catch {
1219 // SSH remotes retain their canonical host; the CLI resolves their web endpoint.
1222 const host = identity?.canonicalKey?.split("/")[0]?.trim();
1223 return host === undefined || host.length === 0 ? kind : host.toLowerCase();
1225​
1226/**
1227 * `author:me` names whoever is signed in to the host being read, GitHub's `@me` spelled either
1228 * way. A host's own search would answer it, but the page and the server both re-check an author
1229 * against the row's login, so the name is resolved before either comparison rather than being
1230 * matched as the literal login "me".
1232 * Null viewer where the host has not said who the reader is; the filter then stands as typed,
1233 * which is the same answer a search for a user named "me" would give.
1235 * Shared between the server and the page so both narrow by the same login.
1236 */
1237export function resolvePullRequestAuthorFilter(
1238 author: string,
1239 viewer: string | null | undefined,
1240): string {
1241 const trimmed = author.trim();
1242 if (!/^@?me$/i.test(trimmed)) return trimmed;
1243 return viewer === null || viewer === undefined || viewer.trim().length === 0 ? trimmed : viewer;
1245​
1246/**
1247 * What a host needs before it can be read, as a sentence to show wherever that host is reported
1248 * as unusable — the whole page when nothing can be read, and one entry in the host switcher when
1249 * only that host cannot. Null when the reason is not about setting a host up.
1250 */
1251export function pullRequestProviderRequirement(
1252 provider: SourceControlProviderKind,
1253 reason: PullRequestUnavailableReason,
1254): string | null {
1255 const requirement = PROVIDER_REQUIREMENT[provider];
1256 if (requirement === undefined) return null;
1257 switch (reason) {
1258 case "cli-missing":
1259 return requirement.missing;
1260 case "cli-unauthenticated":
1261 return requirement.unauthenticated;
1262 case "provider-unsupported":
1263 return null;
1266​
1267/**
1268 * The feature is switched off entirely. The message is derived from `reason` and the host
1269 * rather than from whatever the CLI printed, so it stays a stable sentence the UI can show
1270 * as-is; the underlying failure travels in `cause` (absent for `provider-unsupported`, which
1271 * has none).
1272 */
1273export class PullRequestUnavailableError extends Schema.TaggedError<PullRequestUnavailableError>()(
1274 "PullRequestUnavailableError",
1276 reason: PullRequestUnavailableReason,
1277 provider: Schema.optional(SourceControlProviderKind),
1278 cause: Schema.optional(Schema.Defect()),
1279 },
1280 { httpApiStatus: 503 },
1281) {
1282 [HttpServerRespondable.symbol]() {
1283 return HttpServerResponse.schemaJson(PullRequestUnavailableError)(this, { status: 503 });
1285​
1286 override get message(): string {
1287 const requirement =
1288 this.provider === undefined ? undefined : PROVIDER_REQUIREMENT[this.provider];
1289 switch (this.reason) {
1290 case "cli-missing":
1291 return (
1292 requirement?.missing ?? "The tool this host is read through is not installed or set up."
1293 );
1294 case "cli-unauthenticated":
1295 return requirement?.unauthenticated ?? "This host has no working credentials.";
1296 case "provider-unsupported":
1297 return "Change requests cannot be browsed for this project's host yet.";
1301​
1302export class PullRequestOperationError extends Schema.TaggedError<PullRequestOperationError>()(
1303 "PullRequestOperationError",
1305 operation: Schema.String,
1306 detail: TrimmedNonEmptyString,
1307 cause: Schema.optional(Schema.Defect()),
1308 },
1309 { httpApiStatus: 502 },
1310) {
1311 [HttpServerRespondable.symbol]() {
1312 return HttpServerResponse.schemaJson(PullRequestOperationError)(this, { status: 502 });
1314​
1315 override get message(): string {
1316 return `Pull request operation ${this.operation} failed: ${this.detail}`;