1263 lines · 55.7 KB · TypeScript
RawDownload
import * as Schema from "effect/Schema";import * as HttpServerRespondable from "effect/unstable/http/HttpServerRespondable";import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse"; import {  IsoDateTime,  NonNegativeInt,  PositiveInt,  ProjectId,  ThreadId,  TrimmedNonEmptyString,} from "./baseSchemas.ts";import { SourceControlProviderKind } from "./sourceControl.ts"; export const PullRequestInvolvement = Schema.Literals(["all", "reviewing", "authored"]);export type PullRequestInvolvement = typeof PullRequestInvolvement.Type; export const PullRequestState = Schema.Literals(["open", "closed", "merged"]);export type PullRequestState = typeof PullRequestState.Type; /** * What a listing asks for, which is the three states a change request can be in plus the option * to span them. Separate from `PullRequestState` because a change request is never "all" — only * a request for one can be. */export const PullRequestListState = Schema.Literals(["all", "open", "closed", "merged"]);export type PullRequestListState = typeof PullRequestListState.Type; /** Where a review stands overall, as a host that summarises its reviews reports it. */export const PullRequestReviewDecision = Schema.Literals([  "approved",  "changes-requested",  "review-required",]);export type PullRequestReviewDecision = typeof PullRequestReviewDecision.Type; /** One qualifier's value, bounded because it is written into a host's own search query. */const PullRequestQualifierValue = TrimmedNonEmptyString.check(Schema.isMaxLength(200));const PullRequestQualifierValues = Schema.Array(PullRequestQualifierValue).check(  Schema.isMaxLength(10),); /** * Narrowings beyond state and involvement, each absent by default — an absent field filters * nothing, which is what every listing did before there were any. Optional as a whole so a page * and a server of different ages still speak to each other. * * `checks` is host-side only: no row carries its own check state, so a host that cannot match it * answers unnarrowed rather than the page pretending to know. */export const PullRequestListFilters = Schema.Struct({  draft: Schema.optional(Schema.Literals(["only", "hide"])),  review: Schema.optional(    Schema.Literals(["approved", "changes-requested", "review-required", "none"]),  ),  checks: Schema.optional(Schema.Literals(["passing", "failing"])),  /**   * Labels as GitHub's own search reads them: each group is one `label:` qualifier, a row must   * satisfy every group, and a group holding several names is satisfied by any one of them —   * `label:size:S,size:XS` finds either size. Typed rather than picked, since a project's labels   * are its own and no menu can list them. Bounded because each becomes a host search qualifier.   */  labels: Schema.optional(Schema.Array(PullRequestQualifierValues).check(Schema.isMaxLength(10))),  excludedLabels: Schema.optional(PullRequestQualifierValues),  /** One login, as `author:` names it. */  author: Schema.optional(PullRequestQualifierValue),});export type PullRequestListFilters = typeof PullRequestListFilters.Type; /** The one-glyph summary of a change request's checks, as its list row wears it. */export const PullRequestChecksState = Schema.Literals(["passing", "failing", "pending"]);export type PullRequestChecksState = typeof PullRequestChecksState.Type; export const PullRequestMergeability = Schema.Literals(["mergeable", "conflicting", "unknown"]);export type PullRequestMergeability = typeof PullRequestMergeability.Type; export const PullRequestMergeMethod = Schema.Literals(["merge", "squash", "rebase"]);export type PullRequestMergeMethod = typeof PullRequestMergeMethod.Type; export const PullRequestAction = Schema.Literals([  "merge",  "ready",  "draft",  "close",  "reopen",  /** Bring the base branch's commits into this one, which is what unblocks a stale branch. */  "update-branch",  /**   * Hand the merge to the host: it waits for whatever it requires — a green pipeline, the   * approvals, an unblocked branch — and merges without anybody coming back. Separate from   * `merge` because the two answer different questions. `merge` is refused outright by a host   * that is not ready yet, and this one is for exactly that moment.   */  "enable-auto-merge",  /** Take the standing instruction back, which leaves the change request where it was. */  "disable-auto-merge",  /** Open a new change request that reverses a merged one. */  "revert",  /** Allow Actions workflows from a fork pull request to begin running. */  "approve-workflows",]);export type PullRequestAction = typeof PullRequestAction.Type; /** * How a stale branch catches up with its base: a merge commit, or a rebase onto it. The two are * the host's own choices, not this page's — GitHub offers both and refuses a rebase it cannot * replay, so what is offered comes from the host and what is allowed comes from the viewer. */export const PullRequestUpdateMethod = Schema.Literals(["merge", "rebase"]);export type PullRequestUpdateMethod = typeof PullRequestUpdateMethod.Type; /** * Where the branch stands against the base it would merge into. Separate from `mergeability`, * which answers a different question: a branch can be behind and still merge cleanly, and that * pairing — out of date, no conflicts — is the one an update button exists for. * * "unknown" where the host was not asked or could not say, which is every host but GitHub and * every pull request whose head repository could not be compared. */export const PullRequestBaseComparison = Schema.Literals(["up-to-date", "behind", "unknown"]);export type PullRequestBaseComparison = typeof PullRequestBaseComparison.Type; export const PullRequestActor = Schema.Struct({  login: TrimmedNonEmptyString,  name: Schema.NullOr(Schema.String),  /** Null where a host does not report one, which is what the initials fall back to. */  avatarUrl: Schema.NullOr(Schema.String),});export type PullRequestActor = typeof PullRequestActor.Type; export const PullRequestLabel = Schema.Struct({  name: TrimmedNonEmptyString,  color: Schema.NullOr(Schema.String),});export type PullRequestLabel = typeof PullRequestLabel.Type; export const PullRequestCheckStatus = Schema.Literals([  "pending",  "action-required",  "success",  "failure",  "skipped",  "neutral",  "cancelled",]);export type PullRequestCheckStatus = typeof PullRequestCheckStatus.Type; export const PullRequestCheck = Schema.Struct({  name: TrimmedNonEmptyString,  status: PullRequestCheckStatus,  description: Schema.NullOr(Schema.String),  url: Schema.NullOr(Schema.String),});export type PullRequestCheck = typeof PullRequestCheck.Type; /** * The reactions a remark can carry. GitHub's eight, which is also what the picker offers: GitLab * accepts any emoji as an award, and the ones outside this set are read as nothing rather than * shown under a name no other host would recognise. */export const PullRequestReactionContent = Schema.Literals([  "thumbs-up",  "thumbs-down",  "laugh",  "hooray",  "confused",  "heart",  "rocket",  "eyes",]);export type PullRequestReactionContent = typeof PullRequestReactionContent.Type; /** One reaction and everyone behind it, which is what the hover on a reaction pill says. */export const PullRequestReaction = Schema.Struct({  content: PullRequestReactionContent,  count: PositiveInt,  /**   * Who reacted, as far as the host named them. A host that reports fewer names than it counts   * leaves the rest out, so this is never longer than `count` and may be shorter. When   * `viewerHasReacted` is true, the viewer's own login is left out of this list — the page names   * them "You" instead — but `count` still counts them along with everyone else.   */  actors: Schema.Array(TrimmedNonEmptyString),  /** The signed-in account is one of them, so pressing the pill takes the reaction back. */  viewerHasReacted: Schema.Boolean,});export type PullRequestReaction = typeof PullRequestReaction.Type; export const PullRequestCommentKind = Schema.Literals([  "issue-comment",  "review-comment",  "review",]);export type PullRequestCommentKind = typeof PullRequestCommentKind.Type; export const PullRequestComment = Schema.Struct({  id: TrimmedNonEmptyString,  kind: PullRequestCommentKind,  author: Schema.NullOr(PullRequestActor),  body: Schema.String,  createdAt: IsoDateTime,  url: Schema.NullOr(Schema.String),  path: Schema.NullOr(Schema.String),  reviewState: Schema.NullOr(Schema.String),  /** Absent from a host with no reactions at all, which is a different thing from none on this. */  reactions: Schema.optional(Schema.Array(PullRequestReaction)),});export type PullRequestComment = typeof PullRequestComment.Type; /** * Which file a diff line belongs to: `left` is the version before the change, `right` the * version after. A comment has to name one, because a unified diff shows both at once and the * same line number means two different lines. */export const PullRequestDiffSide = Schema.Literals(["left", "right"]);export type PullRequestDiffSide = typeof PullRequestDiffSide.Type; /** What submitting a review says about the change, beyond the words in it. */export const PullRequestReviewVerdict = Schema.Literals(["comment", "approve", "request-changes"]);export type PullRequestReviewVerdict = typeof PullRequestReviewVerdict.Type; export const PullRequestThreadComment = Schema.Struct({  id: TrimmedNonEmptyString,  author: Schema.NullOr(PullRequestActor),  body: Schema.String,  createdAt: IsoDateTime,  url: Schema.NullOr(Schema.String),  reactions: Schema.optional(Schema.Array(PullRequestReaction)),});export type PullRequestThreadComment = typeof PullRequestThreadComment.Type; /** * A conversation anchored to a line of the diff. The detail carries these alongside `comments` * rather than instead of them: the timeline wants one flat, chronological list, and the diff * wants whole threads pinned to their line — the same remarks, read two different ways. */export const PullRequestReviewThread = Schema.Struct({  id: TrimmedNonEmptyString,  path: TrimmedNonEmptyString,  /** Null when the host anchors the thread to a file rather than to a line. */  line: Schema.NullOr(PositiveInt),  side: PullRequestDiffSide,  isResolved: Schema.Boolean,  /**   * The line the thread was written against is no longer in the diff, so it cannot be shown   * against the code. Such a thread is listed separately rather than pinned to the wrong line.   */  isOutdated: Schema.Boolean,  comments: Schema.Array(PullRequestThreadComment),  /** Host-reported total, when this thread was read in pages. */  commentCount: Schema.optional(NonNegativeInt),  /** Opaque cursor for the next comment page. Absent once this thread is whole. */  nextCommentsCursor: Schema.optional(TrimmedNonEmptyString),});export type PullRequestReviewThread = typeof PullRequestReviewThread.Type; /** * Whether a reviewer is a person or a group of them the host addresses as one. GitHub is the only * host here that takes a review request for a team; the others name individuals only, so nothing * they report is ever anything but a user. */export const PullRequestReviewerKind = Schema.Literals(["user", "team"]);export type PullRequestReviewerKind = typeof PullRequestReviewerKind.Type; /** * Somebody a review may be asked of. Carries the actor fields so the menu shows the same face and * handle the rest of the page does, and a team wears them too — its slug stands in for a login. */export const PullRequestReviewerCandidate = Schema.Struct({  ...PullRequestActor.fields,  /**   * How the host addresses this reviewer when a review is requested, which is not always the   * handle it shows: GitHub takes a login or a team slug, GitLab a numeric user id, Bitbucket an   * account uuid. Opaque to the page, which sends back whatever the candidate arrived with.   */  id: TrimmedNonEmptyString,  kind: PullRequestReviewerKind,  /** A review has already been asked of them, so pressing them takes the request back. */  isRequested: Schema.Boolean,});export type PullRequestReviewerCandidate = typeof PullRequestReviewerCandidate.Type; export const PullRequestReviewerCandidateList = Schema.Struct({  /** Never includes the author: nobody is asked to review their own change request. */  candidates: Schema.Array(PullRequestReviewerCandidate),  /**   * The host has more people with access than the read asked for, so somebody missing from the   * menu may still be somebody this change request can be sent to. Nothing is wrong with the   * list; it is simply not all of it.   */  truncated: Schema.Boolean,});export type PullRequestReviewerCandidateList = typeof PullRequestReviewerCandidateList.Type; /** A label the repository defines, with whether this change request already wears it. */export const PullRequestLabelCandidate = Schema.Struct({  ...PullRequestLabel.fields,  description: Schema.NullOr(Schema.String),  isApplied: Schema.Boolean,});export type PullRequestLabelCandidate = typeof PullRequestLabelCandidate.Type; export const PullRequestLabelCandidateList = Schema.Struct({  candidates: Schema.Array(PullRequestLabelCandidate),  /** The repository defines more labels than the read asked for; the list is not all of them. */  truncated: Schema.Boolean,});export type PullRequestLabelCandidateList = typeof PullRequestLabelCandidateList.Type; export const PullRequestCommit = Schema.Struct({  oid: TrimmedNonEmptyString,  messageHeadline: Schema.String,  committedDate: IsoDateTime,  /** Per-commit line counts where the host can return them without a request per commit. */  additions: Schema.optional(NonNegativeInt),  deletions: Schema.optional(NonNegativeInt),  /**   * Everyone the host attributes the commit to. Optional because older servers and hosts that   * do not expose commit authors still produce a useful timeline entry.   */  authors: Schema.optional(Schema.Array(PullRequestActor)),});export type PullRequestCommit = typeof PullRequestCommit.Type; /** * What a host can do with a review, which is where the four differ most. GitLab has no way to * say "changes requested", and Azure DevOps exposes no diff through its CLI, so it has no lines * to write against at all. */export const PullRequestReviewCapabilities = Schema.Struct({  /** A new comment can be anchored to a line of the diff. */  inlineComment: Schema.Boolean,  /** An existing thread can be replied to. */  reply: Schema.Boolean,  /** A thread can be marked resolved, and unresolved again. */  resolve: Schema.Boolean,  /** The verdicts a submitted review can carry. Empty means reviews cannot be submitted. */  verdicts: Schema.Array(PullRequestReviewVerdict),});export type PullRequestReviewCapabilities = typeof PullRequestReviewCapabilities.Type; /** * What a host lets be rewritten after it has been posted. The two are separate because a host can * take one without the other: Azure DevOps takes a new title and description through the same * command that closes a pull request, and has no way to post a remark here at all — so nothing it * shows in a conversation can be rewritten either. */export const PullRequestEditCapabilities = Schema.Struct({  /** The change request's own title and description can be rewritten. */  changeRequest: Schema.Boolean,  /** A remark can be rewritten by whoever wrote it. */  comment: Schema.Boolean,});export type PullRequestEditCapabilities = typeof PullRequestEditCapabilities.Type; /** * What a host can do about who reviews. The two are independent: a host can take a request without * publishing who may receive one, which is Azure DevOps. */export const PullRequestReviewerCapabilities = Schema.Struct({  /** A review can be asked of somebody, and the request taken back. */  request: Schema.Boolean,  /**   * The people who may be asked can be listed. False where the host has no such list to give,   * which leaves the page to take a name rather than offer a menu — a guessed list would be worse,   * because a name missing from it reads as a name that cannot be asked.   */  listCandidates: Schema.Boolean,});export type PullRequestReviewerCapabilities = typeof PullRequestReviewerCapabilities.Type; /** * What a provider can actually do, so a surface can hide what is missing rather than offer an * action that would fail. Every provider fills this in for itself; nothing is assumed. * * Hosts differ more than they look: Azure DevOps exposes no patch through its CLI, and * Bitbucket has no endpoint that reopens a declined pull request. Both would otherwise be dead * buttons. */export const PullRequestCapabilities = Schema.Struct({  /** A unified patch can be fetched for the change request. */  diff: Schema.Boolean,  /** A comment can be posted, and the conversation read back. */  comment: Schema.Boolean,  /** The actions this host can carry out; anything absent is never offered. */  actions: Schema.Array(PullRequestAction),  /** Merge strategies the provider itself offers, before repository settings narrow them. */  mergeMethods: Schema.Array(PullRequestMergeMethod),  /**   * How this host can bring a stale branch up to date. Absent where it cannot at all, which is   * every host that has not said otherwise — so a provider that says nothing offers nothing.   */  updateMethods: Schema.optional(Schema.Array(PullRequestUpdateMethod)),  /**   * The host can narrow a listing by free text. False means it answers unnarrowed and whoever   * asked has to do the narrowing — which is a different promise, so the page is told rather   * than left to show every change request on that host as a search result.   */  search: Schema.Boolean,  /**   * Reactions can be read from a remark, and added to one or taken back. One flag for both:   * neither host here reports reactions it will not also take, and a surface that could show a   * pill it may never press is a surface offering nothing. Optional for the same reason as   * `updateMethods` and `edit`: a server that says nothing about reactions has none, which is   * what every server before this field was.   */  reactions: Schema.optional(Schema.Boolean),  review: PullRequestReviewCapabilities,  reviewers: PullRequestReviewerCapabilities,  /**   * What can be rewritten after the fact. Optional so a page and a server of different ages still   * speak to each other: a server that says nothing about rewriting is one that cannot, which is   * what every server before this one was.   */  edit: Schema.optional(PullRequestEditCapabilities),  /**   * The host keeps stacks of change requests as objects of its own, so a linked thread can show   * the stack the host shows. Absent means chains are only ever inferred from base branches.   */  stacks: Schema.optional(Schema.Boolean),  stackActions: Schema.optional(Schema.Boolean),  /**   * The repository's labels can be listed, and one put on a change request or taken off it.   * Optional for the same reason `edit` is: a server that says nothing about labels has no way   * to change them, which is what every server before this field was.   */  labels: Schema.optional(Schema.Boolean),});export type PullRequestCapabilities = typeof PullRequestCapabilities.Type; /** * What the signed-in account may do with this change request, which is a different question from * `capabilities`: that says what the host is able to do at all, and this says whether this viewer * is allowed to ask for it. A host that merges pull requests still will not let a stranger merge * one, so a control belongs on the page only where the two agree. * * A permission the host reports nothing about is granted rather than withheld. Hiding a control * from someone who may in fact use it leaves them no way through and no reason given, while * offering one they may not use ends in the host's own refusal — which at least says why. */export const PullRequestViewerPermissions = Schema.Struct({  /** May request remote stack rebases, including when this layer is already current. */  stackRebase: Schema.optional(Schema.Boolean),  /** Which of the actions this viewer may take; anything absent is theirs to look at only. */  actions: Schema.Array(PullRequestAction),  /** This viewer may write a remark: a comment, a reply, or a note against a line. */  comment: Schema.Boolean,  /** This viewer may mark a review conversation resolved, and unresolved again. */  resolve: Schema.Boolean,  /** The verdicts this viewer may submit a review with. Empty means they may not review. */  verdicts: Schema.Array(PullRequestReviewVerdict),  /** This viewer may ask somebody for a review, and take the request back again. */  requestReviewers: Schema.Boolean,  /**   * The ways this viewer may bring the branch up to date, narrowed from what the host offers.   * Absent or empty means they may not, which is also what a host with no such action says.   */  updateMethods: Schema.optional(Schema.Array(PullRequestUpdateMethod)),  /**   * This viewer may put a label on the change request, and take one off. Absent is granted, like   * every permission here; the capability beside it is what decides whether a label can be   * changed on this host at all.   */  labels: Schema.optional(Schema.Boolean),});export type PullRequestViewerPermissions = typeof PullRequestViewerPermissions.Type; export const PullRequestMergeCapabilities = Schema.Struct({  merge: Schema.Boolean,  squash: Schema.Boolean,  rebase: Schema.Boolean,});export type PullRequestMergeCapabilities = typeof PullRequestMergeCapabilities.Type; export const PullRequestStackMembership = Schema.Struct({  number: PositiveInt,  position: PositiveInt,  size: PositiveInt,  base: TrimmedNonEmptyString,});export type PullRequestStackMembership = typeof PullRequestStackMembership.Type; export const PullRequestListEntry = Schema.Struct({  stack: Schema.optional(PullRequestStackMembership),  provider: SourceControlProviderKind,  /**   * The host below which `repository` is addressed, so the same provider kind can serve more   * than one account — github.com and a GitHub Enterprise install are different identities.   */  host: TrimmedNonEmptyString,  projectId: ProjectId,  projectTitle: TrimmedNonEmptyString,  repository: TrimmedNonEmptyString,  number: PositiveInt,  title: TrimmedNonEmptyString,  url: TrimmedNonEmptyString,  author: Schema.NullOr(PullRequestActor),  headBranch: TrimmedNonEmptyString,  baseBranch: TrimmedNonEmptyString,  state: PullRequestState,

Lines 1–500 of 1263.