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

pullRequest.ts

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