@vite-hub/forge 0.4.1 → 0.5.1
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.
- package/README.md +11 -4
- package/dist/{association-Ds6Tgs0W-Cu9_YCGq.js → association-Ds6Tgs0W-CgBVH3ii.js} +1 -2
- package/dist/build/node.d.ts +1 -3
- package/dist/build/node.js +3 -6
- package/dist/build.d.ts +1 -1
- package/dist/build.js +1 -2
- package/dist/{forgejo-UNPc42cY.js → definition-BQFdu9ti-WxMjcAEl.js} +15 -13
- package/dist/{events-DW3SFUDA-D2rhS9D-.js → events-BL0zcgMf-9TwyYtCt.js} +3 -5
- package/dist/{events-uCMi3LHU-Bz79PQtq.js → events-DDdJnmD2-BSMoOqjV.js} +4 -5
- package/dist/{events-DjRw3KSr-C72gY7Vu.js → events-DHqSJ5KI-z2-5_1vo.js} +59 -60
- package/dist/{events-DmSWTdpS-BdJBABfI.js → events-DXE-Ul2S-BzTkugIK.js} +4 -5
- package/dist/{feed-BlzdKdNv-DbxuSgsx.js → feed-B1OiHFg0-DevZZe0y.js} +3 -5
- package/dist/{feed-CIaAZINm-Dpe9DxwK.js → feed-DROLF1tb-CtRfA_7N.js} +3 -5
- package/dist/{feed-BwdcTgZq-Bm_c8br8.js → feed-iWegqepj-ConxMpg4.js} +3 -5
- package/dist/forgejo-4sbZukng.js +6 -0
- package/dist/gitea-Cj7qy2X3.js +10 -0
- package/dist/{gitee-BXyl2_3W-dQOAjWqr.js → gitee-CKt4pEC0-BuLWggck.js} +2 -3
- package/dist/{github-CUiEF2FK.js → github-CHzhqYOr.js} +377 -293
- package/dist/{gitlab-zvWb9zOi.js → gitlab-CS0shW2u.js} +12 -10
- package/dist/{graphql-BDhuP5jN-BSpB8lWf.js → graphql-DxRA9BGO-BBbmTmWi.js} +43 -33
- package/dist/{identity-CmVEBLP5.js → identity-BwC2_3S9.js} +1 -2
- package/dist/{identity-CNTWZZuv.d.ts → identity-D2-HaDku.d.ts} +0 -2
- package/dist/index.d.ts +50 -44
- package/dist/index.js +149 -98
- package/dist/model-Biiu1CfI-CVLamGai.js +288 -0
- package/dist/{templates-BGDqQMu4-PSB43E1j.js → templates-0m5QBVIh-D1fZeoC-.js} +3 -3
- package/dist/{webhooks-Bc6QhmI8-CNgCERCq.js → webhooks-Bc6QhmI8-eK71_mJE.js} +1034 -98
- package/package.json +8 -7
- package/dist/events-C6C7lk1x-J8VCAjEX.js +0 -131
- package/dist/knot-bGebBK_B-CeDHcJUz.js +0 -350
- package/dist/tangled-8lg_73Wi-bSufNXiN.js +0 -43
- package/dist/utils-DC7MBR65-B7Vr2hFm.js +0 -1214
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { C as TokenRevokedError, D as forbiddenReason, E as WebhookVerificationError, O as isSecondaryRateLimit, S as ReadOnlyError, T as UnsupportedOperationError, _ as InsufficientScopeError, a as namespaceRef, b as NotFoundError, d as ContentNotTextError, f as ForbiddenError, g as ForgeTimeoutError, h as ForgeNetworkError, i as isUnsupported, l as AuthenticationRequiredError, m as ForgeError, n as isNamespaceRef, o as normaliseRepoName, p as ForgeApiError, r as isResolvedThread, w as UnresolvedThreadError, x as RateLimitedError } from "./model-Biiu1CfI-CVLamGai.js";
|
|
2
|
+
// ../../node_modules/.pnpm/forges@0.4.1/node_modules/forges/dist/crypto-DydCoK4e.mjs
|
|
3
3
|
const encoder = new TextEncoder();
|
|
4
4
|
function toBytes(value) {
|
|
5
5
|
return typeof value === "string" ? encoder.encode(value) : value;
|
|
@@ -121,8 +121,1012 @@ function headerValue(headers, name) {
|
|
|
121
121
|
function bodyText(body) {
|
|
122
122
|
return typeof body === "string" ? body : new TextDecoder().decode(body);
|
|
123
123
|
}
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
// ../../node_modules/.pnpm/forges@0.4.1/node_modules/forges/dist/contents-NHE4zdZf.mjs
|
|
125
|
+
/** Decodes base64, tolerating the newlines GitHub and Gitea wrap it in. */
|
|
126
|
+
function fromBase64(value) {
|
|
127
|
+
const binary = atob(value.replaceAll(/\s/g, ""));
|
|
128
|
+
const bytes = new Uint8Array(binary.length);
|
|
129
|
+
for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
|
|
130
|
+
return bytes;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Shapes bytes as the caller asked: UTF-8 text for `as: 'text'`, bytes
|
|
134
|
+
* otherwise. Rejects with {@link ContentNotTextError} when text was asked for
|
|
135
|
+
* and the bytes are not valid UTF-8.
|
|
136
|
+
*/
|
|
137
|
+
function toFileContent(bytes, file, options, context) {
|
|
138
|
+
return options?.as === "text" ? {
|
|
139
|
+
...file,
|
|
140
|
+
content: decodeText(bytes, file.path, context),
|
|
141
|
+
encoding: "utf-8"
|
|
142
|
+
} : {
|
|
143
|
+
...file,
|
|
144
|
+
content: bytes,
|
|
145
|
+
encoding: "binary"
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/** Decodes UTF-8, rejecting with {@link ContentNotTextError} that names `what` when the bytes are not text. */
|
|
149
|
+
function decodeText(bytes, what, context) {
|
|
150
|
+
try {
|
|
151
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
152
|
+
} catch (cause) {
|
|
153
|
+
throw new ContentNotTextError(`${what} is not valid UTF-8 text`, context, { cause });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/** The bytes of a file to write, with a string encoded as UTF-8. */
|
|
157
|
+
function changeBytes(content) {
|
|
158
|
+
return typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
159
|
+
}
|
|
160
|
+
/** Base64 of a file to write, with a string encoded as UTF-8. */
|
|
161
|
+
function changeBase64(content) {
|
|
162
|
+
return toBase64(changeBytes(content));
|
|
163
|
+
}
|
|
164
|
+
/** The directory that holds `path`, or `''` at the root. */
|
|
165
|
+
function directoryOf(path) {
|
|
166
|
+
const index = path.lastIndexOf("/");
|
|
167
|
+
return index < 0 ? "" : path.slice(0, index);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Looks up the files that `changes` touch with `find`, which resolves to `undefined` for a missing file,
|
|
171
|
+
* and rejects with {@link NotFoundError} when a file to delete does not exist.
|
|
172
|
+
*/
|
|
173
|
+
async function existingFiles(changes, find, context) {
|
|
174
|
+
const found = await Promise.all(changes.map(async (change) => [change.path, await find(change.path)]));
|
|
175
|
+
const missing = changes.find((change, index) => change.content === null && found[index][1] === void 0);
|
|
176
|
+
if (missing) throw new NotFoundError(`${missing.path} does not exist, so it cannot be deleted`, 404, "", context);
|
|
177
|
+
return new Map(found.flatMap(([path, file]) => file === void 0 ? [] : [[path, file]]));
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Finds files by listing their directories, once per directory.
|
|
181
|
+
* @param list Reads the entries of a directory by their full path, or `undefined` when it does not exist.
|
|
182
|
+
*/
|
|
183
|
+
function inDirectories(list) {
|
|
184
|
+
const listings = /* @__PURE__ */ new Map();
|
|
185
|
+
return async (path) => {
|
|
186
|
+
const directory = directoryOf(path);
|
|
187
|
+
if (!listings.has(directory)) listings.set(directory, list(directory));
|
|
188
|
+
return (await listings.get(directory))?.get(path);
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/** The first line of a commit message and the rest, as forges that take them apart expect. */
|
|
192
|
+
function splitMessage(message) {
|
|
193
|
+
const [headline = "", ...rest] = message.split("\n");
|
|
194
|
+
const body = rest.join("\n").replace(/^\n+/, "");
|
|
195
|
+
return body ? {
|
|
196
|
+
headline,
|
|
197
|
+
body
|
|
198
|
+
} : { headline };
|
|
199
|
+
}
|
|
200
|
+
/** True for a full SHA-1 or SHA-256 commit id, which needs no lookup to resolve. */
|
|
201
|
+
function isSha(ref) {
|
|
202
|
+
return /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i.test(ref);
|
|
203
|
+
}
|
|
204
|
+
// ../../node_modules/.pnpm/forges@0.4.1/node_modules/forges/dist/utils-DEwhctg5.mjs
|
|
205
|
+
const BODY_EXCERPT_LENGTH = 512;
|
|
206
|
+
const REDIRECT_STATUSES = /* @__PURE__ */ new Set([
|
|
207
|
+
301,
|
|
208
|
+
302,
|
|
209
|
+
303,
|
|
210
|
+
307,
|
|
211
|
+
308
|
|
212
|
+
]);
|
|
213
|
+
/** A forge's plain-text rate limit refusal, such as Gitee's `403 Forbidden (Rate Limit Exceeded)`. */
|
|
214
|
+
const PLAIN_RATE_LIMIT_RE = /^[^{<]{0,80}\brate limit exceeded\b/i;
|
|
215
|
+
const DOT_SEGMENT_RE = /^(?:\.|%2e){1,2}$/i;
|
|
216
|
+
/** Parses an RFC 5988 `Link` header into a map of rel to URL. */
|
|
217
|
+
function parseLinkHeader(header) {
|
|
218
|
+
const links = {};
|
|
219
|
+
if (!header) return links;
|
|
220
|
+
for (const part of header.split(",")) {
|
|
221
|
+
const match = /^<([^>]+)>\s*;\s*(.+)/.exec(part.trim());
|
|
222
|
+
if (!match?.[1] || !match[2]) continue;
|
|
223
|
+
const rel = /rel\s*=\s*"?([^";]+)"?/.exec(match[2])?.[1];
|
|
224
|
+
if (rel) links[rel.trim()] = match[1];
|
|
225
|
+
}
|
|
226
|
+
return links;
|
|
227
|
+
}
|
|
228
|
+
function cursorFrom(response) {
|
|
229
|
+
const next = parseLinkHeader(response.headers.get("link")).next;
|
|
230
|
+
const etag = response.headers.get("etag") ?? void 0;
|
|
231
|
+
if (!next && !etag) return;
|
|
232
|
+
return {
|
|
233
|
+
nextUrl: next,
|
|
234
|
+
etag
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
/** The page size a URL carries, under the names forges use for it. */
|
|
238
|
+
function pageSize(url) {
|
|
239
|
+
for (const name of [
|
|
240
|
+
"per_page",
|
|
241
|
+
"limit",
|
|
242
|
+
"perPage",
|
|
243
|
+
"pagelen"
|
|
244
|
+
]) {
|
|
245
|
+
const value = Number(url.searchParams.get(name));
|
|
246
|
+
if (Number.isInteger(value) && value > 0) return value;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* The exact total a response reports in a pagination header. GitLab sends
|
|
251
|
+
* `x-total`, and Forgejo and Gitea send `x-total-count`. A Forgejo or Gitea
|
|
252
|
+
* timeline reports the page's own length there, so a count no larger than the
|
|
253
|
+
* page is ignored for timeline requests; everywhere else it is exact, even
|
|
254
|
+
* when it equals the number of items on a single page.
|
|
255
|
+
*/
|
|
256
|
+
function headerTotal(response, itemCount, requestUrl) {
|
|
257
|
+
const total = headerNumber(response, "x-total");
|
|
258
|
+
if (total !== void 0) return total;
|
|
259
|
+
const counted = headerNumber(response, "x-total-count");
|
|
260
|
+
if (counted === void 0) return;
|
|
261
|
+
return counted <= itemCount && /\/timeline(?:\?|$)/.test(requestUrl) ? void 0 : counted;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* The total a `Link` header implies: the page number of its `rel="last"`
|
|
265
|
+
* entry times the page size that URL, or the request URL, reports. GitHub,
|
|
266
|
+
* GitLab, Forgejo and Gitea page by number, so their last page times their
|
|
267
|
+
* page size approximates the total. A last page of one means a single page,
|
|
268
|
+
* whose total is the items on it. `undefined` when the header carries no
|
|
269
|
+
* usable last page.
|
|
270
|
+
*/
|
|
271
|
+
function linkTotal(header, requestUrl, itemCount) {
|
|
272
|
+
const last = parseLinkHeader(header).last;
|
|
273
|
+
if (!last) return;
|
|
274
|
+
let lastUrl;
|
|
275
|
+
let request;
|
|
276
|
+
try {
|
|
277
|
+
lastUrl = new URL(last);
|
|
278
|
+
request = new URL(requestUrl);
|
|
279
|
+
} catch {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const page = Number(lastUrl.searchParams.get("page"));
|
|
283
|
+
if (!Number.isInteger(page) || page < 1) return;
|
|
284
|
+
if (page === 1) return itemCount;
|
|
285
|
+
const size = pageSize(lastUrl) ?? pageSize(request);
|
|
286
|
+
return size === void 0 ? void 0 : page * size;
|
|
287
|
+
}
|
|
288
|
+
function retryAfterMs(response) {
|
|
289
|
+
const header = response.headers.get("retry-after");
|
|
290
|
+
if (!header) return;
|
|
291
|
+
const seconds = Number(header);
|
|
292
|
+
if (Number.isFinite(seconds)) return seconds * 1e3;
|
|
293
|
+
const date = Date.parse(header);
|
|
294
|
+
return Number.isNaN(date) ? void 0 : Math.max(0, date - Date.now());
|
|
295
|
+
}
|
|
296
|
+
/** `x-ratelimit-reset` and `ratelimit-reset` hold a Unix time in seconds on some forges, and seconds from now on others. */
|
|
297
|
+
function resetDate(response, now) {
|
|
298
|
+
const reset = headerNumber(response, "x-ratelimit-reset", "ratelimit-reset");
|
|
299
|
+
if (reset === void 0) return;
|
|
300
|
+
return new Date(reset > 1e9 ? reset * 1e3 : now + reset * 1e3);
|
|
301
|
+
}
|
|
302
|
+
/** A budget with requests left resets on its own schedule, which says nothing about when a secondary limit lifts. */
|
|
303
|
+
function rateLimitReset(response, budget) {
|
|
304
|
+
const after = retryAfterMs(response);
|
|
305
|
+
if (after !== void 0) return new Date(Date.now() + after);
|
|
306
|
+
return budget?.remaining ? void 0 : budget?.resetAt;
|
|
307
|
+
}
|
|
308
|
+
/** The leading number of the first of `names` to hold one, such as `60` of `60, 60;w=3600`. */
|
|
309
|
+
function headerNumber(response, ...names) {
|
|
310
|
+
for (const name of names) {
|
|
311
|
+
const value = response.headers.get(name)?.split(/[,;]/, 1)[0].trim();
|
|
312
|
+
if (value && Number.isFinite(Number(value))) return Number(value);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/** The members of a structured-field list such as `"burst";r=10;t=5, "day";r=900;t=3600`, by name. */
|
|
316
|
+
function fieldMembers(response, name) {
|
|
317
|
+
const members = /* @__PURE__ */ new Map();
|
|
318
|
+
for (const member of response.headers.get(name)?.split(",") ?? []) {
|
|
319
|
+
const [key = "", ...params] = member.split(";");
|
|
320
|
+
members.set(key.trim().replace(/^"(.*)"$/, "$1"), Object.fromEntries(params.map((param) => {
|
|
321
|
+
const [field = "", value] = param.split("=");
|
|
322
|
+
return [field.trim(), Number(value)];
|
|
323
|
+
})));
|
|
324
|
+
}
|
|
325
|
+
return members;
|
|
326
|
+
}
|
|
327
|
+
/** The IETF `ratelimit` and `ratelimit-policy` fields, for the policy with the fewest requests left. */
|
|
328
|
+
function structuredRateLimit(response, now) {
|
|
329
|
+
const [name, state] = [...fieldMembers(response, "ratelimit")].filter(([, params]) => Number.isFinite(params.r)).sort(([, a], [, b]) => a.r - b.r)[0] ?? [];
|
|
330
|
+
if (!state) return;
|
|
331
|
+
const limit = fieldMembers(response, "ratelimit-policy").get(name)?.q;
|
|
332
|
+
return {
|
|
333
|
+
...Number.isFinite(limit) ? { limit } : {},
|
|
334
|
+
remaining: state.r,
|
|
335
|
+
...Number.isFinite(state.t) ? { resetAt: new Date(now + state.t * 1e3) } : {},
|
|
336
|
+
...name ? { resource: name } : {}
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/** The request budget a response reports, from `x-ratelimit-*` or `ratelimit-*` headers, or the IETF `ratelimit` field. */
|
|
340
|
+
function rateLimitOf(response, now = Date.now()) {
|
|
341
|
+
const limit = headerNumber(response, "x-ratelimit-limit", "ratelimit-limit");
|
|
342
|
+
const remaining = headerNumber(response, "x-ratelimit-remaining", "ratelimit-remaining");
|
|
343
|
+
const reset = resetDate(response, now);
|
|
344
|
+
if (limit === void 0 && remaining === void 0 && reset === void 0) return structuredRateLimit(response, now);
|
|
345
|
+
const resource = response.headers.get("x-ratelimit-resource") || response.headers.get("ratelimit-name") || void 0;
|
|
346
|
+
return {
|
|
347
|
+
...limit === void 0 ? {} : { limit },
|
|
348
|
+
...remaining === void 0 ? {} : { remaining },
|
|
349
|
+
...reset === void 0 ? {} : { resetAt: reset },
|
|
350
|
+
...resource === void 0 ? {} : { resource }
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
/** Whether the `message` or an `errors[].message` of a JSON error body names a secondary rate limit. */
|
|
354
|
+
function scopeList(header) {
|
|
355
|
+
return header === null ? void 0 : header.split(",").map((scope) => scope.trim()).filter(Boolean);
|
|
356
|
+
}
|
|
357
|
+
function namesSecondaryRateLimit(body) {
|
|
358
|
+
let parsed;
|
|
359
|
+
try {
|
|
360
|
+
parsed = JSON.parse(body);
|
|
361
|
+
} catch {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
const { message, errors } = parsed ?? {};
|
|
365
|
+
return [message, ...Array.isArray(errors) ? errors.map((error) => error?.message) : []].some((text) => typeof text === "string" && isSecondaryRateLimit(text));
|
|
366
|
+
}
|
|
367
|
+
/** GitHub sends a secondary limit as a 403 or a 429, and its content creation limit can arrive as a 422. */
|
|
368
|
+
function isRateLimited(response, budget, body) {
|
|
369
|
+
if (response.status === 429) return true;
|
|
370
|
+
if ((response.status === 403 || response.status === 422) && namesSecondaryRateLimit(body)) return true;
|
|
371
|
+
if (response.status !== 403 || budget?.limit === 0) return false;
|
|
372
|
+
return budget?.remaining === 0 || response.headers.has("retry-after") || !budget && PLAIN_RATE_LIMIT_RE.test(body.trim());
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* One signal that aborts when any of `signals` does. `AbortSignal.any` would
|
|
376
|
+
* do this, but StarlingMonkey (the wasm runtime) does not implement it.
|
|
377
|
+
*/
|
|
378
|
+
function anySignal(signals) {
|
|
379
|
+
const aborted = signals.find((signal) => signal.aborted);
|
|
380
|
+
if (aborted) return aborted;
|
|
381
|
+
if (signals.length === 1) return signals[0];
|
|
382
|
+
const controller = new AbortController();
|
|
383
|
+
const listeners = [];
|
|
384
|
+
for (const signal of signals) {
|
|
385
|
+
const listener = () => {
|
|
386
|
+
controller.abort(signal.reason);
|
|
387
|
+
for (const [other, removed] of listeners) other.removeEventListener("abort", removed);
|
|
388
|
+
};
|
|
389
|
+
listeners.push([signal, listener]);
|
|
390
|
+
signal.addEventListener("abort", listener, { once: true });
|
|
391
|
+
}
|
|
392
|
+
return controller.signal;
|
|
393
|
+
}
|
|
394
|
+
function assertUrl(url) {
|
|
395
|
+
if (url.protocol !== "https:" && url.protocol !== "http:" || url.username || url.password) throw new TypeError("Invalid request URL");
|
|
396
|
+
return url;
|
|
397
|
+
}
|
|
398
|
+
function assertInput(input) {
|
|
399
|
+
for (const char of input) {
|
|
400
|
+
const code = char.charCodeAt(0);
|
|
401
|
+
if (code <= 32 || code === 127) throw new TypeError("Invalid request URL");
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
function assertRelativePath(path) {
|
|
405
|
+
const pathname = path.split("?", 1)[0];
|
|
406
|
+
if (path.includes("#") || pathname.includes("\\") || pathname.split("/").some((segment) => DOT_SEGMENT_RE.test(segment))) throw new TypeError(`Unsafe request path ${JSON.stringify(path)}; check the refs passed to the provider`);
|
|
407
|
+
return path;
|
|
408
|
+
}
|
|
409
|
+
function sleep(ms, signal) {
|
|
410
|
+
return new Promise((resolve, reject) => {
|
|
411
|
+
if (signal?.aborted) {
|
|
412
|
+
reject(signal.reason);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
const timer = setTimeout(() => {
|
|
416
|
+
signal?.removeEventListener("abort", onAbort);
|
|
417
|
+
resolve();
|
|
418
|
+
}, ms);
|
|
419
|
+
function onAbort() {
|
|
420
|
+
clearTimeout(timer);
|
|
421
|
+
reject(signal.reason);
|
|
422
|
+
}
|
|
423
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
/** Settles as `promise` does, or rejects with the signal's reason once it aborts, leaving `promise` running. */
|
|
427
|
+
function abortable(promise, signal) {
|
|
428
|
+
if (!signal) return promise;
|
|
429
|
+
if (signal.aborted) return Promise.reject(signal.reason);
|
|
430
|
+
return new Promise((resolve, reject) => {
|
|
431
|
+
const onAbort = () => reject(signal.reason);
|
|
432
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
433
|
+
promise.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Creates a fetcher for one forge API.
|
|
438
|
+
* @param options The base URL and the credentials, timeout and error context of every request.
|
|
439
|
+
*/
|
|
440
|
+
function createFetcher(options) {
|
|
441
|
+
const timeout = options.timeout ?? 3e4;
|
|
442
|
+
const doFetch = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
443
|
+
assertInput(options.baseUrl);
|
|
444
|
+
const base = assertUrl(new URL(options.baseUrl));
|
|
445
|
+
if (base.search || base.hash) throw new TypeError("Invalid API base URL");
|
|
446
|
+
base.pathname = `${base.pathname.replace(/\/$/, "")}/`;
|
|
447
|
+
const baseOrigin = base.origin;
|
|
448
|
+
function resolve(path, query) {
|
|
449
|
+
assertInput(path);
|
|
450
|
+
let url;
|
|
451
|
+
try {
|
|
452
|
+
url = new URL(path);
|
|
453
|
+
} catch {
|
|
454
|
+
if (path.startsWith("//") || path.split("/", 1)[0].includes(":")) throw new TypeError("Invalid request URL");
|
|
455
|
+
}
|
|
456
|
+
url = assertUrl(url ?? new URL(assertRelativePath(path).replace(/^\//, ""), base));
|
|
457
|
+
for (const [key, value] of Object.entries(query ?? {})) if (value !== void 0) url.searchParams.set(key, String(value));
|
|
458
|
+
return url.toString();
|
|
459
|
+
}
|
|
460
|
+
function withDefaultQuery(url) {
|
|
461
|
+
if (!options.query) return url;
|
|
462
|
+
const target = new URL(url);
|
|
463
|
+
for (const [key, value] of Object.entries(options.query)) if (!target.searchParams.has(key)) target.searchParams.set(key, value);
|
|
464
|
+
return target.toString();
|
|
465
|
+
}
|
|
466
|
+
async function send(url, options_, attempt, authenticated = true, download = false, redirects = 0, streaming = false, follow = false) {
|
|
467
|
+
const target = assertUrl(new URL(url));
|
|
468
|
+
const trusted = authenticated && target.origin === baseOrigin;
|
|
469
|
+
const controller = streaming ? new AbortController() : void 0;
|
|
470
|
+
const timer = controller ? setTimeout(() => controller.abort(new DOMException("Request timed out", "TimeoutError")), timeout) : void 0;
|
|
471
|
+
const signals = [controller?.signal ?? AbortSignal.timeout(timeout)];
|
|
472
|
+
if (options_.signal) signals.push(options_.signal);
|
|
473
|
+
const headers = new Headers(trusted ? options.headers : void 0);
|
|
474
|
+
for (const [key, value] of Object.entries(trusted ? await (options.authHeaders?.() ?? {}) : {})) headers.set(key, value);
|
|
475
|
+
for (const [key, value] of new Headers(options_.headers)) headers.set(key, value);
|
|
476
|
+
if (options_.etag) headers.set("if-none-match", options_.etag);
|
|
477
|
+
const { json: payload, mapError: _mapError, ...init } = options_;
|
|
478
|
+
if (payload !== void 0) headers.set("content-type", "application/json");
|
|
479
|
+
let response;
|
|
480
|
+
try {
|
|
481
|
+
response = await doFetch(trusted ? withDefaultQuery(url) : url, {
|
|
482
|
+
...init,
|
|
483
|
+
redirect: follow ? "follow" : "manual",
|
|
484
|
+
credentials: trusted ? init.credentials : "omit",
|
|
485
|
+
headers,
|
|
486
|
+
body: payload === void 0 ? init.body : JSON.stringify(payload),
|
|
487
|
+
signal: anySignal(signals)
|
|
488
|
+
});
|
|
489
|
+
} catch (cause) {
|
|
490
|
+
if (options_.signal?.aborted) throw options_.signal.reason ?? cause;
|
|
491
|
+
if (cause instanceof Error && (cause.name === "TimeoutError" || cause.name === "AbortError")) throw new ForgeTimeoutError(`Request to ${url} timed out after ${timeout}ms`, timeout, {
|
|
492
|
+
...options.context,
|
|
493
|
+
url,
|
|
494
|
+
method: options_.method ?? "GET"
|
|
495
|
+
}, { cause });
|
|
496
|
+
const inner = cause instanceof Error ? cause.cause : void 0;
|
|
497
|
+
const reason = typeof inner?.code === "string" ? inner.code : inner?.message;
|
|
498
|
+
throw new ForgeNetworkError(`Request to ${url} failed: ${cause instanceof Error ? cause.message : String(cause)}${typeof reason === "string" && reason ? ` (${reason})` : ""}`, {
|
|
499
|
+
...options.context,
|
|
500
|
+
url,
|
|
501
|
+
method: options_.method ?? "GET"
|
|
502
|
+
}, { cause });
|
|
503
|
+
} finally {
|
|
504
|
+
clearTimeout(timer);
|
|
505
|
+
}
|
|
506
|
+
if (response.type === "opaqueredirect" && options_.redirect !== "manual") {
|
|
507
|
+
const method = (options_.method ?? "GET").toUpperCase();
|
|
508
|
+
if (options_.redirect === "error" || method !== "GET" && method !== "HEAD") throw new TypeError("Hidden redirect refused");
|
|
509
|
+
return send(url, options_, attempt, authenticated, download, redirects, streaming, true);
|
|
510
|
+
}
|
|
511
|
+
if (follow && response.redirected && response.url) {
|
|
512
|
+
const final = assertUrl(new URL(response.url));
|
|
513
|
+
if (final.origin !== target.origin && !download || target.protocol === "https:" && final.protocol !== "https:") {
|
|
514
|
+
await response.body?.cancel();
|
|
515
|
+
throw new TypeError("Unsafe request redirect");
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
const budget = rateLimitOf(response);
|
|
519
|
+
if (budget && options.onRateLimit && target.origin === baseOrigin) options.onRateLimit({
|
|
520
|
+
url,
|
|
521
|
+
method: options_.method ?? "GET",
|
|
522
|
+
rateLimit: budget
|
|
523
|
+
});
|
|
524
|
+
const location = REDIRECT_STATUSES.has(response.status) ? response.headers.get("location") : null;
|
|
525
|
+
if (location && options_.redirect !== "manual") {
|
|
526
|
+
await response.body?.cancel();
|
|
527
|
+
if (options_.redirect === "error" || redirects >= 20) throw new TypeError("Request redirect refused");
|
|
528
|
+
assertInput(location);
|
|
529
|
+
const next = assertUrl(new URL(location, target));
|
|
530
|
+
const sameOrigin = next.origin === target.origin;
|
|
531
|
+
if (!sameOrigin && !download || target.protocol === "https:" && next.protocol !== "https:") throw new TypeError("Unsafe request redirect");
|
|
532
|
+
const method = (options_.method ?? "GET").toUpperCase();
|
|
533
|
+
if (!sameOrigin && method !== "GET" && method !== "HEAD") throw new TypeError("Unsafe request redirect");
|
|
534
|
+
let nextOptions = options_;
|
|
535
|
+
if (!sameOrigin) nextOptions = {
|
|
536
|
+
method,
|
|
537
|
+
signal: options_.signal,
|
|
538
|
+
credentials: "omit"
|
|
539
|
+
};
|
|
540
|
+
else if (response.status === 303 && method !== "HEAD" || (response.status === 301 || response.status === 302) && method === "POST") {
|
|
541
|
+
const nextHeaders = new Headers(options_.headers);
|
|
542
|
+
for (const name of [
|
|
543
|
+
"content-type",
|
|
544
|
+
"content-length",
|
|
545
|
+
"content-encoding",
|
|
546
|
+
"content-language",
|
|
547
|
+
"content-location"
|
|
548
|
+
]) nextHeaders.delete(name);
|
|
549
|
+
nextOptions = {
|
|
550
|
+
...options_,
|
|
551
|
+
method: "GET",
|
|
552
|
+
body: void 0,
|
|
553
|
+
json: void 0,
|
|
554
|
+
headers: nextHeaders
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
return send(next.toString(), nextOptions, attempt, authenticated && sameOrigin, download, redirects + 1, streaming);
|
|
558
|
+
}
|
|
559
|
+
if (response.ok || response.status === 304 || options_.redirect === "manual" && (response.type === "opaqueredirect" || response.status >= 300 && response.status < 400)) return response;
|
|
560
|
+
const text = await response.text();
|
|
561
|
+
const body = text.slice(0, BODY_EXCERPT_LENGTH);
|
|
562
|
+
const context = {
|
|
563
|
+
...options.context,
|
|
564
|
+
url,
|
|
565
|
+
method: options_.method ?? "GET"
|
|
566
|
+
};
|
|
567
|
+
const credentialed = trusted && options.authenticated || headers.has("authorization");
|
|
568
|
+
if (response.status === 401) throw credentialed ? new TokenRevokedError("Credentials were rejected by the forge", 401, body, context) : new AuthenticationRequiredError("Credentials are required for this request", 401, body, context);
|
|
569
|
+
if (response.status === 403 && !credentialed && budget?.limit === 0) throw new AuthenticationRequiredError("Credentials are required for this request", 403, body, context);
|
|
570
|
+
if (response.status === 404) throw new NotFoundError(`Nothing found at ${options_.method ?? "GET"} ${url}, or the credential cannot see it`, 404, body, context);
|
|
571
|
+
if (isRateLimited(response, budget, text)) {
|
|
572
|
+
const secondary = namesSecondaryRateLimit(text) || budget?.remaining !== 0 && (response.status !== 429 || response.headers.has("retry-after"));
|
|
573
|
+
const wait = retryAfterMs(response);
|
|
574
|
+
if (attempt === 0 && wait !== void 0 && wait <= 6e4) {
|
|
575
|
+
options.onRetry?.({
|
|
576
|
+
url,
|
|
577
|
+
method: options_.method ?? "GET",
|
|
578
|
+
wait
|
|
579
|
+
});
|
|
580
|
+
await sleep(wait, options_.signal);
|
|
581
|
+
return send(url, options_, attempt + 1, authenticated, download, redirects, streaming, follow);
|
|
582
|
+
}
|
|
583
|
+
throw new RateLimitedError("Rate limited by the forge", response.status, body, {
|
|
584
|
+
...context,
|
|
585
|
+
resetAt: rateLimitReset(response, budget),
|
|
586
|
+
secondary
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
if (response.status === 403) {
|
|
590
|
+
const acceptedScopes = scopeList(response.headers.get("x-accepted-oauth-scopes"));
|
|
591
|
+
const grantedScopes = scopeList(response.headers.get("x-oauth-scopes"));
|
|
592
|
+
const missingScope = acceptedScopes?.length && !acceptedScopes.some((scope) => grantedScopes?.includes(scope));
|
|
593
|
+
const ssoUrl = response.headers.get("x-github-sso")?.match(/\burl=(\S+)/)?.[1];
|
|
594
|
+
const forbidden = missingScope ? void 0 : ssoUrl ? {
|
|
595
|
+
reason: "sso_required",
|
|
596
|
+
reasonRaw: forbiddenReason(body)?.reasonRaw
|
|
597
|
+
} : forbiddenReason(body);
|
|
598
|
+
if (!forbidden) {
|
|
599
|
+
const acceptedPermissionsRaw = response.headers.get("x-accepted-github-permissions") || void 0;
|
|
600
|
+
throw new InsufficientScopeError("Credentials lack the scope or permission for this request", 403, body, {
|
|
601
|
+
...context,
|
|
602
|
+
acceptedScopes,
|
|
603
|
+
grantedScopes,
|
|
604
|
+
acceptedPermissionsRaw
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
throw new ForbiddenError(`Forge refused the request (${forbidden.reason})`, 403, body, forbidden.reason, {
|
|
608
|
+
...context,
|
|
609
|
+
reasonRaw: forbidden.reasonRaw,
|
|
610
|
+
ssoUrl
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
throw new ForgeApiError(`Forge responded with ${response.status} for ${options_.method ?? "GET"} ${url}`, response.status, body, context);
|
|
614
|
+
}
|
|
615
|
+
async function raw(path, options_ = {}) {
|
|
616
|
+
try {
|
|
617
|
+
return await send(resolve(path, options_.query), options_, 0);
|
|
618
|
+
} catch (error) {
|
|
619
|
+
throw options_.mapError ? options_.mapError(error) : error;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
async function json(path, options_ = {}) {
|
|
623
|
+
const response = await raw(path, options_);
|
|
624
|
+
if (response.status === 304 || response.status === 204) return {
|
|
625
|
+
data: void 0,
|
|
626
|
+
response,
|
|
627
|
+
notModified: response.status === 304,
|
|
628
|
+
cursor: cursorFrom(response)
|
|
629
|
+
};
|
|
630
|
+
const text = await response.text();
|
|
631
|
+
return {
|
|
632
|
+
data: text ? parseJson(text) : void 0,
|
|
633
|
+
response,
|
|
634
|
+
notModified: false,
|
|
635
|
+
cursor: cursorFrom(response)
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
async function page(path, options_ = {}) {
|
|
639
|
+
const { select, cursor, conditional = true, ...requestOptions } = options_;
|
|
640
|
+
const initial = resolve(path, requestOptions.query);
|
|
641
|
+
const url = cursor?.nextUrl ? resolve(cursor.nextUrl) : initial;
|
|
642
|
+
if (new URL(url).origin !== new URL(initial).origin) throw new TypeError("Pagination URL must remain on the requested origin");
|
|
643
|
+
const first = conditional && !cursor?.nextUrl && !cursor?.token;
|
|
644
|
+
const sent = first ? requestOptions.etag ?? cursor?.etag : void 0;
|
|
645
|
+
const result = await json(url, {
|
|
646
|
+
...requestOptions,
|
|
647
|
+
etag: sent,
|
|
648
|
+
query: void 0
|
|
649
|
+
});
|
|
650
|
+
const validator = first ? result.response.headers.get("etag") ?? (result.notModified ? sent : void 0) : void 0;
|
|
651
|
+
const etag = validator ? { etag: validator } : {};
|
|
652
|
+
if (result.notModified) return {
|
|
653
|
+
...result,
|
|
654
|
+
data: [],
|
|
655
|
+
cursor: void 0,
|
|
656
|
+
...etag
|
|
657
|
+
};
|
|
658
|
+
const next = select ? select(result.data, result.cursor?.nextUrl) : void 0;
|
|
659
|
+
const items = next ? next.items : result.data ?? [];
|
|
660
|
+
const total = next?.total ?? headerTotal(result.response, items.length, url) ?? linkTotal(result.response.headers.get("link"), url, items.length);
|
|
661
|
+
if (!next) return {
|
|
662
|
+
...result,
|
|
663
|
+
data: items,
|
|
664
|
+
cursor: result.cursor?.nextUrl ? result.cursor : void 0,
|
|
665
|
+
...total !== void 0 ? { total } : {},
|
|
666
|
+
...etag
|
|
667
|
+
};
|
|
668
|
+
return {
|
|
669
|
+
...result,
|
|
670
|
+
data: items,
|
|
671
|
+
cursor: next.next ? {
|
|
672
|
+
...result.cursor,
|
|
673
|
+
nextUrl: next.next
|
|
674
|
+
} : void 0,
|
|
675
|
+
...total !== void 0 ? { total } : {},
|
|
676
|
+
...etag
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
async function* items(path, options_ = {}) {
|
|
680
|
+
let cursor;
|
|
681
|
+
do {
|
|
682
|
+
const result = await page(path, {
|
|
683
|
+
...options_,
|
|
684
|
+
cursor
|
|
685
|
+
});
|
|
686
|
+
yield* result.data ?? [];
|
|
687
|
+
cursor = result.notModified ? void 0 : result.cursor;
|
|
688
|
+
} while (cursor?.nextUrl);
|
|
689
|
+
}
|
|
690
|
+
async function stream(path, options_ = {}) {
|
|
691
|
+
try {
|
|
692
|
+
const response = await send(resolve(path, options_.query), options_, 0, true, true, 0, true);
|
|
693
|
+
return {
|
|
694
|
+
status: response.status,
|
|
695
|
+
headers: response.headers,
|
|
696
|
+
body: response.body ?? emptyStream()
|
|
697
|
+
};
|
|
698
|
+
} catch (error) {
|
|
699
|
+
throw options_.mapError ? options_.mapError(error) : error;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return {
|
|
703
|
+
raw,
|
|
704
|
+
stream,
|
|
705
|
+
json,
|
|
706
|
+
page,
|
|
707
|
+
items,
|
|
708
|
+
resolve
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
const LONG_NUMBER_RE = /\d{16}/;
|
|
712
|
+
const INTEGER_RE = /^-?\d+$/;
|
|
713
|
+
/**
|
|
714
|
+
* Parses JSON, keeping integers beyond `Number.MAX_SAFE_INTEGER` (such as
|
|
715
|
+
* GitHub webhook delivery ids) as their exact digits, where the runtime gives
|
|
716
|
+
* the reviver the source text.
|
|
717
|
+
*/
|
|
718
|
+
function parseJson(text) {
|
|
719
|
+
if (!LONG_NUMBER_RE.test(text)) return JSON.parse(text);
|
|
720
|
+
return JSON.parse(text, (_key, value, context) => typeof value === "number" && !Number.isSafeInteger(value) && context?.source && INTEGER_RE.test(context.source) ? context.source : value);
|
|
721
|
+
}
|
|
722
|
+
function emptyStream() {
|
|
723
|
+
return new Blob([]).stream();
|
|
724
|
+
}
|
|
725
|
+
const SAFE_METHODS = /* @__PURE__ */ new Set([
|
|
726
|
+
"GET",
|
|
727
|
+
"HEAD",
|
|
728
|
+
"OPTIONS"
|
|
729
|
+
]);
|
|
730
|
+
/**
|
|
731
|
+
* Builds a provider's `request()` escape hatch on top of its fetcher.
|
|
732
|
+
* @param fetcher The fetcher to send requests with.
|
|
733
|
+
* @param createOptions Where to reject writes, for a read-only provider.
|
|
734
|
+
*/
|
|
735
|
+
function createRequest(fetcher, createOptions = {}) {
|
|
736
|
+
const { readOnly } = createOptions;
|
|
737
|
+
return (async (method, path, options = {}) => {
|
|
738
|
+
const upperMethod = method.toUpperCase();
|
|
739
|
+
if (readOnly && (options.mutates ?? !SAFE_METHODS.has(upperMethod))) throw readOnly(upperMethod, path);
|
|
740
|
+
const json = options.body !== void 0 && isJsonBody(options.body);
|
|
741
|
+
const init = {
|
|
742
|
+
method: upperMethod,
|
|
743
|
+
query: options.query,
|
|
744
|
+
signal: options.signal,
|
|
745
|
+
headers: {
|
|
746
|
+
...json ? { "content-type": "application/json" } : {},
|
|
747
|
+
...options.headers
|
|
748
|
+
},
|
|
749
|
+
body: options.body === void 0 ? void 0 : json ? JSON.stringify(options.body) : options.body
|
|
750
|
+
};
|
|
751
|
+
if ("raw" in options && options.raw) return fetcher.stream(path, init);
|
|
752
|
+
const result = await fetcher.json(path, init);
|
|
753
|
+
const rateLimit = rateLimitOf(result.response);
|
|
754
|
+
return {
|
|
755
|
+
status: result.response.status,
|
|
756
|
+
data: result.data,
|
|
757
|
+
headers: result.response.headers,
|
|
758
|
+
...rateLimit ? { rateLimit } : {}
|
|
759
|
+
};
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
function isJsonBody(value) {
|
|
763
|
+
return typeof value !== "string" && !(value instanceof ArrayBuffer) && !ArrayBuffer.isView(value) && !(typeof Blob !== "undefined" && value instanceof Blob) && !(typeof FormData !== "undefined" && value instanceof FormData) && !(value instanceof URLSearchParams) && !(typeof ReadableStream !== "undefined" && value instanceof ReadableStream);
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Wraps a generator so warnings it reports are collected on the returned
|
|
767
|
+
* iterable rather than interrupting iteration.
|
|
768
|
+
*/
|
|
769
|
+
function forgeIterable(run) {
|
|
770
|
+
const warnings = [];
|
|
771
|
+
return {
|
|
772
|
+
warnings,
|
|
773
|
+
[Symbol.asyncIterator]: () => run((warning) => warnings.push(warning))[Symbol.asyncIterator]()
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
/** Drives a `page()` function until it reports no further cursor, collecting page warnings. */
|
|
777
|
+
function iteratePages(page, options = {}) {
|
|
778
|
+
return forgeIterable(async function* (warn) {
|
|
779
|
+
let cursor = options.cursor;
|
|
780
|
+
while (true) {
|
|
781
|
+
const result = await page({
|
|
782
|
+
...options,
|
|
783
|
+
cursor
|
|
784
|
+
});
|
|
785
|
+
result.warnings?.forEach(warn);
|
|
786
|
+
yield* result.items;
|
|
787
|
+
if (!result.cursor?.nextUrl && !result.cursor?.token || result.notModified) return;
|
|
788
|
+
cursor = result.cursor;
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
/** Turns a caught error into a serialisable warning. */
|
|
793
|
+
function toWarning(code, error, subject) {
|
|
794
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
795
|
+
return {
|
|
796
|
+
code,
|
|
797
|
+
message: err.message,
|
|
798
|
+
subject,
|
|
799
|
+
cause: {
|
|
800
|
+
name: err.name,
|
|
801
|
+
message: err.message,
|
|
802
|
+
status: err instanceof ForgeApiError ? err.status : void 0
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
/** Whether a failed side read may become a warning; rate limits, revoked tokens and errors from outside forges still stop the read. */
|
|
807
|
+
function degradesToWarning(error) {
|
|
808
|
+
return error instanceof ForgeError && !(error instanceof RateLimitedError) && !(error instanceof TokenRevokedError);
|
|
809
|
+
}
|
|
810
|
+
/** Maps with at most `limit` calls in flight, preserving order. Once a call rejects, no further calls start. */
|
|
811
|
+
async function mapConcurrent(items, limit, fn) {
|
|
812
|
+
const results = Array.from({ length: items.length });
|
|
813
|
+
let next = 0;
|
|
814
|
+
let failed = false;
|
|
815
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
816
|
+
while (!failed && next < items.length) {
|
|
817
|
+
const index = next++;
|
|
818
|
+
try {
|
|
819
|
+
results[index] = await fn(items[index]);
|
|
820
|
+
} catch (error) {
|
|
821
|
+
failed = true;
|
|
822
|
+
throw error;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
}));
|
|
826
|
+
return results;
|
|
827
|
+
}
|
|
828
|
+
/** `threads.getMany` for forges without a batch endpoint. A rate limit or a rejected credential rejects the call; other failures become per-item warnings. */
|
|
829
|
+
function getManyConcurrently(refs, get, options = {}) {
|
|
830
|
+
return mapConcurrent(refs, 4, (ref) => get(ref, options).then((thread) => ({
|
|
831
|
+
ok: true,
|
|
832
|
+
ref,
|
|
833
|
+
thread
|
|
834
|
+
}), (error) => {
|
|
835
|
+
if (options.signal?.aborted) throw options.signal.reason;
|
|
836
|
+
if (error instanceof ForgeError && !degradesToWarning(error)) throw error;
|
|
837
|
+
return {
|
|
838
|
+
ok: false,
|
|
839
|
+
ref,
|
|
840
|
+
warning: toWarning(error instanceof UnresolvedThreadError ? "thread_unresolved" : "thread_unreadable", error, ref.number)
|
|
841
|
+
};
|
|
842
|
+
}));
|
|
843
|
+
}
|
|
844
|
+
/** The comment that a notification's `latest_comment_url` names: an issue comment on a thread subject with a number, or a comment on a commit subject. */
|
|
845
|
+
function latestCommentOf(subject, url) {
|
|
846
|
+
if (subject.type === "commit") {
|
|
847
|
+
const id = /\/repos\/[^/]+\/[^/]+\/comments\/(\d+)$/.exec(url ?? "")?.[1];
|
|
848
|
+
return id ? {
|
|
849
|
+
forge: subject.commit.forge,
|
|
850
|
+
instance: subject.commit.instance,
|
|
851
|
+
commit: subject.commit,
|
|
852
|
+
id
|
|
853
|
+
} : void 0;
|
|
854
|
+
}
|
|
855
|
+
const id = /\/issues\/comments\/(\d+)$/.exec(url ?? "")?.[1];
|
|
856
|
+
if (!id || subject.type !== "thread" || !isResolvedThread(subject.thread)) return;
|
|
857
|
+
return {
|
|
858
|
+
forge: subject.thread.forge,
|
|
859
|
+
instance: subject.thread.instance,
|
|
860
|
+
thread: subject.thread,
|
|
861
|
+
id
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
/** Compares dotted numeric versions, ignoring any suffix after the numbers. */
|
|
865
|
+
function versionAtLeast(version, minimum) {
|
|
866
|
+
if (!version) return false;
|
|
867
|
+
const parts = (value) => (/^\D*(\d+(?:\.\d+)*)/.exec(value)?.[1] ?? "0").split(".").map(Number);
|
|
868
|
+
const [a, b] = [parts(version), parts(minimum)];
|
|
869
|
+
for (let index = 0; index < Math.max(a.length, b.length); index++) {
|
|
870
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
871
|
+
if (difference !== 0) return difference > 0;
|
|
872
|
+
}
|
|
873
|
+
return true;
|
|
874
|
+
}
|
|
875
|
+
/** Reads a timestamp from a forge response, or `undefined` when it is empty or not a date. */
|
|
876
|
+
function toDate(value) {
|
|
877
|
+
if (value === null || value === void 0 || value === "") return;
|
|
878
|
+
const date = new Date(value);
|
|
879
|
+
return Number.isNaN(date.getTime()) ? void 0 : date;
|
|
880
|
+
}
|
|
881
|
+
/** The host of `baseUrl`, including the port when there is one. */
|
|
882
|
+
function hostOf(baseUrl) {
|
|
883
|
+
return new URL(baseUrl).host;
|
|
884
|
+
}
|
|
885
|
+
/** The namespace ref of `ref`'s owner, for the `org` of a team's ref. */
|
|
886
|
+
function teamOrg(ref) {
|
|
887
|
+
return isNamespaceRef(ref) ? ref : namespaceRef(ref, ref.owner);
|
|
888
|
+
}
|
|
889
|
+
/** Narrows a ref to one a provider can address, or throws {@link UnresolvedThreadError}. */
|
|
890
|
+
function requireThread(ref, context) {
|
|
891
|
+
if (!isResolvedThread(ref)) throw new UnresolvedThreadError("Thread ref has no number; resolve it before calling the forge", context ?? {
|
|
892
|
+
forge: ref.forge,
|
|
893
|
+
instance: ref.instance
|
|
894
|
+
});
|
|
895
|
+
return ref;
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Narrows a ref to an issue or pull request, or throws
|
|
899
|
+
* {@link UnsupportedOperationError} naming the verb that needs one.
|
|
900
|
+
*/
|
|
901
|
+
function requireIssueOrPull(ref, context, verb) {
|
|
902
|
+
const thread = requireThread(ref, context);
|
|
903
|
+
if (thread.kind !== "issue" && thread.kind !== "pull_request") throw new UnsupportedOperationError(`${context.forge ?? "This forge"} cannot ${verb} a ${thread.kind}`, context);
|
|
904
|
+
return thread;
|
|
905
|
+
}
|
|
906
|
+
/** The token in `auth`, read again on every call when it is a function. */
|
|
907
|
+
async function resolveToken(auth) {
|
|
908
|
+
return typeof auth.token === "function" ? await auth.token() : auth.token;
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* The forge-native id `threads.setMilestone` sends: the milestone's `id`, a
|
|
912
|
+
* string of digits as it is, or the id of the milestone with that title.
|
|
913
|
+
*/
|
|
914
|
+
async function milestoneId(milestone, page, context, options = {}) {
|
|
915
|
+
const value = typeof milestone === "string" ? milestone : milestone.id;
|
|
916
|
+
if (/^\d+$/.test(value)) return Number(value);
|
|
917
|
+
for await (const candidate of iteratePages(page, {
|
|
918
|
+
state: "all",
|
|
919
|
+
signal: options.signal
|
|
920
|
+
})) if (candidate.title === value) return Number(candidate.id);
|
|
921
|
+
throw new UnsupportedOperationError(`No milestone titled ${value}`, context);
|
|
922
|
+
}
|
|
923
|
+
/** Joins the merge commit title and message for a forge that takes them as one string. */
|
|
924
|
+
function mergeCommitMessage({ title, message }) {
|
|
925
|
+
return title && message ? `${title}\n\n${message}` : title || message;
|
|
926
|
+
}
|
|
927
|
+
/** A login from either a login string or an actor. */
|
|
928
|
+
function actorLogin(actor) {
|
|
929
|
+
return typeof actor === "string" ? actor : actor.login;
|
|
930
|
+
}
|
|
931
|
+
/** Maps one fetched page into a {@link Page}. The cursor is kept only when there is a next page. */
|
|
932
|
+
function toPage(result, map, warnings) {
|
|
933
|
+
return {
|
|
934
|
+
items: (result.data ?? []).flatMap((raw) => {
|
|
935
|
+
const item = map(raw);
|
|
936
|
+
return item === void 0 ? [] : [item];
|
|
937
|
+
}),
|
|
938
|
+
...result.total !== void 0 ? { total: result.total } : {},
|
|
939
|
+
cursor: result.cursor?.nextUrl || result.cursor?.token ? result.cursor : void 0,
|
|
940
|
+
...result.etag ? { etag: result.etag } : {},
|
|
941
|
+
notModified: result.notModified || void 0,
|
|
942
|
+
...warnings?.length ? { warnings } : {},
|
|
943
|
+
...rateLimitPart(result.response)
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Adds the validator of a listing's first page to `page`: the response's `etag`, or on a `304` the one
|
|
948
|
+
* `cursor` sent. Later pages are left as they are.
|
|
949
|
+
*/
|
|
950
|
+
function withEtag(page, result, cursor) {
|
|
951
|
+
if (!isFirstPage(cursor)) return page;
|
|
952
|
+
const etag = result.response.headers.get("etag") ?? (result.notModified ? cursor?.etag : void 0);
|
|
953
|
+
return etag ? {
|
|
954
|
+
...page,
|
|
955
|
+
etag
|
|
956
|
+
} : page;
|
|
957
|
+
}
|
|
958
|
+
/** Whether `cursor` asks for the first page of a listing: it has neither `nextUrl` nor `token`, though it may have an `etag`. */
|
|
959
|
+
function isFirstPage(cursor) {
|
|
960
|
+
return !cursor?.nextUrl && !cursor?.token;
|
|
961
|
+
}
|
|
962
|
+
/** The `etag` of `cursor` when it asks for the first page, to send as `If-None-Match`. */
|
|
963
|
+
function firstPageEtag(cursor) {
|
|
964
|
+
return isFirstPage(cursor) ? cursor?.etag : void 0;
|
|
965
|
+
}
|
|
966
|
+
/** Builds a {@link Listing} for a forge that names its page-size parameter `pageParam`. */
|
|
967
|
+
function createListing(fetcher, pageParam, defaultPerPage) {
|
|
968
|
+
return async (path, options, map, { warnings, query, ...extras } = {}) => toPage(await fetcher.page(path, {
|
|
969
|
+
...extras,
|
|
970
|
+
query: {
|
|
971
|
+
...query,
|
|
972
|
+
[pageParam]: options.perPage ?? defaultPerPage
|
|
973
|
+
},
|
|
974
|
+
cursor: options.cursor,
|
|
975
|
+
signal: options.signal
|
|
976
|
+
}), map, warnings);
|
|
977
|
+
}
|
|
978
|
+
/** The `rateLimit` of a page built by hand: the budget of the response behind it, or of the page it maps. */
|
|
979
|
+
function rateLimitPart(source) {
|
|
980
|
+
const rateLimit = source && ("headers" in source ? rateLimitOf(source) : source.rateLimit);
|
|
981
|
+
return rateLimit ? { rateLimit } : {};
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Chains listings that a forge serves from separate endpoints. The cursor
|
|
985
|
+
* `token` records which phase is next, ahead of the phase's own token. With
|
|
986
|
+
* one phase, the first page is conditional as that phase's is; with more,
|
|
987
|
+
* one validator cannot cover every endpoint, so no page has an `etag`.
|
|
988
|
+
*/
|
|
989
|
+
async function phased(phases, cursor) {
|
|
990
|
+
const match = /^(\d+):(.*)$/s.exec(cursor?.token ?? "");
|
|
991
|
+
const index = match ? Number(match[1]) : 0;
|
|
992
|
+
const conditional = phases.length === 1;
|
|
993
|
+
const inner = cursor && (cursor.nextUrl || match?.[2]) ? {
|
|
994
|
+
...cursor,
|
|
995
|
+
token: match?.[2] || void 0
|
|
996
|
+
} : conditional && cursor?.etag ? { etag: cursor.etag } : void 0;
|
|
997
|
+
const { etag, ...rest } = await phases[index](inner);
|
|
998
|
+
const page = conditional && etag ? {
|
|
999
|
+
...rest,
|
|
1000
|
+
etag
|
|
1001
|
+
} : rest;
|
|
1002
|
+
if (page.cursor) return {
|
|
1003
|
+
...page,
|
|
1004
|
+
cursor: {
|
|
1005
|
+
...page.cursor,
|
|
1006
|
+
token: `${index}:${page.cursor.token ?? ""}`
|
|
1007
|
+
}
|
|
1008
|
+
};
|
|
1009
|
+
return index + 1 < phases.length ? {
|
|
1010
|
+
...page,
|
|
1011
|
+
cursor: { token: `${index + 1}:` }
|
|
1012
|
+
} : page;
|
|
1013
|
+
}
|
|
1014
|
+
/** Whether `labels` include every name in `wanted`; true when nothing is wanted. */
|
|
1015
|
+
function hasEveryLabel(labels, wanted) {
|
|
1016
|
+
return !wanted?.length || wanted.every((name) => labels?.some((label) => label.name === name));
|
|
1017
|
+
}
|
|
1018
|
+
/** The counts that are numbers, or `undefined` when none are. */
|
|
1019
|
+
function toPullStats(counts) {
|
|
1020
|
+
const known = Object.entries(counts).filter(([, count]) => typeof count === "number");
|
|
1021
|
+
return known.length ? Object.fromEntries(known) : void 0;
|
|
1022
|
+
}
|
|
1023
|
+
/** Any failure fails, else any pending is pending, else any unknown (or none at all) is unknown, else success. */
|
|
1024
|
+
function summariseChecks(states, url) {
|
|
1025
|
+
const failed = states.filter((state) => state === "failure").length;
|
|
1026
|
+
return {
|
|
1027
|
+
state: failed ? "failure" : states.includes("pending") ? "pending" : !states.length || states.includes("unknown") ? "unknown" : "success",
|
|
1028
|
+
total: states.length,
|
|
1029
|
+
failed,
|
|
1030
|
+
...url ? { url } : {}
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
const FAILED_CONCLUSIONS = /* @__PURE__ */ new Set([
|
|
1034
|
+
"failure",
|
|
1035
|
+
"timed_out",
|
|
1036
|
+
"cancelled",
|
|
1037
|
+
"action_required",
|
|
1038
|
+
"startup_failure"
|
|
1039
|
+
]);
|
|
1040
|
+
/**
|
|
1041
|
+
* State of a check run reported as a status plus a conclusion once completed.
|
|
1042
|
+
* Cancelled, timed-out, action-required and startup failures count as
|
|
1043
|
+
* failures; skipped and neutral runs as neutral.
|
|
1044
|
+
*/
|
|
1045
|
+
function checkRunState(status, conclusion) {
|
|
1046
|
+
if (status !== "completed") return "pending";
|
|
1047
|
+
if (conclusion === "success") return "success";
|
|
1048
|
+
if (conclusion && FAILED_CONCLUSIONS.has(conclusion)) return "failure";
|
|
1049
|
+
return conclusion === "neutral" || conclusion === "skipped" ? "neutral" : "unknown";
|
|
1050
|
+
}
|
|
1051
|
+
/** Maps a forge's own file-change word onto {@link FileStatus}; unknown words become `'changed'`. */
|
|
1052
|
+
function toFileStatus(raw) {
|
|
1053
|
+
switch (raw?.toLowerCase()) {
|
|
1054
|
+
case "added":
|
|
1055
|
+
case "new":
|
|
1056
|
+
case "add": return "added";
|
|
1057
|
+
case "removed":
|
|
1058
|
+
case "deleted":
|
|
1059
|
+
case "remove": return "removed";
|
|
1060
|
+
case "renamed":
|
|
1061
|
+
case "rename": return "renamed";
|
|
1062
|
+
case "copied":
|
|
1063
|
+
case "copy": return "copied";
|
|
1064
|
+
case "modified":
|
|
1065
|
+
case "edit":
|
|
1066
|
+
case "change": return "modified";
|
|
1067
|
+
default: return "changed";
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Caches the result of `load` after its first call. A rejected load is
|
|
1072
|
+
* forgotten so the next call retries; with `ttl` (milliseconds) a resolved
|
|
1073
|
+
* value is reloaded once it is older than that.
|
|
1074
|
+
*/
|
|
1075
|
+
function memo(load, ttl) {
|
|
1076
|
+
let cached;
|
|
1077
|
+
return () => {
|
|
1078
|
+
if (!cached || ttl !== void 0 && Date.now() - cached.at > ttl) {
|
|
1079
|
+
const promise = load();
|
|
1080
|
+
cached = {
|
|
1081
|
+
promise,
|
|
1082
|
+
at: Date.now()
|
|
1083
|
+
};
|
|
1084
|
+
promise.catch(() => {
|
|
1085
|
+
if (cached?.promise === promise) cached = void 0;
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
return cached.promise;
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
/** {@link memo} per key. */
|
|
1092
|
+
function memoBy(load) {
|
|
1093
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1094
|
+
return (key) => {
|
|
1095
|
+
let entry = cache.get(key);
|
|
1096
|
+
if (!entry) {
|
|
1097
|
+
entry = memo(() => load(key));
|
|
1098
|
+
cache.set(key, entry);
|
|
1099
|
+
}
|
|
1100
|
+
return entry();
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* A review standing in for an approval, vote or participant state on a forge
|
|
1105
|
+
* that has no review objects. `comments` is `false` because there is nothing
|
|
1106
|
+
* to hang inline comments on.
|
|
1107
|
+
*/
|
|
1108
|
+
function syntheticReview(thread, id, state, extras) {
|
|
1109
|
+
const { author, stateRaw, submittedAt, raw } = extras;
|
|
1110
|
+
return {
|
|
1111
|
+
ref: {
|
|
1112
|
+
forge: thread.forge,
|
|
1113
|
+
instance: thread.instance,
|
|
1114
|
+
thread,
|
|
1115
|
+
id
|
|
1116
|
+
},
|
|
1117
|
+
author,
|
|
1118
|
+
state,
|
|
1119
|
+
stateRaw,
|
|
1120
|
+
submittedAt,
|
|
1121
|
+
comments: false,
|
|
1122
|
+
raw
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
/** A label colour as six hex digits, with the `#` prefix the forge expects. `ededed` when none is given. */
|
|
1126
|
+
function hexColour(colour, prefix = "") {
|
|
1127
|
+
return `${prefix}${(colour ?? "ededed").replace(/^#/, "")}`;
|
|
1128
|
+
}
|
|
1129
|
+
// ../../node_modules/.pnpm/forges@0.4.1/node_modules/forges/dist/web-CpD15Y5a.mjs
|
|
126
1130
|
function sameRepo(a, b) {
|
|
127
1131
|
if (!b || a.forge !== b.forge || a.instance !== b.instance) return false;
|
|
128
1132
|
const [left, right] = [normaliseRepoName(a), normaliseRepoName(b)];
|
|
@@ -207,12 +1211,14 @@ const SCHEME_CHAR = /[\w+.-]/;
|
|
|
207
1211
|
const LETTER = /[a-z]/i;
|
|
208
1212
|
const SPACE = /\s/;
|
|
209
1213
|
const rules = /* @__PURE__ */ new WeakMap();
|
|
210
|
-
function repoIn(slug, origin) {
|
|
1214
|
+
function repoIn(slug, from, origin) {
|
|
211
1215
|
const at = slug.lastIndexOf("/");
|
|
212
|
-
|
|
1216
|
+
const owner = slug.slice(0, at);
|
|
1217
|
+
const name = slug.slice(at + 1);
|
|
1218
|
+
return name === from.name && (owner === from.owner || owner === from.ownerHandle) ? from : {
|
|
213
1219
|
...origin,
|
|
214
|
-
owner
|
|
215
|
-
name
|
|
1220
|
+
owner,
|
|
1221
|
+
name
|
|
216
1222
|
};
|
|
217
1223
|
}
|
|
218
1224
|
/** The spans of URLs in `text`, each from its scheme to the next whitespace. */
|
|
@@ -234,6 +1240,13 @@ function urlSpans(text) {
|
|
|
234
1240
|
function isBareSha(value) {
|
|
235
1241
|
return /[a-f]/.test(value) && /\d/.test(value);
|
|
236
1242
|
}
|
|
1243
|
+
/**
|
|
1244
|
+
* The shortest prefix of `sha`, at least `length` characters long, that reads back as a bare sha,
|
|
1245
|
+
* or `undefined` when no prefix does, as for a sha of only digits or only letters.
|
|
1246
|
+
*/
|
|
1247
|
+
function bareSha(sha, length) {
|
|
1248
|
+
for (let end = Math.min(length, sha.length); end <= Math.min(sha.length, 40); end++) if (isBareSha(sha.slice(0, end))) return sha.slice(0, end);
|
|
1249
|
+
}
|
|
237
1250
|
function rulesFor(syntax) {
|
|
238
1251
|
const cached = rules.get(syntax);
|
|
239
1252
|
if (cached) return cached;
|
|
@@ -251,9 +1264,9 @@ function rulesFor(syntax) {
|
|
|
251
1264
|
kind,
|
|
252
1265
|
...displayNumber ? { displayNumber: id } : { number: id }
|
|
253
1266
|
}));
|
|
254
|
-
if (syntax.repo && !local) rule(`(?<slug>${syntax.repo})${thread}`, ({ slug, id },
|
|
1267
|
+
if (syntax.repo && !local) rule(`(?<slug>${syntax.repo})${thread}`, ({ slug, id }, from, origin) => ({
|
|
255
1268
|
...origin,
|
|
256
|
-
repo: repoIn(slug, origin),
|
|
1269
|
+
repo: repoIn(slug, from, origin),
|
|
257
1270
|
kind,
|
|
258
1271
|
...displayNumber ? { displayNumber: id } : { number: id }
|
|
259
1272
|
}));
|
|
@@ -264,9 +1277,9 @@ function rulesFor(syntax) {
|
|
|
264
1277
|
repo: from,
|
|
265
1278
|
sha
|
|
266
1279
|
} : void 0);
|
|
267
|
-
if (syntax.repo) rule(`(?<slug>${syntax.repo})@(?<sha>${SHA})`, ({ slug, sha },
|
|
1280
|
+
if (syntax.repo) rule(`(?<slug>${syntax.repo})@(?<sha>${SHA})`, ({ slug, sha }, from, origin) => ({
|
|
268
1281
|
...origin,
|
|
269
|
-
repo: repoIn(slug, origin),
|
|
1282
|
+
repo: repoIn(slug, from, origin),
|
|
270
1283
|
sha
|
|
271
1284
|
}));
|
|
272
1285
|
}
|
|
@@ -394,7 +1407,7 @@ function githubShapedWeb(baseUrl, shape) {
|
|
|
394
1407
|
};
|
|
395
1408
|
},
|
|
396
1409
|
reference: (ref, same) => {
|
|
397
|
-
if ("sha" in ref) return same ? ref.sha
|
|
1410
|
+
if ("sha" in ref) return (same ? bareSha(ref.sha, 7) : void 0) ?? `${ref.repo.owner}/${ref.repo.name}@${ref.sha.slice(0, 7)}`;
|
|
398
1411
|
if (!ref.number) return;
|
|
399
1412
|
const prefix = ref.kind === "pull_request" && shape.pullPrefix ? shape.pullPrefix : "#";
|
|
400
1413
|
return `${same ? "" : `${ref.repo.owner}/${ref.repo.name}`}${prefix}${ref.number}`;
|
|
@@ -414,6 +1427,7 @@ function githubShapedWeb(baseUrl, shape) {
|
|
|
414
1427
|
}
|
|
415
1428
|
/** The API base URL and the instance that `options` select. */
|
|
416
1429
|
function resolveInstance(definition, options) {
|
|
1430
|
+
if (!options.baseUrl && !definition.baseUrl) throw new TypeError(`${definition.forge} has no public instance, so it needs the baseUrl of your server`);
|
|
417
1431
|
const root = (options.baseUrl ?? definition.baseUrl).replace(/\/$/, "");
|
|
418
1432
|
const baseUrl = definition.apiPath && !root.endsWith(definition.apiPath) ? `${root}${definition.apiPath}` : root;
|
|
419
1433
|
let host;
|
|
@@ -427,87 +1441,7 @@ function resolveInstance(definition, options) {
|
|
|
427
1441
|
instance: options.instance ?? definition.instance?.(host) ?? host
|
|
428
1442
|
};
|
|
429
1443
|
}
|
|
430
|
-
|
|
431
|
-
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/define-BRQZP-ft.mjs
|
|
432
|
-
/** Decodes base64, tolerating the newlines GitHub and Gitea wrap it in. */
|
|
433
|
-
function fromBase64(value) {
|
|
434
|
-
const binary = atob(value.replaceAll(/\s/g, ""));
|
|
435
|
-
const bytes = new Uint8Array(binary.length);
|
|
436
|
-
for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
|
|
437
|
-
return bytes;
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Shapes bytes as the caller asked: UTF-8 text for `as: 'text'`, bytes
|
|
441
|
-
* otherwise. Rejects with {@link ContentNotTextError} when text was asked for
|
|
442
|
-
* and the bytes are not valid UTF-8.
|
|
443
|
-
*/
|
|
444
|
-
function toFileContent(bytes, file, options, context) {
|
|
445
|
-
return options?.as === "text" ? {
|
|
446
|
-
...file,
|
|
447
|
-
content: decodeText(bytes, file.path, context),
|
|
448
|
-
encoding: "utf-8"
|
|
449
|
-
} : {
|
|
450
|
-
...file,
|
|
451
|
-
content: bytes,
|
|
452
|
-
encoding: "binary"
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
/** Decodes UTF-8, rejecting with {@link ContentNotTextError} that names `what` when the bytes are not text. */
|
|
456
|
-
function decodeText(bytes, what, context) {
|
|
457
|
-
try {
|
|
458
|
-
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
459
|
-
} catch (cause) {
|
|
460
|
-
throw new ContentNotTextError(`${what} is not valid UTF-8 text`, context, { cause });
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
/** The bytes of a file to write, with a string encoded as UTF-8. */
|
|
464
|
-
function changeBytes(content) {
|
|
465
|
-
return typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
466
|
-
}
|
|
467
|
-
/** Base64 of a file to write, with a string encoded as UTF-8. */
|
|
468
|
-
function changeBase64(content) {
|
|
469
|
-
return toBase64(changeBytes(content));
|
|
470
|
-
}
|
|
471
|
-
/** The directory that holds `path`, or `''` at the root. */
|
|
472
|
-
function directoryOf(path) {
|
|
473
|
-
const index = path.lastIndexOf("/");
|
|
474
|
-
return index < 0 ? "" : path.slice(0, index);
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Looks up the files that `changes` touch with `find`, which resolves to `undefined` for a missing file,
|
|
478
|
-
* and rejects with {@link NotFoundError} when a file to delete does not exist.
|
|
479
|
-
*/
|
|
480
|
-
async function existingFiles(changes, find, context) {
|
|
481
|
-
const found = await Promise.all(changes.map(async (change) => [change.path, await find(change.path)]));
|
|
482
|
-
const missing = changes.find((change, index) => change.content === null && found[index][1] === void 0);
|
|
483
|
-
if (missing) throw new NotFoundError(`${missing.path} does not exist, so it cannot be deleted`, 404, "", context);
|
|
484
|
-
return new Map(found.flatMap(([path, file]) => file === void 0 ? [] : [[path, file]]));
|
|
485
|
-
}
|
|
486
|
-
/**
|
|
487
|
-
* Finds files by listing their directories, once per directory.
|
|
488
|
-
* @param list Reads the entries of a directory by their full path, or `undefined` when it does not exist.
|
|
489
|
-
*/
|
|
490
|
-
function inDirectories(list) {
|
|
491
|
-
const listings = /* @__PURE__ */ new Map();
|
|
492
|
-
return async (path) => {
|
|
493
|
-
const directory = directoryOf(path);
|
|
494
|
-
if (!listings.has(directory)) listings.set(directory, list(directory));
|
|
495
|
-
return (await listings.get(directory))?.get(path);
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
/** The first line of a commit message and the rest, as forges that take them apart expect. */
|
|
499
|
-
function splitMessage(message) {
|
|
500
|
-
const [headline = "", ...rest] = message.split("\n");
|
|
501
|
-
const body = rest.join("\n").replace(/^\n+/, "");
|
|
502
|
-
return body ? {
|
|
503
|
-
headline,
|
|
504
|
-
body
|
|
505
|
-
} : { headline };
|
|
506
|
-
}
|
|
507
|
-
/** True for a full SHA-1 or SHA-256 commit id, which needs no lookup to resolve. */
|
|
508
|
-
function isSha(ref) {
|
|
509
|
-
return /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i.test(ref);
|
|
510
|
-
}
|
|
1444
|
+
// ../../node_modules/.pnpm/forges@0.4.1/node_modules/forges/dist/define-C9xZZNVR.mjs
|
|
511
1445
|
/**
|
|
512
1446
|
* Every capability with the verbs it covers and the flags that gate it, in the order the capability matrix lists them.
|
|
513
1447
|
*/
|
|
@@ -528,6 +1462,10 @@ const CAPABILITY_TABLE = [
|
|
|
528
1462
|
capability: "users.sponsorable",
|
|
529
1463
|
account: true
|
|
530
1464
|
},
|
|
1465
|
+
{
|
|
1466
|
+
capability: "users.sponsorableMany",
|
|
1467
|
+
account: true
|
|
1468
|
+
},
|
|
531
1469
|
{
|
|
532
1470
|
capability: "users.events",
|
|
533
1471
|
listing: true
|
|
@@ -1816,8 +2754,7 @@ function createProvider(definition, givenOptions, givenState) {
|
|
|
1816
2754
|
function defineForgeProvider(definition) {
|
|
1817
2755
|
return ((options = {}) => createProvider(definition, options));
|
|
1818
2756
|
}
|
|
1819
|
-
|
|
1820
|
-
//#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/webhooks-Bc6QhmI8.mjs
|
|
2757
|
+
// ../../node_modules/.pnpm/forges@0.4.1/node_modules/forges/dist/webhooks-Bc6QhmI8.mjs
|
|
1821
2758
|
/** The first of `names` the delivery carries a non-empty value for. */
|
|
1822
2759
|
function firstHeader(delivery, names) {
|
|
1823
2760
|
for (const name of typeof names === "string" ? [names] : names) {
|
|
@@ -1886,5 +2823,4 @@ function eventKindsOf(map, nativeEvents) {
|
|
|
1886
2823
|
for (const [kind, names] of Object.entries(map)) if (nativeEvents.includes("*") || names.some((name) => nativeEvents.includes(name))) kinds.add(kind);
|
|
1887
2824
|
return [...kinds];
|
|
1888
2825
|
}
|
|
1889
|
-
|
|
1890
|
-
export { headerValue as A, verb as C, rangeOf as D, lineOf as E, webUrlFor as O, toFileContent as S, githubShapedWeb as T, reviewState as _, verifyHmacSignature as a, supportOnly as b, changeBase64 as c, eventTime as d, existingFiles as f, perKind as g, isSha as h, refEvent as i, signRs256Jwt as j, bodyText as k, defineForgeProvider as l, inDirectories as m, firstHeader as n, verifySharedToken as o, fromBase64 as p, nativeEventsFor as r, WRITE_VERBS as s, eventKindsOf as t, eventAction as u, snapshotOfThread as v, OWNER_NAME as w, threadSnapshot as x, splitMessage as y };
|
|
2826
|
+
export { syntheticReview as $, firstPageEtag as A, memo as B, abortable as C, createFetcher as D, checkRunState as E, hostOf as F, rateLimitOf as G, mergeCommitMessage as H, isFirstPage as I, requireIssueOrPull as J, rateLimitPart as K, iteratePages as L, getManyConcurrently as M, hasEveryLabel as N, createListing as O, hexColour as P, summariseChecks as Q, latestCommentOf as R, webUrlFor as S, anySignal as T, milestoneId as U, memoBy as V, phased as W, resolveToken as X, requireThread as Y, sleep as Z, OWNER_NAME as _, signRs256Jwt as _t, verifyHmacSignature as a, toWarning as at, lineOf as b, defineForgeProvider as c, changeBase64 as ct, perKind as d, inDirectories as dt, teamOrg as et, reviewState as f, isSha as ft, verb as g, headerValue as gt, threadSnapshot as h, bodyText as ht, refEvent as i, toPullStats as it, forgeIterable as j, degradesToWarning as k, eventAction as l, existingFiles as lt, supportOnly as m, toFileContent as mt, firstHeader as n, toFileStatus as nt, verifySharedToken as o, versionAtLeast as ot, snapshotOfThread as p, splitMessage as pt, rateLimitReset as q, nativeEventsFor as r, toPage as rt, WRITE_VERBS as s, withEtag as st, eventKindsOf as t, toDate as tt, eventTime as u, fromBase64 as ut, bareSha as v, actorLogin as w, rangeOf as x, githubShapedWeb as y, mapConcurrent as z };
|