@vite-hub/presets 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -107,15 +107,21 @@ interface GitHubHostCredentialContext {
107
107
  repository?: string;
108
108
  signal: AbortSignal;
109
109
  }
110
+ /** The GitHub user or App bot that commits and comments for the host. */
111
+ interface GitHubHostIdentity {
112
+ appId?: number;
113
+ email?: string;
114
+ login?: string;
115
+ }
110
116
  interface GitHubHostOptions {
111
117
  credentials: (context: GitHubHostCredentialContext) => GitHubHostCredentials | Promise<GitHubHostCredentials>;
112
118
  /** A `fetch` for Forge requests, for tests and runtimes without a global one. */
113
119
  fetch?: typeof fetch;
114
- identity?: {
115
- appId?: number;
116
- email?: string;
117
- login?: string;
118
- };
120
+ /**
121
+ * Commit author and comment owner. Default: the GitHub App bot of the App credentials, such as
122
+ * `my-app[bot]` with its noreply email. Set it for a token without an App.
123
+ */
124
+ identity?: GitHubHostIdentity;
119
125
  maxBuffer?: number;
120
126
  /** Forge request timeout in milliseconds. Default 60000. */
121
127
  timeout?: number;
@@ -135,6 +141,8 @@ interface GitHubHostAccess {
135
141
  token: string;
136
142
  }
137
143
  interface GitHubHostPullRequest {
144
+ /** Base branch. With it, `push()` tells `beforePush` whether every new commit outside the base is the host's. */
145
+ baseRef?: string;
138
146
  headRef?: string;
139
147
  headRepository?: string;
140
148
  headSha: string;
@@ -163,11 +171,21 @@ interface GitHubHostCheckout extends GitHubHostAccess {
163
171
  }): Promise<string>;
164
172
  push(target?: string, options?: {
165
173
  signal?: AbortSignal;
166
- beforePush?: (head?: string) => void | Promise<void>;
174
+ beforePush?: (head?: string, lineage?: GitHubHostPushLineage) => void | Promise<void>;
167
175
  afterPush?: (head: string) => void | Promise<void>;
168
176
  }): Promise<string>;
169
177
  signal: AbortSignal;
170
178
  }
