@vite-hub/forge 0.5.0 → 0.6.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.
Files changed (31) hide show
  1. package/dist/{association-Ds6Tgs0W-Cu9_YCGq.js → association-Ds6Tgs0W-CgBVH3ii.js} +1 -2
  2. package/dist/build/node.d.ts +1 -3
  3. package/dist/build/node.js +3 -5
  4. package/dist/build.d.ts +1 -1
  5. package/dist/build.js +1 -2
  6. package/dist/{definition-0wjaAw2i-BwSDtp9h.js → definition-BQFdu9ti-WxMjcAEl.js} +8 -8
  7. package/dist/{events-DW3SFUDA-D2rhS9D-.js → events-BL0zcgMf-9TwyYtCt.js} +3 -5
  8. package/dist/{events-uCMi3LHU-Bz79PQtq.js → events-DDdJnmD2-BSMoOqjV.js} +4 -5
  9. package/dist/{events-DjRw3KSr-C72gY7Vu.js → events-DHqSJ5KI-z2-5_1vo.js} +59 -60
  10. package/dist/{events-DmSWTdpS-oDiTlP1L.js → events-DXE-Ul2S-BzTkugIK.js} +4 -5
  11. package/dist/{feed-BlzdKdNv-DbxuSgsx.js → feed-B1OiHFg0-DevZZe0y.js} +3 -5
  12. package/dist/{feed-CIaAZINm-Dpe9DxwK.js → feed-DROLF1tb-CtRfA_7N.js} +3 -5
  13. package/dist/{feed-BwdcTgZq-CbyczJHA.js → feed-iWegqepj-ConxMpg4.js} +3 -5
  14. package/dist/{forgejo-DgNfNjcW.js → forgejo-4sbZukng.js} +3 -4
  15. package/dist/{gitea-Zpwj_XHC.js → gitea-Cj7qy2X3.js} +3 -4
  16. package/dist/{gitee-BXyl2_3W-dQOAjWqr.js → gitee-CKt4pEC0-BuLWggck.js} +2 -3
  17. package/dist/{github-CUiEF2FK.js → github-CHzhqYOr.js} +377 -293
  18. package/dist/{gitlab-zvWb9zOi.js → gitlab-CS0shW2u.js} +12 -10
  19. package/dist/{graphql-BDhuP5jN-BSpB8lWf.js → graphql-DxRA9BGO-BBbmTmWi.js} +43 -33
  20. package/dist/{identity-CmVEBLP5.js → identity-BwC2_3S9.js} +1 -2
  21. package/dist/{identity-CNTWZZuv.d.ts → identity-D2-HaDku.d.ts} +0 -2
  22. package/dist/index.d.ts +35 -38
  23. package/dist/index.js +26 -45
  24. package/dist/model-Biiu1CfI-CVLamGai.js +288 -0
  25. package/dist/{templates-BGDqQMu4-PSB43E1j.js → templates-0m5QBVIh-D1fZeoC-.js} +3 -3
  26. package/dist/{webhooks-Bc6QhmI8-CNgCERCq.js → webhooks-Bc6QhmI8-eK71_mJE.js} +1034 -98
  27. package/package.json +6 -6
  28. package/dist/events-C6C7lk1x-J8VCAjEX.js +0 -131
  29. package/dist/knot-bGebBK_B-CeDHcJUz.js +0 -350
  30. package/dist/tangled-8lg_73Wi-bSufNXiN.js +0 -43
  31. package/dist/utils-DC7MBR65-B7Vr2hFm.js +0 -1214
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { a as ForgeApiError, d as NotFoundError, f as RateLimitedError, l as MergeBlockedError, mt as repoRef, n as BranchMovedError, s as ForgeTimeoutError } from "./utils-DC7MBR65-B7Vr2hFm.js";
1
+ import { b as NotFoundError, c as repoRef, g as ForgeTimeoutError, p as ForgeApiError, u as BranchMovedError, v as MergeBlockedError, x as RateLimitedError } from "./model-Biiu1CfI-CVLamGai.js";
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
3
  import { defineErrors, isRuntimeDiagnostic } from "@vite-hub/runtime";
