@vite-hub/workspace 0.0.3 → 0.1.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.
- package/LICENSE +201 -0
- package/README.md +236 -58
- package/dist/{ai-nmHdzjCM.d.ts → ai-BW2ZhizI.d.ts} +22 -7
- package/dist/{ai-Ce3PtWFW.js → ai-BZyLwULx.js} +147 -66
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-CaG9b7tf.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
- package/dist/blob-database.d.ts +521 -0
- package/dist/blob-database.js +601 -0
- package/dist/cloudflare.d.ts +5 -6
- package/dist/cloudflare.js +1 -1
- package/dist/config-B7dmzDX3.js +1112 -0
- package/dist/{config-3I1BnsdO.d.ts → config-DLKdaFWN.d.ts} +1 -2
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-DY5GP47p.js +96 -0
- package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
- package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
- package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
- package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
- package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
- package/dist/file-C0_aPWSS.js +26 -0
- package/dist/file-metadata-CxDy-E2H.js +58 -0
- package/dist/{files-QRV55OCx.js → files-C7Px8uaC.js} +21 -10
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
- package/dist/{github-CfA5vpJ5.js → github-CPxHtFB7.js} +36 -34
- package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
- package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
- package/dist/glob--XcLlcml.js +22 -0
- package/dist/glob--kNYDbfU.js +30 -0
- package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
- package/dist/host-CFnrTXTK.js +1086 -0
- package/dist/{hosted-C1-tTTTf.js → hosted-acMA5XyL.js} +216 -43
- package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
- package/dist/hosted-vercel-blob.d.ts +5 -6
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +6 -7
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +76 -64
- package/dist/index.js +162 -457
- package/dist/inspect-BoObD2cJ.js +167 -0
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-BwZ7c9hb.js +596 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-BREFCmtn.js +39 -0
- package/dist/memory-BbwOqDXl.js +248 -0
- package/dist/metadata-target-DZEZQGHA.js +1588 -0
- package/dist/mountx.d.ts +4 -6
- package/dist/mountx.js +10 -8
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +13 -12
- package/dist/nuxt.js +10 -8
- package/dist/operations-BcpWr41m.js +159 -0
- package/dist/operations-CGqY1XeG.js +965 -0
- package/dist/operations-DnOwKsJT.d.ts +136 -0
- package/dist/operations.d.ts +53 -0
- package/dist/operations.js +2 -0
- package/dist/{path-CNI6wKIU.js → path-CNAwN7pw.js} +34 -35
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-DqQ8b4T5.d.ts +10 -0
- package/dist/provider-kXjfli9u.js +1457 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/registry-Bp-8UUfG.js +129 -0
- package/dist/{registry-BIQVCBWI.d.ts → registry-Cg1TJVVZ.d.ts} +3 -4
- package/dist/{request-execution-u9mgUXKX.js → request-execution-Dk9rY-Yh.js} +24 -20
- package/dist/rolldown-runtime-B4iAMlE-.js +35 -0
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +9 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -2
- package/dist/runtime/empty-registry.d.ts +1 -2
- package/dist/runtime/state.d.ts +4 -4
- package/dist/runtime/state.js +10 -7
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +84 -15
- package/dist/runtime.js +561 -108
- package/dist/{search-C4REyHj9.js → search-CrTmXj5h.js} +10 -9
- package/dist/server-BNQ-Nbjj.js +290 -0
- package/dist/server.d.ts +22 -34
- package/dist/server.js +2 -355
- package/dist/shared-DalXdP0i.js +2158 -0
- package/dist/source-metadata.d.ts +7 -1
- package/dist/source-metadata.js +34 -2
- package/dist/{state-TTqa3x3Y.d.ts → state-B8zbLi5t.d.ts} +14 -13
- package/dist/store-CXgmu-uw.js +1729 -0
- package/dist/{sync-DiuDmSGk.js → sync-CN6ec-5M.js} +62 -41
- package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/token-CO62GglH.js +61 -0
- package/dist/{types-60Yn149G.d.ts → types-DeK9GIxy.d.ts} +348 -49
- package/dist/{use-CsV3oIxH.js → use-BQj7nSz6.js} +200 -45
- package/dist/{use-CUFSnFCS.d.ts → use-DhwhbAVV.d.ts} +34 -12
- package/dist/utils-Blrh4N2n.js +545 -0
- package/dist/vite-BEvgU2GY.js +20909 -0
- package/dist/vite-CcZmMQ7S.d.ts +476 -0
- package/dist/vite.d.ts +2 -50
- package/dist/vite.js +2 -2
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
- package/dist/workspace-6pxkOuxr.js +1286 -0
- package/dist/workspace-BWJQBK1u.d.ts +7 -0
- package/package.json +90 -59
- package/dist/chunk-8H4AJuhK.js +0 -14
- package/dist/collections/client.d.ts +0 -39
- package/dist/collections/client.js +0 -137
- package/dist/collections.d.ts +0 -59
- package/dist/collections.js +0 -159
- package/dist/config-CDoyls2X.js +0 -30
- package/dist/config-CZLO0m9h.js +0 -7811
- package/dist/file-CHfsZpso.js +0 -23
- package/dist/glob-D0vD_wRY.js +0 -17
- package/dist/host-CAnbugpI.js +0 -370
- package/dist/hosted-vercel-blob-CWBILDVo.js +0 -257
- package/dist/lifecycle-BYoa9hVb.js +0 -176
- package/dist/provider-C3_elpEh.js +0 -599
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/registry-CqyDTW9Y.js +0 -74
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/shared-jfogBrd5.js +0 -273
- package/dist/store-Bs1SLh55.js +0 -414
- package/dist/vite-tbfDxtlu.js +0 -2191
- package/dist/workspace-66SKyiec.d.ts +0 -6
- package/dist/workspace-C4k92Ow8.js +0 -1460
|
@@ -0,0 +1,1565 @@
|
|
|
1
|
+
import { $ as forgeIterable, D as ContentNotTextError, Et as referenceFor, F as NotFoundError, H as UnsupportedOperationError, J as createFetcher, U as WebhookVerificationError, Ut as webUrlFor, X as createRequest, at as isFirstPage, kt as resolveInstance, lt as isUnsupported, mt as memo, ut as iteratePages, vt as parseReferences, yt as parseWebUrl, z as ReadOnlyError } from "./shared-DalXdP0i.js";
|
|
2
|
+
//#region ../forge/dist/webhooks-DgHwxxYz-D1V2LOr1.js
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
function toBytes(value) {
|
|
5
|
+
return typeof value === "string" ? encoder.encode(value) : value;
|
|
6
|
+
}
|
|
7
|
+
function toHex(buffer) {
|
|
8
|
+
return [...new Uint8Array(buffer)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
9
|
+
}
|
|
10
|
+
/** Base64 for arbitrary bytes, a byte at a time so a large buffer cannot overflow the call stack. */
|
|
11
|
+
function toBase64(bytes) {
|
|
12
|
+
let binary = "";
|
|
13
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
14
|
+
return btoa(binary);
|
|
15
|
+
}
|
|
16
|
+
function toBase64Url(input) {
|
|
17
|
+
return (typeof input === "string" ? btoa(input) : toBase64(input)).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
|
|
18
|
+
}
|
|
19
|
+
async function hmacSha256(secret, body) {
|
|
20
|
+
const key = await crypto.subtle.importKey("raw", toBytes(secret), {
|
|
21
|
+
name: "HMAC",
|
|
22
|
+
hash: "SHA-256"
|
|
23
|
+
}, false, ["sign"]);
|
|
24
|
+
return crypto.subtle.sign("HMAC", key, toBytes(body));
|
|
25
|
+
}
|
|
26
|
+
/** Lowercase hex HMAC-SHA256 of `body` under `secret`. */
|
|
27
|
+
async function hmacSha256Hex(secret, body) {
|
|
28
|
+
return toHex(await hmacSha256(secret, body));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Constant-time comparison of two strings. The time taken depends only on the
|
|
32
|
+
* length of `a`, so pass the untrusted value as `a`.
|
|
33
|
+
*/
|
|
34
|
+
function timingSafeEqual(a, b) {
|
|
35
|
+
let mismatch = a.length ^ b.length;
|
|
36
|
+
for (let index = 0; index < a.length; index++) mismatch |= a.charCodeAt(index) ^ b.charCodeAt(index % b.length);
|
|
37
|
+
return mismatch === 0;
|
|
38
|
+
}
|
|
39
|
+
function decodePem(pem) {
|
|
40
|
+
const pkcs1 = pem.includes("BEGIN RSA PRIVATE KEY");
|
|
41
|
+
const body = pem.replace(/-----(?:BEGIN|END)[^-]+-----/g, "").replace(/\s+/g, "");
|
|
42
|
+
const binary = atob(body);
|
|
43
|
+
const der = new Uint8Array(binary.length);
|
|
44
|
+
for (let index = 0; index < binary.length; index++) der[index] = binary.charCodeAt(index);
|
|
45
|
+
return {
|
|
46
|
+
der,
|
|
47
|
+
pkcs1
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function derLength(length) {
|
|
51
|
+
if (length < 128) return [length];
|
|
52
|
+
const bytes = [];
|
|
53
|
+
let remaining = length;
|
|
54
|
+
while (remaining > 0) {
|
|
55
|
+
bytes.unshift(remaining & 255);
|
|
56
|
+
remaining >>= 8;
|
|
57
|
+
}
|
|
58
|
+
return [128 | bytes.length, ...bytes];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Wraps a PKCS#1 RSA key in a PKCS#8 `PrivateKeyInfo`. GitHub App keys are
|
|
62
|
+
* distributed as PKCS#1, which Web Crypto cannot import directly.
|
|
63
|
+
*/
|
|
64
|
+
function pkcs1ToPkcs8(der) {
|
|
65
|
+
const algorithm = [
|
|
66
|
+
48,
|
|
67
|
+
13,
|
|
68
|
+
6,
|
|
69
|
+
9,
|
|
70
|
+
42,
|
|
71
|
+
134,
|
|
72
|
+
72,
|
|
73
|
+
134,
|
|
74
|
+
247,
|
|
75
|
+
13,
|
|
76
|
+
1,
|
|
77
|
+
1,
|
|
78
|
+
1,
|
|
79
|
+
5,
|
|
80
|
+
0
|
|
81
|
+
];
|
|
82
|
+
const octetString = [
|
|
83
|
+
4,
|
|
84
|
+
...derLength(der.length),
|
|
85
|
+
...der
|
|
86
|
+
];
|
|
87
|
+
const contents = [
|
|
88
|
+
2,
|
|
89
|
+
1,
|
|
90
|
+
0,
|
|
91
|
+
...algorithm,
|
|
92
|
+
...octetString
|
|
93
|
+
];
|
|
94
|
+
return new Uint8Array([
|
|
95
|
+
48,
|
|
96
|
+
...derLength(contents.length),
|
|
97
|
+
...contents
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
/** Signs an RS256 JWT with a PEM-encoded RSA private key. */
|
|
101
|
+
async function signRs256Jwt(privateKeyPem, claims) {
|
|
102
|
+
const { der, pkcs1 } = decodePem(privateKeyPem);
|
|
103
|
+
const key = await crypto.subtle.importKey("pkcs8", pkcs1 ? pkcs1ToPkcs8(der) : der, {
|
|
104
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
105
|
+
hash: "SHA-256"
|
|
106
|
+
}, false, ["sign"]);
|
|
107
|
+
const payload = `${toBase64Url(JSON.stringify({
|
|
108
|
+
alg: "RS256",
|
|
109
|
+
typ: "JWT"
|
|
110
|
+
}))}.${toBase64Url(JSON.stringify(claims))}`;
|
|
111
|
+
const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", key, encoder.encode(payload));
|
|
112
|
+
return `${payload}.${toBase64Url(new Uint8Array(signature))}`;
|
|
113
|
+
}
|
|
114
|
+
/** The value of a header, whatever the casing of `name`, from a `Headers` object or a plain record. */
|
|
115
|
+
function headerValue(headers, name) {
|
|
116
|
+
if (headers instanceof Headers) return headers.get(name) ?? void 0;
|
|
117
|
+
const lower = name.toLowerCase();
|
|
118
|
+
for (const [key, value] of Object.entries(headers)) if (key.toLowerCase() === lower) return value;
|
|
119
|
+
}
|
|
120
|
+
/** A request body as text. */
|
|
121
|
+
function bodyText(body) {
|
|
122
|
+
return typeof body === "string" ? body : new TextDecoder().decode(body);
|
|
123
|
+
}
|
|
124
|
+
/** Decodes base64, tolerating the newlines GitHub and Gitea wrap it in. */
|
|
125
|
+
function fromBase64(value) {
|
|
126
|
+
const binary = atob(value.replaceAll(/\s/g, ""));
|
|
127
|
+
const bytes = new Uint8Array(binary.length);
|
|
128
|
+
for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
|
|
129
|
+
return bytes;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Shapes bytes as the caller asked: UTF-8 text for `as: 'text'`, bytes
|
|
133
|
+
* otherwise. Rejects with {@link ContentNotTextError} when text was asked for
|
|
134
|
+
* and the bytes are not valid UTF-8.
|
|
135
|
+
*/
|
|
136
|
+
function toFileContent(bytes, file, options, context) {
|
|
137
|
+
return options?.as === "text" ? {
|
|
138
|
+
...file,
|
|
139
|
+
content: decodeText(bytes, file.path, context),
|
|
140
|
+
encoding: "utf-8"
|
|
141
|
+
} : {
|
|
142
|
+
...file,
|
|
143
|
+
content: bytes,
|
|
144
|
+
encoding: "binary"
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** Decodes UTF-8, rejecting with {@link ContentNotTextError} that names `what` when the bytes are not text. */
|
|
148
|
+
function decodeText(bytes, what, context) {
|
|
149
|
+
try {
|
|
150
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
151
|
+
} catch (cause) {
|
|
152
|
+
throw new ContentNotTextError(`${what} is not valid UTF-8 text`, context, { cause });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/** The bytes of a file to write, with a string encoded as UTF-8. */
|
|
156
|
+
function changeBytes(content) {
|
|
157
|
+
return typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
158
|
+
}
|
|
159
|
+
/** Base64 of a file to write, with a string encoded as UTF-8. */
|
|
160
|
+
function changeBase64(content) {
|
|
161
|
+
return toBase64(changeBytes(content));
|
|
162
|
+
}
|
|
163
|
+
/** The directory that holds `path`, or `''` at the root. */
|
|
164
|
+
function directoryOf(path) {
|
|
165
|
+
const index = path.lastIndexOf("/");
|
|
166
|
+
return index < 0 ? "" : path.slice(0, index);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Looks up the files that `changes` touch with `find`, which resolves to `undefined` for a missing file,
|
|
170
|
+
* and rejects with {@link NotFoundError} when a file to delete does not exist.
|
|
171
|
+
*/
|
|
172
|
+
async function existingFiles(changes, find, context) {
|
|
173
|
+
const found = await Promise.all(changes.map(async (change) => [change.path, await find(change.path)]));
|
|
174
|
+
const missing = changes.find((change, index) => change.content === null && found[index][1] === void 0);
|
|
175
|
+
if (missing) throw new NotFoundError(`${missing.path} does not exist, so it cannot be deleted`, 404, "", context);
|
|
176
|
+
return new Map(found.flatMap(([path, file]) => file === void 0 ? [] : [[path, file]]));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Finds files by listing their directories, once per directory.
|
|
180
|
+
* @param list Reads the entries of a directory by their full path, or `undefined` when it does not exist.
|
|
181
|
+
*/
|
|
182
|
+
function inDirectories(list) {
|
|
183
|
+
const listings = /* @__PURE__ */ new Map();
|
|
184
|
+
return async (path) => {
|
|
185
|
+
const directory = directoryOf(path);
|
|
186
|
+
if (!listings.has(directory)) listings.set(directory, list(directory));
|
|
187
|
+
return (await listings.get(directory))?.get(path);
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/** The first line of a commit message and the rest, as forges that take them apart expect. */
|
|
191
|
+
function splitMessage(message) {
|
|
192
|
+
const [headline = "", ...rest] = message.split("\n");
|
|
193
|
+
const body = rest.join("\n").replace(/^\n+/, "");
|
|
194
|
+
return body ? {
|
|
195
|
+
headline,
|
|
196
|
+
body
|
|
197
|
+
} : { headline };
|
|
198
|
+
}
|
|
199
|
+
/** True for a full SHA-1 or SHA-256 commit id, which needs no lookup to resolve. */
|
|
200
|
+
function isSha(ref) {
|
|
201
|
+
return /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i.test(ref);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Every capability with the verbs it covers and the flags that gate it, in the order the capability matrix lists them.
|
|
205
|
+
*/
|
|
206
|
+
const CAPABILITY_TABLE = [
|
|
207
|
+
{
|
|
208
|
+
capability: "experimental",
|
|
209
|
+
derived: "experimental",
|
|
210
|
+
verbs: []
|
|
211
|
+
},
|
|
212
|
+
{ capability: "sources.stream" },
|
|
213
|
+
{ capability: "repos.get" },
|
|
214
|
+
{ capability: "users.get" },
|
|
215
|
+
{
|
|
216
|
+
capability: "users.me",
|
|
217
|
+
account: true
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
capability: "users.sponsorable",
|
|
221
|
+
account: true
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
capability: "users.events",
|
|
225
|
+
listing: true
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
capability: "users.block",
|
|
229
|
+
write: true,
|
|
230
|
+
account: true,
|
|
231
|
+
spec: "users.blocking",
|
|
232
|
+
verbs: ["users.block", "users.unblock"]
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
capability: "repos.list",
|
|
236
|
+
account: true,
|
|
237
|
+
listing: true
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
capability: "repos.byOwner",
|
|
241
|
+
listing: true
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
capability: "repos.labels",
|
|
245
|
+
listing: true
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
capability: "repos.createLabel",
|
|
249
|
+
write: true
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
capability: "repos.milestones",
|
|
253
|
+
listing: true
|
|
254
|
+
},
|
|
255
|
+
{ capability: "repos.issueTypes" },
|
|
256
|
+
{
|
|
257
|
+
capability: "repos.collaborators",
|
|
258
|
+
listing: true
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
capability: "repos.contributors",
|
|
262
|
+
listing: true
|
|
263
|
+
},
|
|
264
|
+
{ capability: "repos.contributorStats" },
|
|
265
|
+
{ capability: "repos.templates" },
|
|
266
|
+
{ capability: "repos.permissionFor" },
|
|
267
|
+
{ capability: "repos.branchRules" },
|
|
268
|
+
{
|
|
269
|
+
capability: "repos.addCollaborator",
|
|
270
|
+
write: true
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
capability: "repos.assignableUsers",
|
|
274
|
+
listing: true
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
capability: "repos.reviewerCandidates",
|
|
278
|
+
listing: true
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
capability: "repos.events",
|
|
282
|
+
listing: true
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
capability: "orgs.teams",
|
|
286
|
+
listing: true
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
capability: "orgs.teamMembers",
|
|
290
|
+
listing: true,
|
|
291
|
+
account: true
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
capability: "orgs.block",
|
|
295
|
+
write: true,
|
|
296
|
+
spec: "orgs.blocking",
|
|
297
|
+
verbs: ["orgs.block", "orgs.unblock"]
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
capability: "threads.get",
|
|
301
|
+
perKind: true
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
capability: "threads.list",
|
|
305
|
+
listing: true,
|
|
306
|
+
perKind: true
|
|
307
|
+
},
|
|
308
|
+
{ capability: "threads.getMany" },
|
|
309
|
+
{
|
|
310
|
+
capability: "threads.closingIssues",
|
|
311
|
+
listing: true
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
capability: "threads.closingPullRequests",
|
|
315
|
+
listing: true
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
capability: "threads.events",
|
|
319
|
+
listing: true,
|
|
320
|
+
spec: "threads.eventsPage",
|
|
321
|
+
derived: "threadEvents"
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
capability: "threads.comments",
|
|
325
|
+
listing: true,
|
|
326
|
+
perKind: true
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
capability: "threads.getComment",
|
|
330
|
+
spec: "threads.getComment",
|
|
331
|
+
derived: "getComment",
|
|
332
|
+
perKind: true
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
capability: "threads.createComment",
|
|
336
|
+
write: true,
|
|
337
|
+
perKind: true
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
capability: "threads.updateComment",
|
|
341
|
+
write: true,
|
|
342
|
+
perKind: true
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
capability: "threads.deleteComment",
|
|
346
|
+
write: true,
|
|
347
|
+
perKind: true
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
capability: "threads.hideComment",
|
|
351
|
+
write: true,
|
|
352
|
+
spec: "threads.hiding",
|
|
353
|
+
perKind: true,
|
|
354
|
+
verbs: ["threads.hideComment", "threads.unhideComment"]
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
capability: "threads.reactions",
|
|
358
|
+
listing: true,
|
|
359
|
+
perKind: true
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
capability: "threads.react",
|
|
363
|
+
write: true,
|
|
364
|
+
spec: "threads.reactions",
|
|
365
|
+
perKind: true,
|
|
366
|
+
verbs: ["threads.react", "threads.unreact"]
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
capability: "threads.create",
|
|
370
|
+
write: true,
|
|
371
|
+
perKind: true
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
capability: "threads.update",
|
|
375
|
+
write: true,
|
|
376
|
+
perKind: true
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
capability: "threads.close",
|
|
380
|
+
write: true,
|
|
381
|
+
perKind: true
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
capability: "threads.reopen",
|
|
385
|
+
write: true,
|
|
386
|
+
perKind: true
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
capability: "threads.lock",
|
|
390
|
+
write: true,
|
|
391
|
+
spec: "threads.locking",
|
|
392
|
+
perKind: true,
|
|
393
|
+
verbs: ["threads.lock", "threads.unlock"]
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
capability: "threads.setLabels",
|
|
397
|
+
write: true,
|
|
398
|
+
perKind: true
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
capability: "threads.addLabels",
|
|
402
|
+
write: true,
|
|
403
|
+
perKind: true
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
capability: "threads.removeLabels",
|
|
407
|
+
write: true,
|
|
408
|
+
perKind: true
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
capability: "threads.setMilestone",
|
|
412
|
+
write: true,
|
|
413
|
+
perKind: true
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
capability: "threads.setIssueType",
|
|
417
|
+
write: true,
|
|
418
|
+
perKind: true
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
capability: "threads.setAssignees",
|
|
422
|
+
write: true,
|
|
423
|
+
perKind: true
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
capability: "threads.requestReview",
|
|
427
|
+
write: true,
|
|
428
|
+
perKind: true
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
capability: "threads.merge",
|
|
432
|
+
write: true
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
capability: "threads.updateBranch",
|
|
436
|
+
write: true
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
capability: "threads.transfer",
|
|
440
|
+
write: true
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
capability: "threads.markDuplicate",
|
|
444
|
+
write: true
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
capability: "threads.subscription",
|
|
448
|
+
account: true,
|
|
449
|
+
spec: "threads.subscriptions",
|
|
450
|
+
perKind: true
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
capability: "threads.subscribe",
|
|
454
|
+
write: true,
|
|
455
|
+
derived: "subscriptionSet",
|
|
456
|
+
verbs: ["threads.subscribe", "threads.unsubscribe"]
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
capability: "threads.checks",
|
|
460
|
+
perKind: true
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
capability: "threads.files",
|
|
464
|
+
listing: true
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
capability: "threads.commits",
|
|
468
|
+
listing: true
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
capability: "threads.reviews",
|
|
472
|
+
listing: true
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
capability: "threads.getReview",
|
|
476
|
+
spec: "threads.getReview",
|
|
477
|
+
derived: "getReview"
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
capability: "threads.createReview",
|
|
481
|
+
write: true
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
capability: "threads.submitReview",
|
|
485
|
+
write: true
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
capability: "threads.approve",
|
|
489
|
+
write: true,
|
|
490
|
+
spec: "threads.approve",
|
|
491
|
+
derived: "approve"
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
capability: "threads.replyToReviewComment",
|
|
495
|
+
write: true
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
capability: "threads.resolveReviewThread",
|
|
499
|
+
write: true,
|
|
500
|
+
spec: "threads.reviewThreads",
|
|
501
|
+
verbs: ["threads.resolveReviewThread", "threads.unresolveReviewThread"]
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
capability: "notifications.list",
|
|
505
|
+
account: true,
|
|
506
|
+
listing: true
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
capability: "notifications.markRead",
|
|
510
|
+
account: true,
|
|
511
|
+
write: true
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
capability: "notifications.markDone",
|
|
515
|
+
account: true,
|
|
516
|
+
write: true
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
capability: "notifications.unsubscribe",
|
|
520
|
+
account: true,
|
|
521
|
+
write: true
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
capability: "notifications.markAllRead",
|
|
525
|
+
account: true,
|
|
526
|
+
write: true
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
capability: "notifications.markAllDone",
|
|
530
|
+
account: true,
|
|
531
|
+
write: true
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
capability: "notifications.unreadCount",
|
|
535
|
+
account: true
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
capability: "installations.list",
|
|
539
|
+
account: true,
|
|
540
|
+
spec: "installations",
|
|
541
|
+
verbs: [
|
|
542
|
+
"installations.list",
|
|
543
|
+
"installations.get",
|
|
544
|
+
"installations.token",
|
|
545
|
+
"installations.repos",
|
|
546
|
+
"installations.provider",
|
|
547
|
+
"installations.providers"
|
|
548
|
+
],
|
|
549
|
+
listings: ["installations.list", "installations.repos"]
|
|
550
|
+
},
|
|
551
|
+
{ capability: "checks.list" },
|
|
552
|
+
{ capability: "checks.get" },
|
|
553
|
+
{
|
|
554
|
+
capability: "checks.report",
|
|
555
|
+
write: true
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
capability: "checks.rerun",
|
|
559
|
+
write: true
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
capability: "ci.runs",
|
|
563
|
+
listing: true
|
|
564
|
+
},
|
|
565
|
+
{ capability: "ci.getRun" },
|
|
566
|
+
{
|
|
567
|
+
capability: "ci.jobs",
|
|
568
|
+
listing: true
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
capability: "ci.getJob",
|
|
572
|
+
spec: "ci.getJob",
|
|
573
|
+
derived: "ciJob"
|
|
574
|
+
},
|
|
575
|
+
{ capability: "ci.log" },
|
|
576
|
+
{
|
|
577
|
+
capability: "ci.rerunFailed",
|
|
578
|
+
write: true
|
|
579
|
+
},
|
|
580
|
+
{ capability: "contents.getFile" },
|
|
581
|
+
{
|
|
582
|
+
capability: "contents.tree",
|
|
583
|
+
listing: true
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
capability: "contents.branches",
|
|
587
|
+
listing: true
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
capability: "contents.tags",
|
|
591
|
+
listing: true
|
|
592
|
+
},
|
|
593
|
+
{ capability: "contents.resolveRef" },
|
|
594
|
+
{ capability: "contents.compare" },
|
|
595
|
+
{
|
|
596
|
+
capability: "contents.commitFiles",
|
|
597
|
+
write: true
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
capability: "commits.list",
|
|
601
|
+
listing: true
|
|
602
|
+
},
|
|
603
|
+
{ capability: "commits.get" },
|
|
604
|
+
{
|
|
605
|
+
capability: "commits.comments",
|
|
606
|
+
listing: true
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
capability: "commits.getComment",
|
|
610
|
+
spec: "commits.getComment",
|
|
611
|
+
derived: "commitComment"
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
capability: "commits.createComment",
|
|
615
|
+
write: true
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
capability: "commits.updateComment",
|
|
619
|
+
write: true
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
capability: "commits.deleteComment",
|
|
623
|
+
write: true
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
capability: "commits.hideComment",
|
|
627
|
+
write: true,
|
|
628
|
+
spec: "commits.commentHiding",
|
|
629
|
+
verbs: ["commits.hideComment", "commits.unhideComment"]
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
capability: "releases.list",
|
|
633
|
+
listing: true
|
|
634
|
+
},
|
|
635
|
+
{ capability: "releases.get" },
|
|
636
|
+
{ capability: "releases.latest" },
|
|
637
|
+
{ capability: "releases.getByTag" },
|
|
638
|
+
{ capability: "releases.downloadAsset" },
|
|
639
|
+
{
|
|
640
|
+
capability: "releases.create",
|
|
641
|
+
write: true
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
capability: "releases.update",
|
|
645
|
+
write: true
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
capability: "webhooks.ingest",
|
|
649
|
+
derived: "webhook",
|
|
650
|
+
verbs: ["webhooks.verify", "webhooks.ingest"]
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
capability: "webhooks.list",
|
|
654
|
+
account: true,
|
|
655
|
+
listing: true
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
capability: "webhooks.create",
|
|
659
|
+
write: true
|
|
660
|
+
},
|
|
661
|
+
{
|
|
662
|
+
capability: "webhooks.update",
|
|
663
|
+
write: true
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
capability: "webhooks.delete",
|
|
667
|
+
write: true
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
capability: "webhooks.rotateSecret",
|
|
671
|
+
write: true
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
capability: "webhooks.deliveries",
|
|
675
|
+
account: true,
|
|
676
|
+
listing: true
|
|
677
|
+
},
|
|
678
|
+
{
|
|
679
|
+
capability: "webhooks.redeliver",
|
|
680
|
+
write: true
|
|
681
|
+
},
|
|
682
|
+
{
|
|
683
|
+
capability: "search.threads",
|
|
684
|
+
listing: true
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
capability: "search.repos",
|
|
688
|
+
listing: true
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
capability: "search.commits",
|
|
692
|
+
listing: true
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
capability: "search.code",
|
|
696
|
+
listing: true
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
capability: "securityAlerts.list",
|
|
700
|
+
listing: true,
|
|
701
|
+
derived: "alertKinds"
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
capability: "eventKinds",
|
|
705
|
+
derived: "eventKinds",
|
|
706
|
+
verbs: []
|
|
707
|
+
},
|
|
708
|
+
{
|
|
709
|
+
capability: "authKinds",
|
|
710
|
+
derived: "authKinds",
|
|
711
|
+
verbs: []
|
|
712
|
+
},
|
|
713
|
+
{
|
|
714
|
+
capability: "limits",
|
|
715
|
+
derived: "limits",
|
|
716
|
+
verbs: []
|
|
717
|
+
}
|
|
718
|
+
].map(({ listing, ...row }) => {
|
|
719
|
+
const path = listing ? `${row.capability}Page` : row.capability;
|
|
720
|
+
const spec = row.spec ?? (row.derived ? void 0 : path);
|
|
721
|
+
return {
|
|
722
|
+
...row,
|
|
723
|
+
...spec ? { spec } : {},
|
|
724
|
+
verbs: row.verbs ?? [row.capability],
|
|
725
|
+
...listing ? { listings: [row.capability] } : {}
|
|
726
|
+
};
|
|
727
|
+
});
|
|
728
|
+
const ALERT_KINDS = [
|
|
729
|
+
"dependency",
|
|
730
|
+
"code_scanning",
|
|
731
|
+
"secret",
|
|
732
|
+
"advisory"
|
|
733
|
+
];
|
|
734
|
+
const KINDS = [
|
|
735
|
+
"issue",
|
|
736
|
+
"pull_request",
|
|
737
|
+
"discussion"
|
|
738
|
+
];
|
|
739
|
+
const NOT_APPLICABLE_KINDS = {
|
|
740
|
+
issue: "not_applicable",
|
|
741
|
+
pull_request: "not_applicable",
|
|
742
|
+
discussion: "not_applicable"
|
|
743
|
+
};
|
|
744
|
+
const NOT_APPLICABLE_ALERTS = {
|
|
745
|
+
dependency: "not_applicable",
|
|
746
|
+
code_scanning: "not_applicable",
|
|
747
|
+
secret: "not_applicable",
|
|
748
|
+
advisory: "not_applicable"
|
|
749
|
+
};
|
|
750
|
+
/**
|
|
751
|
+
* The level `support` declares. Unless `declared` is set, `'experimental'` and
|
|
752
|
+
* `'unverified'` resolve to `true`, as `capabilities` reports them.
|
|
753
|
+
*/
|
|
754
|
+
function resolve(support, env, declared = false) {
|
|
755
|
+
const level = typeof support === "function" ? support(env) : support ?? false;
|
|
756
|
+
return declared || level !== "experimental" && level !== "unverified" ? level : true;
|
|
757
|
+
}
|
|
758
|
+
function resolveKinds(kinds, env, declared = false) {
|
|
759
|
+
return Object.fromEntries(KINDS.map((kind) => [kind, resolve(kinds?.[kind], env, declared)]));
|
|
760
|
+
}
|
|
761
|
+
/** A capability composed of `parts` is `'not_applicable'` when any part is, else `false`, else `'unverified'`. */
|
|
762
|
+
function composed(parts, level) {
|
|
763
|
+
return parts.includes("not_applicable") ? "not_applicable" : parts.includes(false) ? false : parts.includes("unverified") ? "unverified" : level;
|
|
764
|
+
}
|
|
765
|
+
/** A thread's events are read for each kind the provider reads threads of, at the weaker of the two levels. */
|
|
766
|
+
function threadEventKinds(spec, env, declared = false) {
|
|
767
|
+
const events = resolve(spec.threads.eventsPage.support, env, declared);
|
|
768
|
+
const threads = resolveKinds(spec.threads.get.kinds, env, declared);
|
|
769
|
+
return Object.fromEntries(KINDS.map((kind) => [kind, composed([events, threads[kind]], events === true ? threads[kind] : events)]));
|
|
770
|
+
}
|
|
771
|
+
/** A single-item read the spec does not declare is emulated by walking its listing. */
|
|
772
|
+
function readOrEmulated(read, listing, emulated, env, declared) {
|
|
773
|
+
if (read !== false) return read;
|
|
774
|
+
const level = emulated === void 0 ? "emulated" : resolve(emulated, env, declared);
|
|
775
|
+
return composed([listing], level === true ? "emulated" : level);
|
|
776
|
+
}
|
|
777
|
+
/** `threads.getComment`, per kind: declared, or emulated from `threads.comments`. */
|
|
778
|
+
function getCommentKinds(spec, env, declared = false) {
|
|
779
|
+
const read = resolveKinds(spec.threads.getComment?.kinds, env, declared);
|
|
780
|
+
const listing = resolveKinds(spec.threads.commentsPage.kinds, env, declared);
|
|
781
|
+
return Object.fromEntries(KINDS.map((kind) => [kind, readOrEmulated(read[kind], listing[kind], spec.emulated?.getComment?.[kind], env, declared)]));
|
|
782
|
+
}
|
|
783
|
+
/** `threads.getReview`: declared, or emulated from `threads.reviews`. */
|
|
784
|
+
function getReviewSupport(spec, env, declared = false) {
|
|
785
|
+
return readOrEmulated(resolve(spec.threads.getReview?.support, env, declared), resolve(spec.threads.reviewsPage?.support, env, declared), spec.emulated?.getReview, env, declared);
|
|
786
|
+
}
|
|
787
|
+
/** `ci.getJob`: declared, or emulated from `ci.jobs` for a job ref that names its run. */
|
|
788
|
+
function ciJobSupport(spec, env, declared = false) {
|
|
789
|
+
return readOrEmulated(resolve(spec.ci?.getJob?.support, env, declared), resolve(spec.ci?.jobsPage?.support, env, declared), spec.emulated?.getJob, env, declared);
|
|
790
|
+
}
|
|
791
|
+
/** `commits.getComment`: declared, or emulated from `commits.commentsPage`. */
|
|
792
|
+
function commitCommentSupport(spec, env, declared = false) {
|
|
793
|
+
return readOrEmulated(resolve(spec.commits?.getComment?.support, env, declared), resolve(spec.commits?.commentsPage?.support, env, declared), spec.emulated?.getCommitComment, env, declared);
|
|
794
|
+
}
|
|
795
|
+
function read(source, path) {
|
|
796
|
+
return path.split(".").reduce((value, key) => value?.[key], source);
|
|
797
|
+
}
|
|
798
|
+
function write(target, path, value) {
|
|
799
|
+
const keys = path.split(".");
|
|
800
|
+
const leaf = keys.pop();
|
|
801
|
+
const parent = keys.reduce((node, key) => node[key] ??= {}, target);
|
|
802
|
+
parent[leaf] = value;
|
|
803
|
+
}
|
|
804
|
+
function unsupported(declared) {
|
|
805
|
+
return declared && {
|
|
806
|
+
...declared,
|
|
807
|
+
support: declared.support === "not_applicable" ? "not_applicable" : false
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
/** Keeps the kinds that are `'not_applicable'`, which no credential or mode changes. */
|
|
811
|
+
function unsupportedKinds(declared) {
|
|
812
|
+
return declared && {
|
|
813
|
+
...declared,
|
|
814
|
+
kinds: Object.fromEntries(Object.entries(declared.kinds ?? {}).filter(([, value]) => value === "not_applicable"))
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
/** What `entry` contributes to the capability object; `undefined` leaves the field to core. */
|
|
818
|
+
function valueFor(entry, spec, env, flags, declared) {
|
|
819
|
+
switch (entry.derived) {
|
|
820
|
+
case "experimental": return;
|
|
821
|
+
case "webhook": return flags.webhook || (spec.notApplicable?.includes("webhooks.ingest") ? "not_applicable" : false);
|
|
822
|
+
case "threadEvents": return threadEventKinds(spec, env, declared);
|
|
823
|
+
case "getComment": return getCommentKinds(spec, env, declared);
|
|
824
|
+
case "getReview": return getReviewSupport(spec, env, declared);
|
|
825
|
+
case "ciJob": return ciJobSupport(spec, env, declared);
|
|
826
|
+
case "commitComment": return commitCommentSupport(spec, env, declared);
|
|
827
|
+
case "subscriptionSet": return resolveKinds((flags.readOnly ? unsupportedKinds(spec.threads.subscriptions) : spec.threads.subscriptions)?.kinds, env, declared);
|
|
828
|
+
case "approve": return resolve((spec.threads.approve ?? spec.threads.createReview)?.support, env, declared);
|
|
829
|
+
case "alertKinds": return Object.fromEntries(ALERT_KINDS.map((kind) => [kind, resolve(spec.securityAlerts?.kinds[kind], env, declared)]));
|
|
830
|
+
case "eventKinds": return spec.traits.eventKinds;
|
|
831
|
+
case "authKinds": return spec.traits.authKinds;
|
|
832
|
+
case "limits": return spec.traits.limits;
|
|
833
|
+
}
|
|
834
|
+
const verb = read(spec, entry.spec);
|
|
835
|
+
return entry.perKind ? resolveKinds(verb?.kinds, env, declared) : resolve(verb?.support, env, declared);
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* The capability object a spec declares, derived from {@link CAPABILITY_TABLE} with every support resolved against `env`.
|
|
839
|
+
* With `declared`, it keeps the `'experimental'` and `'unverified'` levels that `capabilities` reports as `true`.
|
|
840
|
+
*/
|
|
841
|
+
function capabilitiesOf(spec, env, flags, declared = false) {
|
|
842
|
+
const resolved = applyNotApplicable(spec);
|
|
843
|
+
const capabilities = {
|
|
844
|
+
version: env.version,
|
|
845
|
+
...flags.experimental ? { experimental: true } : {}
|
|
846
|
+
};
|
|
847
|
+
for (const entry of CAPABILITY_TABLE) {
|
|
848
|
+
const value = valueFor(entry, resolved, env, flags, declared);
|
|
849
|
+
if (value === void 0) continue;
|
|
850
|
+
for (const key of entry.verbs?.length ? entry.verbs : [entry.capability]) write(capabilities, key, value);
|
|
851
|
+
}
|
|
852
|
+
return capabilities;
|
|
853
|
+
}
|
|
854
|
+
const DECLARED = Symbol.for("forges.declaredCapabilities");
|
|
855
|
+
/** Records how to read the declared levels of `provider`, for {@link declaredCapabilities}. */
|
|
856
|
+
function trackDeclared(provider, read) {
|
|
857
|
+
return Object.defineProperty(provider, DECLARED, { value: read });
|
|
858
|
+
}
|
|
859
|
+
/** Verbs `readOnly` blocks, by their {@link ForgeVerb} name. */
|
|
860
|
+
const WRITE_VERBS = new Set(CAPABILITY_TABLE.flatMap((entry) => entry.write ? entry.verbs ?? [] : []));
|
|
861
|
+
function update(target, path, change, create = false) {
|
|
862
|
+
const [key, ...rest] = path.split(".");
|
|
863
|
+
const node = target;
|
|
864
|
+
if (!key) return change(target);
|
|
865
|
+
if (!create && node?.[key] === void 0) return target;
|
|
866
|
+
return {
|
|
867
|
+
...node,
|
|
868
|
+
[key]: update(node?.[key], rest.join("."), change, create)
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
const notApplicable = (declared) => ({
|
|
872
|
+
...declared,
|
|
873
|
+
support: "not_applicable"
|
|
874
|
+
});
|
|
875
|
+
const notApplicableKinds = (declared) => ({
|
|
876
|
+
...declared,
|
|
877
|
+
kinds: NOT_APPLICABLE_KINDS
|
|
878
|
+
});
|
|
879
|
+
/** Fills `spec` with `'not_applicable'` entries before anything resolves it, so derived capabilities inherit the level from their parts. */
|
|
880
|
+
function applyNotApplicable(spec) {
|
|
881
|
+
if (!spec.notApplicable?.length) return spec;
|
|
882
|
+
const absent = new Set(spec.notApplicable);
|
|
883
|
+
let updated = spec;
|
|
884
|
+
for (const entry of CAPABILITY_TABLE) if (entry.spec && absent.has(entry.capability)) updated = update(updated, entry.spec, entry.perKind ? notApplicableKinds : notApplicable, true);
|
|
885
|
+
if (absent.has("securityAlerts.list")) updated = update(updated, "securityAlerts", (declared) => ({
|
|
886
|
+
...declared,
|
|
887
|
+
kinds: NOT_APPLICABLE_ALERTS
|
|
888
|
+
}), true);
|
|
889
|
+
return updated;
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Marks writes unsupported, with `anonymous` everything that needs an account,
|
|
893
|
+
* and with `webhooksOnly` every declared verb, leaving only webhook ingestion.
|
|
894
|
+
*/
|
|
895
|
+
function restrict(spec, anonymous, webhooksOnly = false) {
|
|
896
|
+
let restricted = applyNotApplicable(spec);
|
|
897
|
+
for (const entry of CAPABILITY_TABLE) if (entry.spec && (entry.write || anonymous && (entry.account || webhooksOnly))) restricted = update(restricted, entry.spec, entry.perKind ? unsupportedKinds : unsupported);
|
|
898
|
+
const result = restricted;
|
|
899
|
+
return anonymous && webhooksOnly ? update(result, "securityAlerts", unsupportedKinds) : result;
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Marks every declared verb unsupported except the capabilities in `keep` and
|
|
903
|
+
* anything under them, for a credential that reaches only part of the API.
|
|
904
|
+
* @param spec The spec that `setup()` declares.
|
|
905
|
+
* @param keep Capability paths, such as `installations`, that stay as declared.
|
|
906
|
+
* @example
|
|
907
|
+
* ```ts
|
|
908
|
+
* return appItself ? supportOnly(spec, ['installations']) : spec
|
|
909
|
+
* ```
|
|
910
|
+
*/
|
|
911
|
+
function supportOnly(spec, keep) {
|
|
912
|
+
const kept = (capability) => keep.some((path) => capability === path || capability.startsWith(`${path}.`));
|
|
913
|
+
let restricted = applyNotApplicable(spec);
|
|
914
|
+
for (const entry of CAPABILITY_TABLE) if (entry.spec && !kept(entry.capability)) restricted = update(restricted, entry.spec, entry.perKind ? unsupportedKinds : unsupported);
|
|
915
|
+
return kept("securityAlerts") ? restricted : update(restricted, "securityAlerts", unsupportedKinds);
|
|
916
|
+
}
|
|
917
|
+
const ACTIONS = {
|
|
918
|
+
open: "opened",
|
|
919
|
+
opened: "opened",
|
|
920
|
+
close: "closed",
|
|
921
|
+
closed: "closed",
|
|
922
|
+
reopen: "reopened",
|
|
923
|
+
reopened: "reopened",
|
|
924
|
+
merge: "merged",
|
|
925
|
+
merged: "merged",
|
|
926
|
+
edit: "edited",
|
|
927
|
+
edited: "edited",
|
|
928
|
+
update: "edited",
|
|
929
|
+
updated: "edited",
|
|
930
|
+
create: "created",
|
|
931
|
+
created: "created",
|
|
932
|
+
delete: "deleted",
|
|
933
|
+
deleted: "deleted",
|
|
934
|
+
submitted: "submitted",
|
|
935
|
+
labeled: "labelled",
|
|
936
|
+
labelled: "labelled",
|
|
937
|
+
label_added: "labelled",
|
|
938
|
+
unlabeled: "unlabelled",
|
|
939
|
+
unlabelled: "unlabelled",
|
|
940
|
+
label_removed: "unlabelled",
|
|
941
|
+
label_updated: "edited",
|
|
942
|
+
label_cleared: "unlabelled",
|
|
943
|
+
assigned: "assigned",
|
|
944
|
+
unassigned: "unassigned",
|
|
945
|
+
review_requested: "review_requested",
|
|
946
|
+
synchronize: "synchronised",
|
|
947
|
+
synchronized: "synchronised",
|
|
948
|
+
synchronised: "synchronised",
|
|
949
|
+
ready_for_review: "ready_for_review",
|
|
950
|
+
converted_to_draft: "converted_to_draft",
|
|
951
|
+
convert_to_draft: "converted_to_draft",
|
|
952
|
+
publish: "published",
|
|
953
|
+
published: "published",
|
|
954
|
+
renamed: "renamed",
|
|
955
|
+
transferred: "transferred",
|
|
956
|
+
archived: "archived",
|
|
957
|
+
unarchived: "unarchived",
|
|
958
|
+
added: "added",
|
|
959
|
+
removed: "removed",
|
|
960
|
+
typed: "typed",
|
|
961
|
+
untyped: "untyped"
|
|
962
|
+
};
|
|
963
|
+
/** What a comment or review event means when the forge names no verb. */
|
|
964
|
+
const KIND_DEFAULTS = {
|
|
965
|
+
comment: "created",
|
|
966
|
+
review_comment: "created",
|
|
967
|
+
review: "submitted"
|
|
968
|
+
};
|
|
969
|
+
/** Normalises a forge-native verb (`closed`, `close`, `synchronize`, ...) into an {@link EventAction}. */
|
|
970
|
+
function eventAction(raw) {
|
|
971
|
+
return raw ? ACTIONS[raw.toLowerCase()] : void 0;
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Fills `action` from `actionRaw`, or from the last `.`/`:` segment of
|
|
975
|
+
* `kindRaw`, falling back to the kind's default verb, then `other`.
|
|
976
|
+
*/
|
|
977
|
+
function completeEvent(event) {
|
|
978
|
+
if (event.action) return event;
|
|
979
|
+
const raw = event.actionRaw ?? event.kindRaw?.split(/[.:]/).pop();
|
|
980
|
+
return {
|
|
981
|
+
...event,
|
|
982
|
+
action: eventAction(raw) ?? KIND_DEFAULTS[event.kind] ?? "other"
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
const REVIEW_STATES = {
|
|
986
|
+
approved: "approved",
|
|
987
|
+
approve: "approved",
|
|
988
|
+
changes_requested: "changes_requested",
|
|
989
|
+
request_changes: "changes_requested",
|
|
990
|
+
commented: "commented",
|
|
991
|
+
comment: "commented",
|
|
992
|
+
pending: "pending",
|
|
993
|
+
dismissed: "dismissed"
|
|
994
|
+
};
|
|
995
|
+
/** Sets `occurredAt` to `time`, or to `fallback` with `undated` when the forge reported no time. */
|
|
996
|
+
function eventTime(time, fallback = /* @__PURE__ */ new Date()) {
|
|
997
|
+
return time ? { occurredAt: time } : {
|
|
998
|
+
occurredAt: fallback,
|
|
999
|
+
undated: true
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
/** Normalises a forge-native review verdict (`APPROVED`, `changes_requested`, ...) into a {@link ReviewState}. */
|
|
1003
|
+
function reviewState(raw) {
|
|
1004
|
+
return raw && REVIEW_STATES[raw.toLowerCase()] || "unknown";
|
|
1005
|
+
}
|
|
1006
|
+
/** A {@link ThreadSnapshot} of the fields that are known, or `undefined` when none is. An `unknown` state is dropped. */
|
|
1007
|
+
function threadSnapshot(fields) {
|
|
1008
|
+
const known = Object.entries(fields).filter(([key, value]) => value !== void 0 && !(key === "state" && value === "unknown"));
|
|
1009
|
+
return known.length ? Object.fromEntries(known) : void 0;
|
|
1010
|
+
}
|
|
1011
|
+
/** The {@link ThreadSnapshot} of a thread normalised from the issue or pull request an event embeds. */
|
|
1012
|
+
function snapshotOfThread({ title, body, state, stateRaw, stateReason, isDraft, author, labels, issueType, url, branches, stats, mergedBy }) {
|
|
1013
|
+
return threadSnapshot({
|
|
1014
|
+
title,
|
|
1015
|
+
body,
|
|
1016
|
+
state,
|
|
1017
|
+
stateRaw,
|
|
1018
|
+
stateReason,
|
|
1019
|
+
isDraft,
|
|
1020
|
+
author,
|
|
1021
|
+
labels,
|
|
1022
|
+
issueType,
|
|
1023
|
+
url,
|
|
1024
|
+
branches,
|
|
1025
|
+
stats,
|
|
1026
|
+
mergedBy
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
const VERBS = new Set(CAPABILITY_TABLE.flatMap((entry) => entry.verbs ?? []));
|
|
1030
|
+
/**
|
|
1031
|
+
* Whether `verb` is supported according to `capabilities`, for `kind` where
|
|
1032
|
+
* support differs by thread kind (or by alert kind for `securityAlerts`).
|
|
1033
|
+
* Without `kind`, a per-kind verb counts as supported when any kind is.
|
|
1034
|
+
* @param capabilities The capabilities of a provider, such as `provider.capabilities`.
|
|
1035
|
+
* @param verb The operation, named by its path on the provider, such as `threads.createComment`.
|
|
1036
|
+
* @param kind The thread or alert kind, for an operation whose support differs by kind.
|
|
1037
|
+
* @example
|
|
1038
|
+
* ```ts
|
|
1039
|
+
* if (can(provider.capabilities, 'threads.merge')) {
|
|
1040
|
+
* await provider.threads.merge(ref)
|
|
1041
|
+
* }
|
|
1042
|
+
* ```
|
|
1043
|
+
*/
|
|
1044
|
+
function can(capabilities, verb, kind) {
|
|
1045
|
+
return !isUnsupported(support(capabilities, verb, kind));
|
|
1046
|
+
}
|
|
1047
|
+
/** Levels from strongest to weakest, as the capability matrix ranks them. */
|
|
1048
|
+
const LEVELS = [true, "emulated"];
|
|
1049
|
+
/**
|
|
1050
|
+
* How well `verb` is supported according to `capabilities`: `true`,
|
|
1051
|
+
* `'emulated'`, `'not_applicable'` or `false`, for `kind` where support differs
|
|
1052
|
+
* by thread kind (or by alert kind for `securityAlerts`). Without `kind`, a
|
|
1053
|
+
* per-kind verb reports its strongest available level, or `'not_applicable'`
|
|
1054
|
+
* when no kind is available and any kind is, else `false`.
|
|
1055
|
+
* @param capabilities The capabilities of a provider, such as `provider.capabilities`.
|
|
1056
|
+
* @param verb The operation, named by its path on the provider, such as `threads.createComment`.
|
|
1057
|
+
* @param kind The thread or alert kind, for an operation whose support differs by kind.
|
|
1058
|
+
*/
|
|
1059
|
+
function support(capabilities, verb, kind) {
|
|
1060
|
+
const declared = capabilityOf(capabilities, verb);
|
|
1061
|
+
if (typeof declared !== "object") return declared;
|
|
1062
|
+
if (kind) return declared[kind] ?? false;
|
|
1063
|
+
const levels = Object.values(declared);
|
|
1064
|
+
return LEVELS.find((level) => levels.includes(level)) ?? (levels.includes("not_applicable") ? "not_applicable" : false);
|
|
1065
|
+
}
|
|
1066
|
+
/** The capability entry behind `verb`: one support level, or one per kind. */
|
|
1067
|
+
function capabilityOf(capabilities, verb) {
|
|
1068
|
+
if (!VERBS.has(verb)) throw new TypeError(`Unknown verb ${JSON.stringify(verb)}; verbs are named by their path on the provider, such as 'threads.createComment'`);
|
|
1069
|
+
return verb.split(".").reduce((value, key) => value[key], capabilities);
|
|
1070
|
+
}
|
|
1071
|
+
const THREAD_FILTERS = [
|
|
1072
|
+
"involves",
|
|
1073
|
+
"mentions",
|
|
1074
|
+
"milestone"
|
|
1075
|
+
];
|
|
1076
|
+
/**
|
|
1077
|
+
* Declares a verb whose support does not depend on the thread kind.
|
|
1078
|
+
* @param support How well the verb is supported.
|
|
1079
|
+
* @param run The function that implements the verb.
|
|
1080
|
+
*/
|
|
1081
|
+
function verb(support, run) {
|
|
1082
|
+
return {
|
|
1083
|
+
support,
|
|
1084
|
+
run
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Declares a verb whose support depends on the thread kind.
|
|
1089
|
+
* @param kinds How well each thread kind is supported. Kinds that are left out are unsupported.
|
|
1090
|
+
* @param run The function that implements the verb.
|
|
1091
|
+
* @example
|
|
1092
|
+
* ```ts
|
|
1093
|
+
* const threads = {
|
|
1094
|
+
* get: perKind({ issue: true, pull_request: true }, getThread),
|
|
1095
|
+
* }
|
|
1096
|
+
* ```
|
|
1097
|
+
*/
|
|
1098
|
+
function perKind(kinds, run) {
|
|
1099
|
+
return {
|
|
1100
|
+
kinds,
|
|
1101
|
+
run
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
/** Iterables whose page takes only options, with no target before them. */
|
|
1105
|
+
const UNTARGETED = /* @__PURE__ */ new Set([
|
|
1106
|
+
"repos.list",
|
|
1107
|
+
"notifications.list",
|
|
1108
|
+
"installations.list",
|
|
1109
|
+
"search.threads",
|
|
1110
|
+
"search.repos",
|
|
1111
|
+
"search.commits",
|
|
1112
|
+
"search.code"
|
|
1113
|
+
]);
|
|
1114
|
+
/** The thread kind a per-kind verb is called for, read from its arguments. */
|
|
1115
|
+
function kindOf(name, args) {
|
|
1116
|
+
const first = args[0];
|
|
1117
|
+
if (name === "create" || name === "list") return args[1]?.kind;
|
|
1118
|
+
return first?.thread?.kind ?? first?.kind;
|
|
1119
|
+
}
|
|
1120
|
+
async function* completeItems(items) {
|
|
1121
|
+
for await (const item of items) yield {
|
|
1122
|
+
...item,
|
|
1123
|
+
event: completeEvent(item.event)
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
function readPath(source, path) {
|
|
1127
|
+
return path.split(".").reduce((value, key) => value?.[key], source);
|
|
1128
|
+
}
|
|
1129
|
+
/** Most reads spent looking for a first item when a provider's filtering empties a page. */
|
|
1130
|
+
const MAX_EMPTY_READS = 10;
|
|
1131
|
+
/**
|
|
1132
|
+
* Providers that cannot filter on the forge's side drop items from each page
|
|
1133
|
+
* they read, so a page can come back empty with a `cursor`. Reads on until the
|
|
1134
|
+
* page has an item, the listing ends or `MAX_EMPTY_READS` reads are spent.
|
|
1135
|
+
*/
|
|
1136
|
+
async function nonEmptyPage(read, start) {
|
|
1137
|
+
let page = await read(start);
|
|
1138
|
+
const warnings = page.warnings;
|
|
1139
|
+
for (let reads = 1; !page.items.length && page.cursor && !page.notModified && reads < MAX_EMPTY_READS; reads++) page = await read(page.cursor);
|
|
1140
|
+
if (!warnings?.length || page.warnings === warnings) return page;
|
|
1141
|
+
const later = (page.warnings ?? []).filter((warning) => !warnings.some((seen) => seen.code === warning.code && seen.message === warning.message));
|
|
1142
|
+
return {
|
|
1143
|
+
...page,
|
|
1144
|
+
warnings: [...warnings, ...later]
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
/** Resets this close together belong to one window, as a reset in seconds from now drifts between responses. */
|
|
1148
|
+
const RESET_TOLERANCE_MS = 1e3;
|
|
1149
|
+
/** Whether `next` was counted before `kept` though it arrived after it: from an older window, or with more requests left in the same one. */
|
|
1150
|
+
function countedBefore(next, kept) {
|
|
1151
|
+
if (!next.resetAt || !kept.resetAt) return false;
|
|
1152
|
+
const gap = next.resetAt.getTime() - kept.resetAt.getTime();
|
|
1153
|
+
if (Math.abs(gap) > RESET_TOLERANCE_MS) return gap < 0;
|
|
1154
|
+
return next.remaining !== void 0 && kept.remaining !== void 0 && next.remaining > kept.remaining;
|
|
1155
|
+
}
|
|
1156
|
+
function createProvider(definition, givenOptions, givenState) {
|
|
1157
|
+
const givenAuth = givenOptions.auth;
|
|
1158
|
+
const anonymous = Boolean(definition.anonymous) && (!givenAuth || givenAuth.type === "anonymous");
|
|
1159
|
+
const options = anonymous && !givenAuth ? {
|
|
1160
|
+
...givenOptions,
|
|
1161
|
+
auth: { type: "anonymous" }
|
|
1162
|
+
} : givenOptions;
|
|
1163
|
+
const { baseUrl, instance } = resolveInstance(definition, options);
|
|
1164
|
+
const origin = {
|
|
1165
|
+
forge: definition.forge,
|
|
1166
|
+
instance
|
|
1167
|
+
};
|
|
1168
|
+
const browser = "document" in globalThis || "WorkerGlobalScope" in globalThis;
|
|
1169
|
+
const userAgent = options.userAgent ?? (browser ? void 0 : "forges");
|
|
1170
|
+
const headers = {
|
|
1171
|
+
...definition.headers,
|
|
1172
|
+
...userAgent ? { "user-agent": userAgent } : {}
|
|
1173
|
+
};
|
|
1174
|
+
const prepared = {
|
|
1175
|
+
options,
|
|
1176
|
+
forge: definition.forge,
|
|
1177
|
+
instance,
|
|
1178
|
+
baseUrl,
|
|
1179
|
+
headers,
|
|
1180
|
+
origin,
|
|
1181
|
+
state: givenState
|
|
1182
|
+
};
|
|
1183
|
+
const state = definition.prepare ? definition.prepare(prepared) : givenState;
|
|
1184
|
+
const base = {
|
|
1185
|
+
...prepared,
|
|
1186
|
+
state
|
|
1187
|
+
};
|
|
1188
|
+
const budgets = /* @__PURE__ */ new Map();
|
|
1189
|
+
const tracked = (event) => {
|
|
1190
|
+
const kept = budgets.get(event.rateLimit.resource);
|
|
1191
|
+
if (!kept || !countedBefore(event.rateLimit, kept)) budgets.set(event.rateLimit.resource, event.rateLimit);
|
|
1192
|
+
options.onRateLimit?.(event);
|
|
1193
|
+
};
|
|
1194
|
+
const authHeaders = anonymous ? void 0 : definition.authHeaders?.(base);
|
|
1195
|
+
const makeFetcher = (overrides) => createFetcher({
|
|
1196
|
+
fetch: options.fetch,
|
|
1197
|
+
timeout: options.timeout,
|
|
1198
|
+
onRetry: options.onRetry,
|
|
1199
|
+
onRateLimit: "authHeaders" in overrides || authHeaders ? options.onRateLimit : tracked,
|
|
1200
|
+
headers,
|
|
1201
|
+
query: definition.query,
|
|
1202
|
+
context: origin,
|
|
1203
|
+
...overrides
|
|
1204
|
+
});
|
|
1205
|
+
const fetcher = makeFetcher({
|
|
1206
|
+
baseUrl,
|
|
1207
|
+
authHeaders,
|
|
1208
|
+
onRateLimit: tracked
|
|
1209
|
+
});
|
|
1210
|
+
const ctx = {
|
|
1211
|
+
...base,
|
|
1212
|
+
fetcher,
|
|
1213
|
+
createFetcher: makeFetcher,
|
|
1214
|
+
derive: (derivedOptions, derivedState) => createProvider(definition, derivedOptions, derivedState ?? state)
|
|
1215
|
+
};
|
|
1216
|
+
const declaredSpec = applyNotApplicable(definition.setup(ctx));
|
|
1217
|
+
const handlers = definition.webhooks?.(ctx);
|
|
1218
|
+
const spec = anonymous || options.readOnly ? restrict(declaredSpec, anonymous, definition.anonymous === "webhooks") : declaredSpec;
|
|
1219
|
+
const authKind = anonymous ? "anonymous" : givenAuth?.type ?? spec.traits.authKinds[0] ?? "anonymous";
|
|
1220
|
+
const env = { version: options.instanceVersion };
|
|
1221
|
+
const probeVersion = spec.probeVersion && memo(spec.probeVersion);
|
|
1222
|
+
const flags = {
|
|
1223
|
+
experimental: Boolean(definition.experimental),
|
|
1224
|
+
readOnly: Boolean(options.readOnly),
|
|
1225
|
+
webhook: Boolean(handlers)
|
|
1226
|
+
};
|
|
1227
|
+
let capabilities = capabilitiesOf(spec, env, flags);
|
|
1228
|
+
const unsupported = (verb, support, kind) => options.readOnly && WRITE_VERBS.has(verb) ? new ReadOnlyError(`${verb} is a write and this ${definition.forge} provider is read-only`, origin) : new UnsupportedOperationError(`${definition.forge} ${support === "not_applicable" ? "has no" : "does not support"} ${verb}${kind ? ` for a ${kind.replace("_", " ")}` : ""}`, origin);
|
|
1229
|
+
/** An iterable that rejects on first read, for listings the forge does not have. */
|
|
1230
|
+
const emptyIterable = (verb, support) => forgeIterable(async function* () {
|
|
1231
|
+
throw unsupported(verb, support);
|
|
1232
|
+
});
|
|
1233
|
+
/** Support is resolved at call time, so a version gate is honoured once the version is known. */
|
|
1234
|
+
function gate(verb, support, run) {
|
|
1235
|
+
return (...args) => {
|
|
1236
|
+
const level = resolve(support, env);
|
|
1237
|
+
return run && !isUnsupported(level) ? run(...args) : Promise.reject(unsupported(verb, level));
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
/** A per-kind verb: rejects for kinds it does not support, or entirely when undeclared. */
|
|
1241
|
+
function kindGate(verb, kinds, run) {
|
|
1242
|
+
const name = verb.slice(verb.indexOf(".") + 1);
|
|
1243
|
+
return (...args) => {
|
|
1244
|
+
const kind = kindOf(name, args);
|
|
1245
|
+
const knownKind = kind && KINDS.includes(kind) ? kind : void 0;
|
|
1246
|
+
if (!run || options.readOnly && WRITE_VERBS.has(verb)) return Promise.reject(unsupported(verb, kinds && resolve(kinds[knownKind ?? "issue"], env)));
|
|
1247
|
+
if (knownKind) {
|
|
1248
|
+
const level = resolve(kinds?.[knownKind], env);
|
|
1249
|
+
if (isUnsupported(level)) return Promise.reject(unsupported(verb, level, knownKind));
|
|
1250
|
+
}
|
|
1251
|
+
return run(...args);
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
const api = {};
|
|
1255
|
+
const set = (verb, value) => {
|
|
1256
|
+
const [group, name] = verb.split(".");
|
|
1257
|
+
(api[group] ??= {})[name] = value;
|
|
1258
|
+
};
|
|
1259
|
+
const call = (verb) => readPath(api, verb);
|
|
1260
|
+
const listing = (read, listOptions = {}) => Object.assign(iteratePages(read, listOptions), { page: () => read(listOptions) });
|
|
1261
|
+
const subscriptions = spec.threads.subscriptions;
|
|
1262
|
+
const createReview = spec.threads.createReview;
|
|
1263
|
+
const approve = spec.threads.approve ?? (createReview && {
|
|
1264
|
+
support: createReview.support,
|
|
1265
|
+
...createReview.run ? { run: (ref, body, options) => createReview.run(ref, {
|
|
1266
|
+
event: "approve",
|
|
1267
|
+
body
|
|
1268
|
+
}, options) } : {}
|
|
1269
|
+
});
|
|
1270
|
+
const declaredStream = spec.sources?.stream;
|
|
1271
|
+
const alerts = spec.securityAlerts;
|
|
1272
|
+
const declaredInstallations = spec.installations;
|
|
1273
|
+
const installationsSupported = () => Boolean(declaredInstallations?.run && !isUnsupported(resolve(declaredInstallations.support, env)));
|
|
1274
|
+
const listThreads = kindGate("threads.list", spec.threads.listPage.kinds, spec.threads.listPage.run);
|
|
1275
|
+
const listOwnerRepos = gate("repos.byOwner", spec.repos.byOwnerPage?.support, spec.repos.byOwnerPage?.run);
|
|
1276
|
+
const listComments = kindGate("threads.comments", spec.threads.commentsPage.kinds, spec.threads.commentsPage.run);
|
|
1277
|
+
const listEvents = kindGate("threads.events", Object.fromEntries(KINDS.map((kind) => [kind, (kindEnv) => threadEventKinds(spec, kindEnv)[kind]])), spec.threads.eventsPage.run);
|
|
1278
|
+
const native = spec.search?.queryRaw;
|
|
1279
|
+
const search = (name) => {
|
|
1280
|
+
const run = gate(`search.${name.slice(0, -4)}`, spec.search?.[name]?.support, spec.search?.[name]?.run);
|
|
1281
|
+
return async ({ queryRaw, ...query } = {}) => {
|
|
1282
|
+
const page = await run(native ? {
|
|
1283
|
+
queryRaw,
|
|
1284
|
+
...query
|
|
1285
|
+
} : query);
|
|
1286
|
+
return !queryRaw || native || !isFirstPage(query.cursor) ? page : {
|
|
1287
|
+
...page,
|
|
1288
|
+
warnings: [{
|
|
1289
|
+
code: "filter_unsupported",
|
|
1290
|
+
message: "This search has no query syntax; queryRaw was ignored"
|
|
1291
|
+
}, ...page.warnings ?? []]
|
|
1292
|
+
};
|
|
1293
|
+
};
|
|
1294
|
+
};
|
|
1295
|
+
const feed = (verb) => {
|
|
1296
|
+
const declared = readPath(spec, verb);
|
|
1297
|
+
const run = gate(verb.slice(0, -4), declared?.support, declared?.run);
|
|
1298
|
+
return async (target, pageOptions) => {
|
|
1299
|
+
const page = await run(target, pageOptions);
|
|
1300
|
+
return {
|
|
1301
|
+
...page,
|
|
1302
|
+
items: page.items.map(completeEvent)
|
|
1303
|
+
};
|
|
1304
|
+
};
|
|
1305
|
+
};
|
|
1306
|
+
const special = {
|
|
1307
|
+
"repos.eventsPage": feed("repos.eventsPage"),
|
|
1308
|
+
"users.eventsPage": feed("users.eventsPage"),
|
|
1309
|
+
"search.threadsPage": search("threadsPage"),
|
|
1310
|
+
"search.reposPage": search("reposPage"),
|
|
1311
|
+
"search.commitsPage": search("commitsPage"),
|
|
1312
|
+
"search.codePage": search("codePage"),
|
|
1313
|
+
"threads.listPage": async (repo, given = {}) => {
|
|
1314
|
+
if (given.state === "merged" && given.kind && given.kind !== "pull_request") return { items: [] };
|
|
1315
|
+
const query = { ...given };
|
|
1316
|
+
const ignored = THREAD_FILTERS.filter((filter) => query[filter] !== void 0 && !spec.threads.listFilters?.includes(filter));
|
|
1317
|
+
for (const filter of ignored) delete query[filter];
|
|
1318
|
+
const run = (cursor) => listThreads(repo, {
|
|
1319
|
+
...query,
|
|
1320
|
+
...query.state === "merged" ? { kind: "pull_request" } : {},
|
|
1321
|
+
cursor
|
|
1322
|
+
});
|
|
1323
|
+
const page = await nonEmptyPage(run, query.cursor);
|
|
1324
|
+
if (!ignored.length || !isFirstPage(query.cursor)) return page;
|
|
1325
|
+
const warnings = ignored.map((filter) => ({
|
|
1326
|
+
code: "filter_unsupported",
|
|
1327
|
+
message: `This listing has no ${filter} filter; it was ignored`
|
|
1328
|
+
}));
|
|
1329
|
+
return {
|
|
1330
|
+
...page,
|
|
1331
|
+
warnings: [...warnings, ...page.warnings ?? []]
|
|
1332
|
+
};
|
|
1333
|
+
},
|
|
1334
|
+
"repos.byOwnerPage": (owner, query = {}) => nonEmptyPage(async (cursor) => {
|
|
1335
|
+
const page = await listOwnerRepos(owner, {
|
|
1336
|
+
...query,
|
|
1337
|
+
cursor
|
|
1338
|
+
});
|
|
1339
|
+
return !query.visibility || query.visibility === "all" ? page : {
|
|
1340
|
+
...page,
|
|
1341
|
+
items: page.items.filter((repo) => repo.visibility === query.visibility)
|
|
1342
|
+
};
|
|
1343
|
+
}, query.cursor),
|
|
1344
|
+
"threads.eventsPage": async (ref, listOptions) => {
|
|
1345
|
+
const page = await listEvents(ref, listOptions);
|
|
1346
|
+
return {
|
|
1347
|
+
...page,
|
|
1348
|
+
items: page.items.map(completeEvent)
|
|
1349
|
+
};
|
|
1350
|
+
},
|
|
1351
|
+
"threads.commentsPage": (ref, listOptions = {}) => {
|
|
1352
|
+
const since = listOptions.since;
|
|
1353
|
+
if (!since) return listComments(ref, listOptions);
|
|
1354
|
+
return nonEmptyPage(async (cursor) => {
|
|
1355
|
+
const page = await listComments(ref, {
|
|
1356
|
+
...listOptions,
|
|
1357
|
+
cursor
|
|
1358
|
+
});
|
|
1359
|
+
return {
|
|
1360
|
+
...page,
|
|
1361
|
+
items: page.items.filter((comment) => (comment.updatedAt ?? comment.createdAt ?? since) >= since)
|
|
1362
|
+
};
|
|
1363
|
+
}, listOptions.cursor);
|
|
1364
|
+
},
|
|
1365
|
+
"threads.getComment": kindGate("threads.getComment", Object.fromEntries(KINDS.map((kind) => [kind, (kindEnv) => getCommentKinds(spec, kindEnv)[kind]])), (ref, options) => !isUnsupported(resolve(spec.threads.getComment?.kinds[ref.thread.kind], env)) ? spec.threads.getComment.run(ref, options) : listed(call("threads.comments")(ref.thread, options), ref.id, "Comment")),
|
|
1366
|
+
"threads.getReview": gate("threads.getReview", (reviewEnv) => getReviewSupport(spec, reviewEnv), (ref, options) => !isUnsupported(resolve(spec.threads.getReview?.support, env)) ? spec.threads.getReview.run(ref, options) : listed(call("threads.reviews")(ref.thread, options), ref.id, "Review")),
|
|
1367
|
+
"ci.getJob": gate("ci.getJob", (jobEnv) => ciJobSupport(spec, jobEnv), (ref, options) => {
|
|
1368
|
+
if (!isUnsupported(resolve(spec.ci?.getJob?.support, env))) return spec.ci.getJob.run(ref, options);
|
|
1369
|
+
if (!ref.run) return Promise.reject(new UnsupportedOperationError(`${definition.forge} reads a CI job from its run's jobs, and this ref names no run`, origin));
|
|
1370
|
+
return listed(call("ci.jobs")(ref.run, options), ref.id, "CI job");
|
|
1371
|
+
}),
|
|
1372
|
+
"commits.getComment": gate("commits.getComment", (commentEnv) => commitCommentSupport(spec, commentEnv), (ref, options) => !isUnsupported(resolve(spec.commits?.getComment?.support, env)) ? spec.commits.getComment.run(ref, options) : listed(call("commits.comments")(ref.commit, options), ref.id, "Comment")),
|
|
1373
|
+
"threads.subscribe": kindGate("threads.subscribe", subscriptions?.kinds, subscriptions?.run?.subscribe),
|
|
1374
|
+
"threads.unsubscribe": kindGate("threads.unsubscribe", subscriptions?.kinds, subscriptions?.run?.unsubscribe),
|
|
1375
|
+
"threads.approve": gate("threads.approve", approve?.support, approve?.run),
|
|
1376
|
+
"releases.downloadAsset": async (ref, options) => {
|
|
1377
|
+
const stream = await gate("releases.downloadAsset", spec.releases?.downloadAsset?.support, spec.releases?.downloadAsset?.run)(ref, options);
|
|
1378
|
+
if (!options?.as || options.as === "stream") return stream;
|
|
1379
|
+
const bytes = new Uint8Array(await new Response(stream).arrayBuffer());
|
|
1380
|
+
return options.as === "text" ? decodeText(bytes, `Release asset ${ref.id}`, origin) : bytes;
|
|
1381
|
+
},
|
|
1382
|
+
"contents.compare": async (repo, base, head, compareOptions = {}) => {
|
|
1383
|
+
const comparison = await gate("contents.compare", spec.contents?.compare?.support, spec.contents?.compare?.run)(repo, base, head, compareOptions);
|
|
1384
|
+
const { commitLimit, files } = compareOptions;
|
|
1385
|
+
if (commitLimit === void 0 && files !== false) return comparison;
|
|
1386
|
+
const commits = commitLimit === void 0 ? comparison.commits : comparison.commits.slice(0, Math.max(0, commitLimit));
|
|
1387
|
+
return {
|
|
1388
|
+
...comparison,
|
|
1389
|
+
commits: files === false ? commits.map(({ files: _files, ...commit }) => commit) : commits,
|
|
1390
|
+
...files === false ? { files: [] } : {}
|
|
1391
|
+
};
|
|
1392
|
+
},
|
|
1393
|
+
"contents.resolveRef": (repo, ref, options) => isSha(ref) ? Promise.resolve(ref.toLowerCase()) : gate("contents.resolveRef", spec.contents?.resolveRef?.support, spec.contents?.resolveRef?.run)(repo, ref, options),
|
|
1394
|
+
"contents.commitFiles": async (repo, input, options) => {
|
|
1395
|
+
const declared = spec.contents?.commitFiles;
|
|
1396
|
+
const level = resolve(declared?.support, env);
|
|
1397
|
+
if (!declared?.run || isUnsupported(level)) throw unsupported("contents.commitFiles", level);
|
|
1398
|
+
const changes = input.changes.map((change) => ({
|
|
1399
|
+
...change,
|
|
1400
|
+
path: change.path.replace(/^\/+/, "")
|
|
1401
|
+
}));
|
|
1402
|
+
const paths = new Set(changes.map((change) => change.path));
|
|
1403
|
+
if (!changes.length || paths.size < changes.length) throw new TypeError("`changes` must name at least one file, and each file once");
|
|
1404
|
+
const invalid = changes.find((change) => change.path.split("/").some((segment) => segment === "" || segment === "." || segment === ".."));
|
|
1405
|
+
if (invalid) throw new TypeError(`\`${invalid.path}\` is not a path to a file: it has an empty, \`.\` or \`..\` segment`);
|
|
1406
|
+
if (!input.branch || !input.message.trim()) throw new TypeError("`branch` and `message` cannot be empty");
|
|
1407
|
+
if (input.expectedHead !== void 0 && !isSha(input.expectedHead)) throw new TypeError("`expectedHead` must be a full commit sha");
|
|
1408
|
+
if (input.expectedHead !== void 0 && input.createFrom !== void 0) throw new TypeError("`expectedHead` and `createFrom` cannot be combined: a branch created from `createFrom` has no head yet");
|
|
1409
|
+
return declared.run(repo, {
|
|
1410
|
+
...input,
|
|
1411
|
+
changes
|
|
1412
|
+
}, options);
|
|
1413
|
+
},
|
|
1414
|
+
"webhooks.verify": handlers ? handlers.verify : () => Promise.reject(unsupported("webhooks.verify", capabilities.webhooks.ingest)),
|
|
1415
|
+
"webhooks.ingest": async (delivery) => {
|
|
1416
|
+
if (!handlers) throw unsupported("webhooks.ingest", capabilities.webhooks.ingest);
|
|
1417
|
+
if (!await handlers.verify(delivery)) throw new WebhookVerificationError("Webhook signature verification failed", origin);
|
|
1418
|
+
return (await handlers.translate(delivery)).map(completeEvent);
|
|
1419
|
+
},
|
|
1420
|
+
"sources.stream": (streamOptions) => declaredStream?.run && !isUnsupported(resolve(declaredStream.support, env)) ? completeItems(declaredStream.run(streamOptions)) : emptyIterable("sources.stream", resolve(declaredStream?.support, env)),
|
|
1421
|
+
"securityAlerts.listPage": (repo, listOptions = {}) => {
|
|
1422
|
+
if (!(alerts?.listPage && (listOptions.kind ? !isUnsupported(resolve(alerts.kinds[listOptions.kind], env)) : ALERT_KINDS.some((kind) => !isUnsupported(resolve(alerts.kinds[kind], env)))))) {
|
|
1423
|
+
const level = listOptions.kind ? resolve(alerts?.kinds[listOptions.kind], env) : ALERT_KINDS.every((kind) => resolve(alerts?.kinds[kind], env) === "not_applicable") ? "not_applicable" : false;
|
|
1424
|
+
return Promise.reject(listOptions.kind ? new UnsupportedOperationError(`${definition.forge} ${level === "not_applicable" ? "has no" : "cannot list"} ${listOptions.kind.replace("_", " ")} alerts`, origin) : unsupported("securityAlerts.list", level));
|
|
1425
|
+
}
|
|
1426
|
+
return alerts.listPage(repo, listOptions);
|
|
1427
|
+
},
|
|
1428
|
+
"installations.provider": (installation) => {
|
|
1429
|
+
if (!installationsSupported()) throw unsupported("installations.provider", resolve(declaredInstallations?.support, env));
|
|
1430
|
+
return declaredInstallations.run.provider(installation);
|
|
1431
|
+
},
|
|
1432
|
+
"installations.providers": () => installationsSupported() ? declaredInstallations.run.providers() : emptyIterable("installations.providers", resolve(declaredInstallations?.support, env))
|
|
1433
|
+
};
|
|
1434
|
+
for (const entry of CAPABILITY_TABLE) {
|
|
1435
|
+
const declared = entry.spec ? readPath(spec, entry.spec) : void 0;
|
|
1436
|
+
for (const verb of entry.verbs ?? []) if (verb in special) set(verb, special[verb]);
|
|
1437
|
+
else if (entry.listings?.includes(verb)) {
|
|
1438
|
+
const pageVerb = `${verb}Page`;
|
|
1439
|
+
const run = typeof declared?.run === "function" ? declared.run : declared?.run?.[pageVerb.slice(pageVerb.indexOf(".") + 1)];
|
|
1440
|
+
const page = special[pageVerb] ?? (entry.perKind ? kindGate(verb, declared?.kinds, run) : gate(verb, declared?.support, run));
|
|
1441
|
+
const untargeted = UNTARGETED.has(verb);
|
|
1442
|
+
set(verb, (...args) => listing((options) => page(...untargeted ? [] : [args[0]], options), (untargeted ? args[0] : args[1]) ?? {}));
|
|
1443
|
+
} else {
|
|
1444
|
+
const run = typeof declared?.run === "function" ? declared.run : declared?.run?.[verb.slice(verb.indexOf(".") + 1)];
|
|
1445
|
+
set(verb, entry.perKind ? kindGate(verb, declared?.kinds, run) : gate(verb, declared?.support, run));
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
api.webhooks.events = handlers?.events ?? [];
|
|
1449
|
+
async function listed(items, id, what) {
|
|
1450
|
+
for await (const item of items) if (item.ref.id === id) return item;
|
|
1451
|
+
throw new NotFoundError(`${what} ${id} not found`, 404, "", origin);
|
|
1452
|
+
}
|
|
1453
|
+
return trackDeclared({
|
|
1454
|
+
...declaredSpec.extensions,
|
|
1455
|
+
...api,
|
|
1456
|
+
forge: definition.forge,
|
|
1457
|
+
instance,
|
|
1458
|
+
baseUrl,
|
|
1459
|
+
authKind,
|
|
1460
|
+
request: createRequest(spec.request ?? fetcher, options.readOnly ? { readOnly: (method, path) => new ReadOnlyError(`${method} ${path} is a write and this ${definition.forge} provider is read-only; pass \`mutates: false\` if it only reads`, origin) } : {}),
|
|
1461
|
+
get capabilities() {
|
|
1462
|
+
return capabilities;
|
|
1463
|
+
},
|
|
1464
|
+
rateLimits: spec.rateLimits ?? (() => {
|
|
1465
|
+
const now = Date.now();
|
|
1466
|
+
for (const [resource, budget] of budgets) if (budget.resetAt && budget.resetAt.getTime() <= now) budgets.delete(resource);
|
|
1467
|
+
return [...budgets.values()].map((budget) => ({ ...budget }));
|
|
1468
|
+
}),
|
|
1469
|
+
async refreshCapabilities() {
|
|
1470
|
+
if (!options.instanceVersion && probeVersion) {
|
|
1471
|
+
env.version = await probeVersion();
|
|
1472
|
+
capabilities = capabilitiesOf(spec, env, flags);
|
|
1473
|
+
}
|
|
1474
|
+
return capabilities;
|
|
1475
|
+
},
|
|
1476
|
+
normaliseMarkdown: spec.normaliseMarkdown ?? ((body) => body),
|
|
1477
|
+
scopesFor: (verb) => spec.scopes?.(verb) ?? {},
|
|
1478
|
+
can: (verb, kind) => can(capabilities, verb, kind),
|
|
1479
|
+
support: (verb, kind) => support(capabilities, verb, kind),
|
|
1480
|
+
urlFor: ((target) => spec.web ? webUrlFor(spec.web, target) : void 0),
|
|
1481
|
+
webOrigin: spec.web ? new URL(spec.web.baseUrl).origin : void 0,
|
|
1482
|
+
parseUrl: (url) => spec.web ? parseWebUrl(spec.web, url, origin) : void 0,
|
|
1483
|
+
referenceFor: (ref, referenceOptions) => referenceFor(spec.web, ref, referenceOptions),
|
|
1484
|
+
parseReferences: (text, { from }) => parseReferences(spec.web, text, from, origin)
|
|
1485
|
+
}, () => capabilitiesOf(spec, env, flags, true));
|
|
1486
|
+
}
|
|
1487
|
+
/**
|
|
1488
|
+
* Defines a forge provider. Returns the function end users call to create
|
|
1489
|
+
* one, for example `github({ auth })`. Nothing touches the network until a
|
|
1490
|
+
* method of the provider is called.
|
|
1491
|
+
* @param definition The defaults, authentication and setup of the forge.
|
|
1492
|
+
*/
|
|
1493
|
+
function defineForgeProvider(definition) {
|
|
1494
|
+
return ((options = {}) => createProvider(definition, options));
|
|
1495
|
+
}
|
|
1496
|
+
/** The first of `names` the delivery carries a non-empty value for. */
|
|
1497
|
+
function firstHeader(delivery, names) {
|
|
1498
|
+
for (const name of typeof names === "string" ? [names] : names) {
|
|
1499
|
+
const value = headerValue(delivery.headers, name);
|
|
1500
|
+
if (value) return value;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
/**
|
|
1504
|
+
* Checks a hex HMAC-SHA256 of the raw body, sent in the first of `header`
|
|
1505
|
+
* present, after an optional `prefix` such as `sha256=`. The delivery's own
|
|
1506
|
+
* `secret` takes precedence over the provider's.
|
|
1507
|
+
*/
|
|
1508
|
+
async function verifyHmacSignature(delivery, secret, { header, prefix = "" }) {
|
|
1509
|
+
const signature = firstHeader(delivery, header);
|
|
1510
|
+
const key = delivery.secret ?? secret;
|
|
1511
|
+
if (!key || !signature) return false;
|
|
1512
|
+
return timingSafeEqual(signature.toLowerCase(), `${prefix}${await hmacSha256Hex(key, delivery.body)}`);
|
|
1513
|
+
}
|
|
1514
|
+
/** Checks a secret sent verbatim in `header`. */
|
|
1515
|
+
function verifySharedToken(delivery, secret, header) {
|
|
1516
|
+
const token = headerValue(delivery.headers, header);
|
|
1517
|
+
const key = delivery.secret ?? secret;
|
|
1518
|
+
return Boolean(key && token && timingSafeEqual(token, key));
|
|
1519
|
+
}
|
|
1520
|
+
/**
|
|
1521
|
+
* The kind, detail and summary of one ref update in a push: a deletion, a creation, or new commits. Without
|
|
1522
|
+
* `commits` or `commitCount`, the detail has no `commitCount`.
|
|
1523
|
+
*/
|
|
1524
|
+
function refEvent(who, change) {
|
|
1525
|
+
const name = change.ref.replace(/^refs\/(?:heads|tags)\//, "");
|
|
1526
|
+
const refType = change.refType ?? (change.ref.startsWith("refs/tags/") ? "tag" : "branch");
|
|
1527
|
+
if (change.deleted || change.created) return {
|
|
1528
|
+
kind: "ref",
|
|
1529
|
+
action: change.deleted ? "deleted" : "created",
|
|
1530
|
+
detail: {
|
|
1531
|
+
type: "ref",
|
|
1532
|
+
ref: change.ref,
|
|
1533
|
+
refType
|
|
1534
|
+
},
|
|
1535
|
+
summary: `${who} ${change.deleted ? "deleted" : "created"} ${name}`
|
|
1536
|
+
};
|
|
1537
|
+
const count = change.commitCount ?? change.commits?.length;
|
|
1538
|
+
return {
|
|
1539
|
+
kind: "push",
|
|
1540
|
+
detail: {
|
|
1541
|
+
type: "push",
|
|
1542
|
+
ref: change.ref,
|
|
1543
|
+
before: change.before,
|
|
1544
|
+
after: change.after,
|
|
1545
|
+
commitCount: count,
|
|
1546
|
+
forced: change.forced ?? false,
|
|
1547
|
+
commits: change.commits ?? []
|
|
1548
|
+
},
|
|
1549
|
+
summary: count === void 0 ? `${who} pushed to ${name}` : `${who} pushed ${count} commit(s) to ${name}`
|
|
1550
|
+
};
|
|
1551
|
+
}
|
|
1552
|
+
/** The forge's own event names for `events`, plus any `nativeEvents` passed through unchanged. */
|
|
1553
|
+
function nativeEventsFor(map, events, nativeEvents) {
|
|
1554
|
+
const names = new Set(nativeEvents ?? []);
|
|
1555
|
+
for (const kind of events ?? []) for (const name of map[kind] ?? []) names.add(name);
|
|
1556
|
+
return [...names];
|
|
1557
|
+
}
|
|
1558
|
+
/** The normalised kinds a subscription to `nativeEvents` covers. */
|
|
1559
|
+
function eventKindsOf(map, nativeEvents) {
|
|
1560
|
+
const kinds = /* @__PURE__ */ new Set();
|
|
1561
|
+
for (const [kind, names] of Object.entries(map)) if (nativeEvents.includes("*") || names.some((name) => nativeEvents.includes(name))) kinds.add(kind);
|
|
1562
|
+
return [...kinds];
|
|
1563
|
+
}
|
|
1564
|
+
//#endregion
|
|
1565
|
+
export { toFileContent as C, verifySharedToken as E, threadSnapshot as S, verifyHmacSignature as T, reviewState as _, eventAction as a, splitMessage as b, existingFiles as c, headerValue as d, inDirectories as f, refEvent as g, perKind as h, defineForgeProvider as i, firstHeader as l, nativeEventsFor as m, bodyText as n, eventKindsOf as o, isSha as p, changeBase64 as r, eventTime as s, WRITE_VERBS as t, fromBase64 as u, signRs256Jwt as v, verb as w, supportOnly as x, snapshotOfThread as y };
|