179
+ /** How a pushed head relates to the head it replaces. */
180
+ interface GitHubHostPushLineage {
181
+ /** The pull request head that the push replaces. The pushed head descends from it. */
182
+ parent: string;
183
+ /**
184
+ * Every commit that the push adds, apart from commits on the base branch, is one that `commitRepair()`
185
+ * made in this checkout. A provider that fetches and merges someone else's commits makes this `false`.
186
+ */
187
+ hostOnly: boolean;
188
+ }
171
189
  interface GitHubHostCheckoutOptions {
172
190
  signal?: AbortSignal;
173
191
  timeout?: number;
@@ -190,6 +208,12 @@ interface GitHubHostAccessOptions extends GitHubHostCheckoutOptions {
190
208
  /** Mint a new App installation token when the cached one expires within this many milliseconds. */
191
209
  minLifetime?: number;
192
210
  repository?: string;
211
+ /**
212
+ * Repository whose App installation mints the token, when it is not `repository`. Git still sends the
213
+ * token only to `repository`. A fork without the App uses its base repository's installation, whose
214
+ * token may push to the fork's branch while its author allows edits by maintainers.
215
+ */
216
+ installationRepository?: string;
193
217
  }
194
218
  /** A GitHub rate limit that the response headers of this host's Forge requests reported. */
195
219
  interface GitHubHostRateLimit {
@@ -244,11 +268,7 @@ declare function createGitHubAppCredentials(app: GitHubAppEnvironment): {
244
268
  /** Sends one App webhook delivery again. */
245
269
  redeliver: (id: string, signal?: AbortSignal) => Promise<void>;
246
270
  /** The App bot's login and noreply email, used as the commit author. */
247
- identity(): Promise<{
248
- appId: number;
249
- login: string;
250
- email: string;
251
- }>;
271
+ identity(): Promise<Required<GitHubHostIdentity>>;
252
272
  };
253
273
  declare function createGitHubHost(options: GitHubHostOptions): GitHubHost;
254
274
  //#endregion
@@ -458,6 +478,13 @@ interface StatusDelivery {
458
478
  };
459
479
  }
460
480
  //#endregion
481
+ //#region src/babysitter/approval.d.ts
482
+ /** A head that the host pushed, with the head it replaced. Only heads whose new commits are all the host's own are recorded. */
483
+ interface HostHead {
484
+ head: string;
485
+ parent: string;
486
+ }
487
+ //#endregion
461
488
  //#region src/babysitter/inbox/store.d.ts
462
489
  type Snapshot = {
463
490
  repository: string;
@@ -488,6 +515,10 @@ type Snapshot = {
488
515
  token: string;
489
516
  heads: string[];
490
517
  };
518
+ /** Heads the host pushed whose new commits are all its own, oldest first. An approval carries over along them. */
519
+ hostHeads?: HostHead[];
520
+ /** Heads the host asked GitHub to update with the base. The host's own `synchronize` from one adds a `hostHeads` entry. */
521
+ hostUpdates?: string[];
491
522
  threadReopens?: Record<string, number>;
492
523
  /** Authenticated outcome replies, including IDs used by thread-only reads. */
493
524
  ownedReviewCommentIds?: string[];
@@ -570,6 +601,16 @@ interface PullRequestInboxOptions {
570
601
  /** The served repositories, or a function that returns the current lowercase list on each read. */
571
602
  repositories: readonly string[] | (() => readonly string[]);
572
603
  filter?: GitHubPullRequestFilter;
604
+ /**
605
+ * Also admit an open PR that `filter`'s author rules leave out while a reviewer with write access
606
+ * approves its current head, or a head the host built on the approved one. Every other rule still applies.
607
+ */
608
+ admitApproved?: boolean;
609
+ /**
610
+ * The time in Unix milliseconds, for tests. By default a shared `storage` inbox follows the clock of its database:
611
+ * it reads that clock at most every 30 seconds and counts elapsed time from there, so servers with different host
612
+ * clocks agree when a lease expires. A private `path` inbox has one host and uses `Date.now`.
613
+ */
573
614
  clock?: () => number;
574
615
  activityAuthors?: readonly string[];
575
616
  activityAppId?: number;
@@ -604,7 +645,11 @@ declare class PullRequestInbox {
604
645
  private tables;
605
646
  private repositoryList;
606
647
  private clock;
648
+ private usesDatabaseClock;
649
+ private clockSample?;
607
650
  private filter?;
651
+ /** Whether a maintainer's approval admits an author the filter leaves out. */
652
+ readonly admitApproved: boolean;
608
653
  private activityAuthors;
609
654
  private activityAppId?;
610
655
  private budgets;
@@ -613,9 +658,12 @@ declare class PullRequestInbox {
613
658
  private claimStackChildren;
614
659
  private invalidRow?;
615
660
  private reportedRows;
616
- constructor({ path, storage, scope, repositories, filter, clock, budgets, activityAuthors, activityAppId, priorityLabels, mainRepairBranchPrefix, claimStackChildren, invalidRow }: PullRequestInboxOptions);
661
+ constructor({ path, storage, scope, repositories, filter, admitApproved, clock, budgets, activityAuthors, activityAppId, priorityLabels, mainRepairBranchPrefix, claimStackChildren, invalidRow }: PullRequestInboxOptions);
617
662
  close(): Promise<void>;
618
663
  private init;
664
+ /** The current time on the inbox clock. Compare lease ends from the inbox with it, not with `Date.now()`. */
665
+ now(): number;
666
+ private syncClock;
619
667
  private transaction;
620
668
  private read;
621
669
  /** Parses one stored row. An invalid row is reported once and skipped by queue-wide reads. */
@@ -670,6 +718,11 @@ declare class PullRequestInbox {
670
718
  private stackFoldKey;
671
719
  /** The stacked pull request whose merge into this pull request's branch has an unknown outcome. */
672
720
  private foldingChildIn;
721
+ /**
722
+ * A closed child's fold has a known outcome, and its pending-merge path never runs again to clear it.
723
+ * Retire the attempt with the parent's slot, so a reopened child must win the slot again before it folds.
724
+ */
725
+ private retireFoldIn;
673
726
  foldingChild(repository: string, parent: number): Promise<number | undefined>;
674
727
  /**
675
728
  * Atomically records that a claim has started an irreversible merge request. With `foldInto`, the merge
@@ -694,7 +747,13 @@ declare class PullRequestInbox {
694
747
  isPriority(pr: GitHubPullRequestRecord | null | undefined): boolean;
695
748
  /** Whether the PR's head branch starts with `mainRepairBranchPrefix`. */
696
749
  isMainRepair(pr: GitHubPullRequestRecord | null | undefined): boolean;
697
- eligible(repository: string, pr: GitHubPullRequestRecord | null): boolean;
750
+ /**
751
+ * Whether the runtime acts on `pr`. With `admitApproved`, a maintainer's approval of the head in
752
+ * `snapshot` admits an author the filter leaves out. `writers` holds the reviewers whose write
753
+ * permission the caller verified; without it, the review's association stands in, which only the
754
+ * inbox's own bookkeeping relies on before a pass checks again.
755
+ */
756
+ eligible(repository: string, pr: GitHubPullRequestRecord | null, snapshot?: Pick<Snapshot, "reviews" | "hostHeads">, writers?: ReadonlySet<string>): boolean;
698
757
  seed(repository: string, value: unknown, signal?: AbortSignal): Promise<Snapshot>;
699
758
  ingest(id: string, event: string, value: unknown, signal?: AbortSignal): Promise<GitHubInboxDeliveryResult>;
700
759
  /** Leases up to `limit` eligible PRs. `skip` leaves a candidate unclaimed for this call. */
@@ -708,8 +767,29 @@ declare class PullRequestInbox {
708
767
  refreshThreads(observed: Snapshot, threads: GitHubReviewThread[], signal?: AbortSignal): Promise<boolean>;
709
768
  /** Retain a worker's verified thread resolution even when its webhook is missing. */
710
769
  recordThreadResolution(claim: Claim, id: string, observed: Snapshot): Promise<boolean>;
711
- /** Retain CI for an exact candidate before its source-push webhook arrives. This is not a publication receipt. */
712
- registerProspectivePush(claim: Claim, head: string): Promise<boolean>;
770
+ /**
771
+ * Retain CI for an exact candidate before its source-push webhook arrives. This is not a publication receipt.
772
+ * With `lineage.hostOnly`, it also records the head as the host's own work on `lineage.parent`, so an
773
+ * approval of that parent carries over to it.
774
+ */
775
+ registerProspectivePush(claim: Claim, head: string, lineage?: {
776
+ parent: string;
777
+ hostOnly: boolean;
778
+ }): Promise<boolean>;
779
+ /**
780
+ * Records that the host asks GitHub to update the PR's branch from `from` with its base, before it sends
781
+ * the request. GitHub writes the merge commit and the response carries no SHA, so the `synchronize`
782
+ * delivery that the host's own identity sends from `from` records the new head as the host's work. A
783
+ * merges API call returns the commit: pass it as `head` to record it at once. Anything but a full commit
784
+ * SHA records nothing, so the approval does not carry over.
785
+ */
786
+ registerHostUpdate(repository: string, number: number, from: string, head?: string): Promise<void>;
787
+ private addHostHead;
788
+ /**
789
+ * A webhook head move ends every pending update. Only the host's own move from a registered head carries an
790
+ * approval. A probe's synthetic `synchronize` has no `before` and leaves the updates for the webhook.
791
+ */
792
+ private settleHostUpdate;
713
793
  release(claim: Claim): Promise<boolean>;
714
794
  renew(claim: Claim, leaseUntil: number): Promise<boolean>;
715
795
  /**