4
4
  import { defineDiagnostics } from "nostics";
5
5
  import { createHash } from "node:crypto";
6
6
  import { Buffer } from "node:buffer";
7
- //#region ../internal/src/runtime/cloudflare-env-lookup.ts
7
+ // ../internal/src/runtime/cloudflare-env-lookup.ts
8
8
  /** The key of the AsyncLocalStorage store on `globalThis`. Every bundled copy of this module shares the store. */
9
9
  const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
10
10
  let activeEnv;
@@ -18,16 +18,14 @@ function getActiveCloudflareEnv() {
18
18
  const host = globalThis;
19
19
  return Object.hasOwn(host, "__env__") && host.__env__ !== void 0 ? host.__env__ : activeEnv;
20
20
  }
21
- //#endregion
22
- //#region ../internal/src/runtime/cloudflare-env.ts
21
+ // ../internal/src/runtime/cloudflare-env.ts
23
22
  const runtimeGlobal = globalThis;
24
23
  runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
25
24
  function getActiveCloudflareBinding(name) {
26
25
  const env = getActiveCloudflareEnv();
27
26
  return env && Object.hasOwn(env, name) ? env[name] : void 0;
28
27
  }
29
- //#endregion
30
- //#region ../internal/src/forge.ts
28
+ // ../internal/src/forge.ts
31
29
  /**
32
30
  * Server Env of each Forge, keyed by the `env.server.<forge>.<field>` path.
33
31
  * Channels, Capabilities, Workspaces and Sources read the same names.
@@ -105,8 +103,7 @@ function forgeErrorStatus(error) {
105
103
  if (!(error instanceof Error) || !("status" in error)) return void 0;
106
104
  return typeof error.status === "number" ? error.status : void 0;
107
105
  }
108
- //#endregion
109
- //#region src/errors.ts
106
+ // src/errors.ts
110
107
  const forgeErrors = /*#__PURE__*/ defineErrors({
111
108
  docs: "https://vitehub.dev/docs/forge/diagnostics",
112
109
  codes: {
@@ -136,8 +133,7 @@ const forgeErrors = /*#__PURE__*/ defineErrors({
136
133
  }
137
134
  }
138
135
  });
139
- //#endregion
140
- //#region src/error-diagnostics.ts
136
+ // src/error-diagnostics.ts
141
137
  const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
142
138
  const forgeDiagnostics = /*#__PURE__*/ defineDiagnostics({
143
139
  docsBase: "https://vitehub.dev/docs/forge/diagnostics",
@@ -184,8 +180,7 @@ const forgeDiagnostics = /*#__PURE__*/ defineDiagnostics({
184
180
  }
185
181
  }
186
182
  });
187
- //#endregion
188
- //#region src/conditional.ts
183
+ // src/conditional.ts
189
184
  const storedHeaders = [
190
185
  "content-type",
191
186
  "link",
@@ -281,8 +276,7 @@ function conditionalFetch(fetcher, options = {}) {
281
276
  });
282
277
  };
283
278
  }
