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

pullRequest.ts

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