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

pullRequest.ts

1,482 lines65.1 KB

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