284
- //#endregion
285
- //#region src/provider.ts
279
+ // src/provider.ts
286
280
  async function forgeProvider(connection) {
287
281
  const auth = connection.token ? {
288
282
  type: "token",
@@ -300,19 +294,19 @@ async function forgeProvider(connection) {
300
294
  };
301
295
  switch (connection.forge) {
302
296
  case "github": {
303
- const { github } = await import("./github-CUiEF2FK.js");
297
+ const { github } = await import("./github-CHzhqYOr.js");
304
298
  return github(options);
305
299
  }
306
300
  case "gitlab": {
307
- const { gitlab } = await import("./gitlab-zvWb9zOi.js");
301
+ const { gitlab } = await import("./gitlab-CS0shW2u.js");
308
302
  return gitlab(options);
309
303
  }
310
304
  case "forgejo": {
311
- const { forgejo } = await import("./forgejo-DgNfNjcW.js");
305
+ const { forgejo } = await import("./forgejo-4sbZukng.js");
312
306
  return forgejo(options);
313
307
  }
314
308
  case "gitea": {
315
- const { gitea } = await import("./gitea-Zpwj_XHC.js");
309
+ const { gitea } = await import("./gitea-Cj7qy2X3.js");
316
310
  const { webhookSecret } = connection;
317
311
  return gitea({
318
312
  ...options,
@@ -351,14 +345,12 @@ async function withSignal(promise, signal) {
351
345
  });
352
346
  });
353
347
  }
354
- //#endregion
355
- //#region ../internal/src/object.ts
348
+ // ../internal/src/object.ts
356
349
  /** A non-null object that is not an array. Functions do not pass. */
357
350
  function isRecord(value) {
358
351
  return typeof value === "object" && value !== null && !Array.isArray(value);
359
352
  }
360
- //#endregion
361
- //#region src/github-app.ts
353
+ // src/github-app.ts
362
354
  const appProviders = /* @__PURE__ */ new Map();
363
355
  const installationTokens = /* @__PURE__ */ new WeakMap();
364
356
  const tokenMints = /* @__PURE__ */ new WeakMap();
@@ -421,7 +413,7 @@ function appProvider(input, installationId = "", refresh = false) {
421
413
  if (refresh) appProviders.delete(key);
422
414
  const cached = appProviders.get(key);
423
415
  if (cached) return cached;
424
- const pending = import("./github-CUiEF2FK.js").then(({ github }) => github({
416
+ const pending = import("./github-CHzhqYOr.js").then(({ github }) => github({
425
417
  ...input.baseUrl ? { baseUrl: input.baseUrl } : {},
426
418
  ...input.fetch ? { fetch: input.fetch } : {},
427
419
  userAgent: input.userAgent ?? "vitehub",
@@ -446,7 +438,7 @@ async function appIdentity(input) {
446
438
  if (!id) throw forgeResponseError("GitHub App metadata did not include an ID.");
447
439
  if (!slug) throw forgeResponseError("GitHub App response did not include a slug.");
448
440
  const login = `${slug}[bot]`;
449
- const { github } = await import("./github-CUiEF2FK.js");
441
+ const { github } = await import("./github-CHzhqYOr.js");
450
442
  const userId = await github({
451
443
  ...input.baseUrl ? { baseUrl: input.baseUrl } : {},
452
444
  ...input.fetch ? { fetch: input.fetch } : {},
@@ -601,8 +593,7 @@ async function readGitHubAppPrivateKey(inline, path) {
601
593
  const file = (await readFile(path, "utf8")).trim();
602
594
  return file ? file.replace(/\\n/g, "\n") : void 0;
603
595
  }
604
- //#endregion
605
- //#region src/github-installations.ts
596
+ // src/github-installations.ts
606
597
  const names = {
607
598
  installationId: forgeEnv.github.installationId.names[0],
608
599
  appOwner: forgeEnv.github.appOwner.names[0],
@@ -658,8 +649,7 @@ function githubInstallationFor(routing, repository) {
658
649
  const owner = repository.split("/", 1)[0].toLowerCase();
659
650
  return (Object.hasOwn(routing.installations, owner) ? routing.installations[owner] : void 0) ?? (owner === routing.owner ? routing.installationId : void 0);
660
651
  }
661
- //#endregion
662
- //#region src/use-forge.ts
652
+ // src/use-forge.ts
663
653
  function hostEnv(name) {
664
654
  return getActiveCloudflareBinding(name) ?? globalThis.process?.env?.[name];
665
655
  }
@@ -834,8 +824,7 @@ function useForge(options = {}) {
834
824
  }
835
825
  };
836
826
  }
837
- //#endregion
838
- //#region src/gaps/archive.ts
827
+ // src/gaps/archive.ts
839
828
  /**
840
829
  * The repository tree at `ref` as a gzipped tarball stream.
841
830
  * Gap: `forges` has no `contents.archive()`. Proposed upstream as `provider.contents.archive(repo, options)`
@@ -852,8 +841,7 @@ async function forgeArchive(provider, repo, options) {
852
841
  signal: options.signal
853
842
  })).body;
854
843
  }
855
- //#endregion
856
- //#region src/gaps/blob.ts
844
+ // src/gaps/blob.ts
857
845
  /**
858
846
  * The bytes of one Git blob, by its sha. The blob of a symlink holds the link target.
859
847
  * Gap: `forges` reads files by path only, and GitHub follows a symlink path to its target.
@@ -878,8 +866,7 @@ function decodeBase64Blob(value) {
878
866
  return;
879
867
  }
880
868
  }
881
- //#endregion
882
- //#region src/gaps/github.ts
869
+ // src/gaps/github.ts
883
870
  /** Narrow a provider to GitHub, or throw `FORGE_R0006` for a GitHub-only helper. */
884
871
  function requireGitHub(provider, operation) {
885
872
  if (isGitHubProvider(provider)) return provider;
@@ -891,8 +878,7 @@ function isGitHubProvider(provider) {
891
878
  function repositoryPath$1(repo) {
892
879
  return `/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}`;
893
880
  }
894
- //#endregion
895
- //#region src/gaps/branch-rules.ts
881
+ // src/gaps/branch-rules.ts
896
882
  const mergeMethods = {
897
883
  merge: "merge",
898
884
  squash: "squash",
@@ -976,8 +962,7 @@ function planWithoutRules(error) {
976
962
  const body = "body" in error && typeof error.body === "string" ? error.body : "";
977
963
  return /Upgrade to GitHub Pro or make this repository public/i.test(`${error.message}\n${body}`);
978
964
  }
979
- //#endregion
980
- //#region src/gaps/commit-files.ts
965
+ // src/gaps/commit-files.ts
981
966
  /**
982
967
  * `provider.contents.commitFiles()` with Git file modes, and the sha of the new commit.
983
968
  * Without a `mode` or a GitHub author, the call goes to `commitFiles()`. Every write without a mode is `100644`.
@@ -1089,8 +1074,7 @@ function sha(value, key, description) {
1089
1074
  if (typeof result !== "string" || !result) throw forgeResponseError(`GitHub returned a malformed ${description} response.`);
1090
1075
  return result;
1091
1076
  }
1092
- //#endregion
1093
- //#region src/gaps/git-credentials.ts
1077
+ // src/gaps/git-credentials.ts
1094
1078
  const defaultInstance = {
1095
1079
  github: "https://github.com",
1096
1080
  gitlab: "https://gitlab.com",
@@ -1146,8 +1130,7 @@ function forgeGitAuthHeader(credentials) {
1146
1130
  value: `AUTHORIZATION: basic ${basic}`
1147
1131
  };
1148
1132
  }
1149
- //#endregion
1150
- //#region src/gaps/merge.ts
1133
+ // src/gaps/merge.ts
1151
1134
  const pollDelays = [
1152
1135
  500,
1153
1136
  1e3,
@@ -1237,8 +1220,7 @@ async function sleep(ms, signal) {
1237
1220
  signal.addEventListener("abort", abort, { once: true });
1238
1221
  });
1239
1222
  }
1240
- //#endregion
1241
- //#region src/gaps/retarget.ts
1223
+ // src/gaps/retarget.ts
1242
1224
  /** Change the base branch of a GitHub pull request. */
1243
1225
  async function retargetPullRequest(provider, thread, base, options) {
1244
1226
  requireGitHub(provider, "retargetPullRequest()");
@@ -1249,5 +1231,4 @@ async function retargetPullRequest(provider, thread, base, options) {
1249
1231
  signal: options?.signal
1250
1232
  });
1251
1233
  }
1252
- //#endregion
1253
1234
  export { BranchMovedError, ForgeApiError, ForgeTimeoutError, MergeBlockedError, NotFoundError, RateLimitedError, abortError, conditionalFetch, forgeArchive, forgeBlob, forgeBranchRules, forgeCommitFiles, forgeEnv, forgeErrorStatus, forgeGitAuthHeader, forgeGitCredentials, forgeMemoryCache, forgeMerge, forgeProvider, forgeResponseError, githubAppCredentials, githubBranchRuleDetails, githubInstallationFor, githubInstallationRouting, isForgeResponseError, readForgeEnv, readGitHubAppPrivateKey, repoRef, retargetPullRequest, useForge, withSignal };
@@ -0,0 +1,288 @@
1
+ // ../../node_modules/.pnpm/forges@0.4.1/node_modules/forges/dist/errors-DBJbfvy-.mjs
2
+ /** Base class for every error that forges throws. */
3
+ var ForgeError = class extends Error {
4
+ name = "ForgeError";
5
+ /** The forge that the request went to. */
6
+ forge;
7
+ instance;
8
+ url;
9
+ method;
10
+ constructor(message, context = {}, options) {
11
+ super(message, options);
12
+ this.forge = context.forge;
13
+ this.instance = context.instance;
14
+ this.url = context.url;
15
+ this.method = context.method;
16
+ }
17
+ };
18
+ /** The forge responded with an error. */
19
+ var ForgeApiError = class extends ForgeError {
20
+ name = "ForgeApiError";
21
+ status;
22
+ /** Truncated response body, for diagnostics. */
23
+ body;
24
+ constructor(message, status, body, context, options) {
25
+ super(message, context, options);
26
+ this.status = status;
27
+ this.body = body;
28
+ }
29
+ };
30
+ /** A 404: the resource does not exist, or the credential cannot see it. Many forges respond the same way to both. */
31
+ var NotFoundError = class extends ForgeApiError {
32
+ name = "NotFoundError";
33
+ };
34
+ /**
35
+ * A 401, or a 403 with a request budget of zero (GitHub GraphQL), for a request
36
+ * sent without credentials. A rejected credential is {@link TokenRevokedError}.
37
+ */
38
+ var AuthenticationRequiredError = class extends ForgeApiError {
39
+ name = "AuthenticationRequiredError";
40
+ };
41
+ /** The forge rate limited the request and a retry didn't help. Every rate limit rejects with this class, primary or secondary. */
42
+ var RateLimitedError = class extends ForgeApiError {
43
+ name = "RateLimitedError";
44
+ /** When to send again: after the forge's `retry-after`, or when a used-up budget resets. Absent when the forge names neither. */
45
+ resetAt;
46
+ /**
47
+ * Whether the forge applied a secondary limit, such as a limit on concurrent requests or on content creation,
48
+ * rather than a used-up request budget. No remaining-request counter predicts it.
49
+ */
50
+ secondary;
51
+ constructor(message, status, body, options = {}, errorOptions) {
52
+ super(message, status, body, options, errorOptions);
53
+ this.resetAt = options.resetAt;
54
+ this.secondary = options.secondary ?? false;
55
+ }
56
+ };
57
+ /** The credential was revoked or expired. */
58
+ var TokenRevokedError = class extends ForgeApiError {
59
+ name = "TokenRevokedError";
60
+ };
61
+ /** The credential is valid but lacks the scope or permission for this call. */
62
+ var InsufficientScopeError = class extends ForgeApiError {
63
+ name = "InsufficientScopeError";
64
+ /** Scopes that would allow the request, any one of them, where the forge names them (GitHub's `X-Accepted-OAuth-Scopes`). */
65
+ acceptedScopes;
66
+ /** Scopes the credential holds, where the forge reports them (GitHub's `X-OAuth-Scopes`). */
67
+ grantedScopes;
68
+ /** Fine-grained permissions that would allow the request, verbatim, such as `issues=write` (GitHub's `X-Accepted-GitHub-Permissions`). */
69
+ acceptedPermissionsRaw;
70
+ constructor(message, status, body, context, options) {
71
+ super(message, status, body, context, options);
72
+ this.acceptedScopes = context?.acceptedScopes;
73
+ this.grantedScopes = context?.grantedScopes;
74
+ this.acceptedPermissionsRaw = context?.acceptedPermissionsRaw;
75
+ }
76
+ };
77
+ /**
78
+ * The forge refused the request for a reason other than a missing scope or a
79
+ * rate limit: an organisation policy, an SSO requirement, a protected
80
+ * resource, a release the forge has marked immutable, or a resource that
81
+ * belongs to another app. A missing scope is
82
+ * {@link InsufficientScopeError}, and a rate limit {@link RateLimitedError}.
83
+ */
84
+ var ForbiddenError = class extends ForgeApiError {
85
+ name = "ForbiddenError";
86
+ /** Why the forge refused the request. */
87
+ reason;
88
+ /** The forge's own wording, for diagnostics and for reasons that have no `ForbiddenReason`. */
89
+ reasonRaw;
90
+ /** Where the user authorises the credential for the organisation, when `reason` is `sso_required` and the forge links it (GitHub's `X-GitHub-SSO`). */
91
+ ssoUrl;
92
+ constructor(message, status, body, reason, context, options) {
93
+ super(message, status, body, context, options);
94
+ this.reason = reason;
95
+ this.reasonRaw = context?.reasonRaw;
96
+ this.ssoUrl = context?.ssoUrl;
97
+ }
98
+ };
99
+ /** Body patterns that identify a 403 reason, most specific first. */
100
+ const FORBIDDEN_PATTERNS = [
101
+ ["org_restriction", /third[- ]party application|OAuth App access restrictions|organization has enabled OAuth|not authorized by the organization|blocked by the organization/i],
102
+ ["sso_required", /SAML|single sign[- ]on|\bSSO\b|must be granted .* organization/i],
103
+ ["resource_protected", /archived|read[- ]only|protected branch|repository has been disabled|is disabled/i],
104
+ ["unknown", /contributor list is too large[^".]*/i]
105
+ ];
106
+ /**
107
+ * Classifies a 403 body. Returns `undefined` for a body that names no policy
108
+ * the caller could act on, which stays {@link InsufficientScopeError}.
109
+ */
110
+ function forbiddenReason(body) {
111
+ for (const [reason, pattern] of FORBIDDEN_PATTERNS) {
112
+ const match = body.match(pattern);
113
+ if (match) return {
114
+ reason,
115
+ reasonRaw: match[0]
116
+ };
117
+ }
118
+ }
119
+ const SECONDARY_RATE_LIMIT_RE = /secondary rate limit|abuse detection|submitted too quickly/i;
120
+ /** Whether an error message names a secondary rate limit, such as GitHub's limits on concurrency and content creation. */
121
+ function isSecondaryRateLimit(message) {
122
+ return SECONDARY_RATE_LIMIT_RE.test(message);
123
+ }
124
+ /** The pull request cannot be merged yet, typically because of failing or pending checks or branch protection. */
125
+ var MergeBlockedError = class extends ForgeApiError {
126
+ name = "MergeBlockedError";
127
+ };
128
+ /** The merge conflicts with the base branch, or the head moved since `sha` was read. */
129
+ var MergeConflictError = class extends ForgeApiError {
130
+ name = "MergeConflictError";
131
+ };
132
+ /** `contents.commitFiles()` was given an `expectedHead`, or `threads.updateBranch()` a `sha`, and the branch no longer points at it. */
133
+ var BranchMovedError = class extends ForgeApiError {
134
+ name = "BranchMovedError";
135
+ };
136
+ /** A request or a pending merge exceeded `timeout`. */
137
+ var ForgeTimeoutError = class extends ForgeError {
138
+ name = "ForgeTimeoutError";
139
+ /** The timeout that was exceeded, in milliseconds. */
140
+ timeout;
141
+ constructor(message, timeout, context, options) {
142
+ super(message, context, options);
143
+ this.timeout = timeout;
144
+ }
145
+ };
146
+ /** The request never got a response: DNS, TLS, connection refused or a proxy refusal. */
147
+ var ForgeNetworkError = class extends ForgeError {
148
+ name = "ForgeNetworkError";
149
+ };
150
+ /** A delivery's signature didn't match. */
151
+ var WebhookVerificationError = class extends ForgeError {
152
+ name = "WebhookVerificationError";
153
+ };
154
+ /** The forge doesn't support the operation. */
155
+ var UnsupportedOperationError = class extends ForgeError {
156
+ name = "UnsupportedOperationError";
157
+ };
158
+ /** A write was called on a provider constructed with `readOnly: true`. */
159
+ var ReadOnlyError = class extends UnsupportedOperationError {
160
+ name = "ReadOnlyError";
161
+ };
162
+ /** `contents.getFile` was asked for text and the file's bytes are not valid UTF-8. */
163
+ var ContentNotTextError = class extends ForgeError {
164
+ name = "ContentNotTextError";
165
+ };
166
+ /** Maps a generic merge-endpoint failure onto {@link MergeBlockedError} or {@link MergeConflictError}. */
167
+ function toMergeError(error) {
168
+ if (!(error instanceof ForgeApiError) || error.constructor !== ForgeApiError) return error;
169
+ const context = {
170
+ forge: error.forge,
171
+ instance: error.instance,
172
+ url: error.url,
173
+ method: error.method
174
+ };
175
+ if (error.status === 405) return new MergeBlockedError("Pull request is not mergeable yet", error.status, error.body, context, { cause: error });
176
+ if (error.status === 406 || error.status === 409) return new MergeConflictError("Pull request conflicts with its base or the head has moved", error.status, error.body, context, { cause: error });
177
+ return error;
178
+ }
179
+ /** The thread ref has no number, or is a kind the provider cannot address. */
180
+ var UnresolvedThreadError = class extends ForgeError {
181
+ name = "UnresolvedThreadError";
182
+ };
183
+ /** No merge method was given, and the repository allows several or reports none. */
184
+ var MergeMethodRequiredError = class extends ForgeError {
185
+ name = "MergeMethodRequiredError";
186
+ /** The merge methods that the repository allows. */
187
+ allowed;
188
+ constructor(allowed, context, options) {
189
+ super(allowed.length ? `Repository allows ${allowed.join(", ")}; pass \`method\` to choose one` : "Repository reports no merge method this provider can use; pass `method` explicitly", context, options);
190
+ this.allowed = allowed;
191
+ }
192
+ };
193
+ /** Picks the only allowed merge method, or throws {@link MergeMethodRequiredError}. */
194
+ function soleMergeMethod(allowed, context) {
195
+ const methods = Object.keys(allowed).filter((method) => allowed[method]);
196
+ if (methods.length !== 1) throw new MergeMethodRequiredError(methods, context);
197
+ return methods[0];
198
+ }
199
+ // ../../node_modules/.pnpm/forges@0.4.1/node_modules/forges/dist/model-Biiu1CfI.mjs
200
+ /** Whether `support` means the operation cannot be called. Test this rather than `support === false`: `'not_applicable'` is a non-empty string. Accepts the declaration-only levels too, so a declared level can be tested before it resolves. */
201
+ function isUnsupported(support) {
202
+ return support === false || support === "not_applicable";
203
+ }
204
+ /** Every name {@link ReactionContent} covers. */
205
+ const REACTION_CONTENTS = [
206
+ "+1",
207
+ "-1",
208
+ "laugh",
209
+ "confused",
210
+ "heart",
211
+ "hooray",
212
+ "rocket",
213
+ "eyes"
214
+ ];
215
+ /** The normalised name for a forge-native reaction name, or `'other'` where there is none. */
216
+ function reactionContent(raw) {
217
+ return REACTION_CONTENTS.includes(raw) ? raw : "other";
218
+ }
219
+ const CASE_INSENSITIVE = /* @__PURE__ */ new Set([
220
+ "github",
221
+ "gitlab",
222
+ "forgejo",
223
+ "gitea",
224
+ "bitbucket",
225
+ "gitee",
226
+ "azure-devops"
227
+ ]);
228
+ /** Whether `forge` treats owner and repository names case-insensitively. Unknown forges are assumed not to. */
229
+ function namesAreCaseInsensitive(forge) {
230
+ return CASE_INSENSITIVE.has(forge);
231
+ }
232
+ /** `repo` with `owner` and `name` lowercased where the forge ignores case, so equal repositories compare equal. */
233
+ function normaliseRepoName(repo) {
234
+ return namesAreCaseInsensitive(repo.forge) ? {
235
+ ...repo,
236
+ owner: repo.owner.toLowerCase(),
237
+ name: repo.name.toLowerCase()
238
+ } : repo;
239
+ }
240
+ /** Whether `ref` addresses an organisation, group or workspace rather than a repository, by its `kind`. */
241
+ function isNamespaceRef(ref) {
242
+ return ref.kind === "namespace";
243
+ }
244
+ /**
245
+ * The ref of a repository on `origin` from the `owner/name` that people type. The name is what follows the last
246
+ * slash, so a GitLab subgroup stays in `owner`.
247
+ * @param origin The forge and instance, such as a provider.
248
+ * @param slug The repository, such as `acme/widgets` or `acme/platform/widgets`.
249
+ * @throws {TypeError} When `slug` has no owner or no name.
250
+ * @example
251
+ * ```ts
252
+ * const repo = repoRef(provider, 'acme/widgets')
253
+ * ```
254
+ */
255
+ function repoRef(origin, slug) {
256
+ const last = slug.lastIndexOf("/");
257
+ if (last <= 0 || last === slug.length - 1) throw new TypeError(`Repository ${JSON.stringify(slug)} is not in the form owner/name`);
258
+ return {
259
+ forge: origin.forge,
260
+ instance: origin.instance,
261
+ owner: slug.slice(0, last),
262
+ name: slug.slice(last + 1)
263
+ };
264
+ }
265
+ /**
266
+ * The ref of an organisation, group, workspace or project on `origin`, as `orgs`, `repos.byOwner()` and
267
+ * namespace webhooks take it.
268
+ * @param origin The forge and instance, such as a provider.
269
+ * @param owner The namespace path, such as `acme`, `acme/platform` on GitLab or `acme/Widgets` on Azure DevOps.
270
+ * @example
271
+ * ```ts
272
+ * const teams = provider.orgs.teams(namespaceRef(provider, 'acme'))
273
+ * ```
274
+ */
275
+ function namespaceRef(origin, owner) {
276
+ return {
277
+ forge: origin.forge,
278
+ instance: origin.instance,
279
+ owner,
280
+ name: "",
281
+ kind: "namespace"
282
+ };
283
+ }
284
+ /** Whether a thread ref has a number, so that it is a `ResolvedThreadRef`. */
285
+ function isResolvedThread(thread) {
286
+ return typeof thread.number === "string" && thread.number !== "";
287
+ }
288
+ export { toMergeError as A, TokenRevokedError as C, forbiddenReason as D, WebhookVerificationError as E, isSecondaryRateLimit as O, ReadOnlyError as S, UnsupportedOperationError as T, InsufficientScopeError as _, namespaceRef as a, NotFoundError as b, repoRef as c, ContentNotTextError as d, ForbiddenError as f, ForgeTimeoutError as g, ForgeNetworkError as h, isUnsupported as i, soleMergeMethod as k, AuthenticationRequiredError as l, ForgeError as m, isNamespaceRef as n, normaliseRepoName as o, ForgeApiError as p, isResolvedThread as r, reactionContent as s, REACTION_CONTENTS as t, BranchMovedError as u, MergeBlockedError as v, UnresolvedThreadError as w, RateLimitedError as x, MergeConflictError as y };
@@ -1,5 +1,6 @@
1
- import { I as mapConcurrent, d as NotFoundError } from "./utils-DC7MBR65-B7Vr2hFm.js";
2
- //#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/templates-BGDqQMu4.mjs
1
+ import { b as NotFoundError } from "./model-Biiu1CfI-CVLamGai.js";
2
+ import { z as mapConcurrent } from "./webhooks-Bc6QhmI8-eK71_mJE.js";
3
+ // ../../node_modules/.pnpm/forges@0.4.1/node_modules/forges/dist/templates-0m5QBVIh.mjs
3
4
  /** Where GitHub looks for a pull request template and the legacy issue template, in its order of precedence. */
4
5
  const LOCATIONS = [
5
6
  ".github",
@@ -121,5 +122,4 @@ async function orEmpty(listing) {
121
122
  throw error;
122
123
  }
123
124
  }
124
- //#endregion
125
125
  export { readTemplates };