@vite-hub/workspace 0.1.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +164 -107
- package/dist/abort-BCwpdrN0.js +32 -0
- package/dist/blob-database.d.ts +70 -117
- package/dist/blob-database.js +48 -41
- package/dist/checkout.d.ts +128 -0
- package/dist/checkout.js +849 -0
- package/dist/cloudflare.d.ts +2 -2
- package/dist/cloudflare.js +1 -1
- package/dist/config-B-863EgC.js +15 -0
- package/dist/{config-B7dmzDX3.js → config-BAgL2dtB.js} +48 -84
- package/dist/{config-DLKdaFWN.d.ts → config-BQKcPawI.d.ts} +1 -1
- package/dist/discard-CNNtCozM.js +8 -0
- package/dist/durability.d.ts +22 -0
- package/dist/durability.js +70 -0
- package/dist/error-diagnostics-CtKjGtGb.js +188 -0
- package/dist/error-diagnostics-DSkCJC_L.js +266 -0
- package/dist/file-2pFYNtsU.js +22 -0
- package/dist/{files-C7Px8uaC.js → files-BOo4SbwE.js} +2 -2
- package/dist/files.d.ts +38 -0
- package/dist/files.js +6 -0
- package/dist/{github-CPxHtFB7.js → github-CrYp4v8k.js} +32 -5
- package/dist/{glob--XcLlcml.js → glob-B8YGvTrZ.js} +4 -5
- package/dist/{glob--kNYDbfU.js → glob-Cjxms1t7.js} +1 -1
- package/dist/{host-CFnrTXTK.js → host-BFBpXn0N.js} +58 -47
- package/dist/{hosted-acMA5XyL.js → hosted-KcUR_jPv.js} +216 -93
- package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
- package/dist/hosted-vercel-blob.d.ts +2 -2
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +5 -3
- package/dist/hosted.js +2 -2
- package/dist/index.d.ts +9 -51
- package/dist/index.js +21 -91
- package/dist/{lifecycle-BwZ7c9hb.js → lifecycle-B-enk_4A.js} +8 -8
- package/dist/lineage.d.ts +26 -0
- package/dist/lineage.js +76 -0
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +2 -2
- package/dist/{mcp-resources-BREFCmtn.js → mcp-resources-DF0F5rcL.js} +2 -2
- package/dist/{memory-BbwOqDXl.js → memory-BOexthyW.js} +3 -4
- package/dist/{metadata-target-DZEZQGHA.js → metadata-target-CWz6KHKq.js} +17 -16
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
- package/dist/operations-C6FpR8Rr.js +389 -0
- package/dist/operations-CE2drFih.js +1234 -0
- package/dist/operations.d.ts +41 -4
- package/dist/operations.js +3 -2
- package/dist/{path-CNAwN7pw.js → path--wrT_Azm.js} +2 -3
- package/dist/path-AxMho1wo.d.ts +7 -0
- package/dist/{plugins-DqQ8b4T5.d.ts → plugins-C8C0auoW.d.ts} +1 -1
- package/dist/{provider-kXjfli9u.js → provider-9s4Ufkm5.js} +104 -82
- package/dist/providers/github/store.d.ts +1 -1
- package/dist/providers/github/store.js +1 -1
- package/dist/registry-B3BBm4Ts.d.ts +19 -0
- package/dist/{registry-Bp-8UUfG.js → registry-CNphafBx.js} +55 -20
- package/dist/registry-CYNN623b.d.ts +9 -0
- package/dist/request-scope-Dw5n8bMC.js +83 -0
- package/dist/results-DgkZUmTL.js +8 -0
- package/dist/{rolldown-runtime-B4iAMlE-.js → rolldown-runtime-rQ84J-ij.js} +2 -3
- package/dist/runtime/assets.d.ts +1 -1
- package/dist/runtime/assets.js +3 -3
- package/dist/runtime/empty-assets-registry.d.ts +1 -1
- package/dist/runtime/empty-registry.d.ts +2 -1
- package/dist/runtime/registry.d.ts +2 -0
- package/dist/runtime/registry.js +23 -0
- package/dist/runtime/request.d.ts +4 -0
- package/dist/runtime/request.js +8 -0
- package/dist/runtime/state.d.ts +5 -4
- package/dist/runtime/state.js +8 -18
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +9 -8
- package/dist/runtime.js +23 -26
- package/dist/{search-CrTmXj5h.js → search-C_RfoM2j.js} +2 -2
- package/dist/{server-BNQ-Nbjj.js → server-8tGltlGz.js} +53 -40
- package/dist/server.d.ts +17 -8
- package/dist/server.js +1 -1
- package/dist/shared-B3_EUk89.js +848 -0
- package/dist/source-metadata.d.ts +6 -2
- package/dist/source-metadata.js +8 -8
- package/dist/state-BISnUf1s.d.ts +35 -0
- package/dist/{ai-BZyLwULx.js → state-DbrW-njQ.js} +96 -54
- package/dist/{store-CXgmu-uw.js → store-ybhyD38Z.js} +250 -106
- package/dist/{sync-CN6ec-5M.js → sync-CCD_VYC8.js} +4 -4
- package/dist/target-jWhTdIuF.js +89 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{types-DeK9GIxy.d.ts → types-BbtwmBZ5.d.ts} +68 -14
- package/dist/use-C6lV3-wC.d.ts +321 -0
- package/dist/{use-BQj7nSz6.js → use-CSpT5W87.js} +75 -82
- package/dist/{utils-Blrh4N2n.js → utils-CgMZCHsX.js} +112 -41
- package/dist/vite.d.ts +585 -2
- package/dist/vite.js +21368 -1
- package/dist/{workspace-BWJQBK1u.d.ts → workspace-CYB2xZ1T.d.ts} +1 -1
- package/dist/{workspace-6pxkOuxr.js → workspace-sPWn2Jxj.js} +125 -40
- package/package.json +46 -55
- package/dist/ai-BW2ZhizI.d.ts +0 -177
- package/dist/ai.d.ts +0 -3
- package/dist/ai.js +0 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +0 -19
- package/dist/error-diagnostics-A_8Kp-48.js +0 -116
- package/dist/error-diagnostics-DY5GP47p.js +0 -96
- package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +0 -354
- package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +0 -214
- package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +0 -527
- package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +0 -248
- package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +0 -179
- package/dist/file-C0_aPWSS.js +0 -26
- package/dist/file-metadata-CxDy-E2H.js +0 -58
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +0 -2278
- package/dist/github-DtncTfmv-Du2S8lGF.js +0 -4159
- package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +0 -2530
- package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +0 -489
- package/dist/hosted-vercel-blob-DKntsHaf.js +0 -12603
- package/dist/inspect-BoObD2cJ.js +0 -167
- package/dist/mountx.d.ts +0 -8
- package/dist/mountx.js +0 -145
- package/dist/nitro.d.ts +0 -2
- package/dist/nitro.js +0 -2
- package/dist/nuxt.d.ts +0 -27
- package/dist/nuxt.js +0 -38
- package/dist/operations-BcpWr41m.js +0 -159
- package/dist/operations-CGqY1XeG.js +0 -965
- package/dist/operations-DnOwKsJT.d.ts +0 -136
- package/dist/registry-Cg1TJVVZ.d.ts +0 -10
- package/dist/request-execution-Dk9rY-Yh.js +0 -84
- package/dist/shared-DalXdP0i.js +0 -2158
- package/dist/state-B8zbLi5t.d.ts +0 -26
- package/dist/target-D4Bqb1eH.js +0 -11
- package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +0 -125
- package/dist/token-CO62GglH.js +0 -61
- package/dist/use-DhwhbAVV.d.ts +0 -108
- package/dist/vite-BEvgU2GY.js +0 -20909
- package/dist/vite-CcZmMQ7S.d.ts +0 -476
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +0 -1565
|
@@ -1,4159 +0,0 @@
|
|
|
1
|
-
import { $ as forgeIterable, A as ForgeError, At as resolveToken, Bt as toPullStats, Ct as rateLimitPart, Dt as requireIssueOrPull, E as BranchMovedError, F as NotFoundError, Ft as teamOrg, G as actorLogin, H as UnsupportedOperationError, Ht as versionAtLeast, I as OWNER_NAME, It as toDate, J as createFetcher, K as anySignal, L as REACTION_CONTENTS, Lt as toFileStatus, M as InsufficientScopeError, Mt as soleMergeMethod, N as MergeBlockedError, Nt as summariseChecks, O as ForbiddenError, Ot as requireThread, P as MergeConflictError, R as RateLimitedError, Rt as toMergeError, St as rateLimitOf, T as AuthenticationRequiredError, Tt as reactionContent, Vt as toWarning, W as abortable, Y as createListing, Z as degradesToWarning, _t as milestoneId, at as isFirstPage, bt as phased, ct as isSecondaryRateLimit, dt as latestCommentOf, et as getManyConcurrently, it as hostOf, j as ForgeTimeoutError, jt as sleep, k as ForgeApiError, mt as memo, ot as isNamespaceRef, q as checkRunState, st as isResolvedThread, tt as githubShapedWeb, ut as iteratePages, wt as rateLimitReset, z as ReadOnlyError, zt as toPage } from "./shared-DalXdP0i.js";
|
|
2
|
-
import { C as toFileContent, T as verifyHmacSignature, _ as reviewState, b as splitMessage, c as existingFiles, f as inDirectories, h as perKind, i as defineForgeProvider, m as nativeEventsFor, o as eventKindsOf, p as isSha, r as changeBase64, s as eventTime, t as WRITE_VERBS, u as fromBase64, v as signRs256Jwt, w as verb, x as supportOnly } from "./webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js";
|
|
3
|
-
import { t as toAuthorAssociation } from "./association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js";
|
|
4
|
-
//#region ../forge/dist/github-DtncTfmv.js
|
|
5
|
-
const RESERVED_PATHS = [
|
|
6
|
-
"about",
|
|
7
|
-
"account",
|
|
8
|
-
"apps",
|
|
9
|
-
"codespaces",
|
|
10
|
-
"collections",
|
|
11
|
-
"contact",
|
|
12
|
-
"customer-stories",
|
|
13
|
-
"dashboard",
|
|
14
|
-
"enterprise",
|
|
15
|
-
"enterprises",
|
|
16
|
-
"events",
|
|
17
|
-
"explore",
|
|
18
|
-
"features",
|
|
19
|
-
"gist",
|
|
20
|
-
"issues",
|
|
21
|
-
"join",
|
|
22
|
-
"login",
|
|
23
|
-
"logout",
|
|
24
|
-
"marketplace",
|
|
25
|
-
"new",
|
|
26
|
-
"notifications",
|
|
27
|
-
"organizations",
|
|
28
|
-
"orgs",
|
|
29
|
-
"pricing",
|
|
30
|
-
"pulls",
|
|
31
|
-
"search",
|
|
32
|
-
"security",
|
|
33
|
-
"settings",
|
|
34
|
-
"signup",
|
|
35
|
-
"site",
|
|
36
|
-
"sponsors",
|
|
37
|
-
"stars",
|
|
38
|
-
"topics",
|
|
39
|
-
"trending",
|
|
40
|
-
"users",
|
|
41
|
-
"watching"
|
|
42
|
-
];
|
|
43
|
-
const REFERENCES = {
|
|
44
|
-
threads: [{
|
|
45
|
-
prefix: "#",
|
|
46
|
-
kind: "issue"
|
|
47
|
-
}, {
|
|
48
|
-
prefix: "GH-",
|
|
49
|
-
kind: "issue",
|
|
50
|
-
sameRepo: true
|
|
51
|
-
}],
|
|
52
|
-
repo: OWNER_NAME,
|
|
53
|
-
commits: true
|
|
54
|
-
};
|
|
55
|
-
function isGheCom(host) {
|
|
56
|
-
return /^api\.[^.]+\.ghe\.com$/.test(host);
|
|
57
|
-
}
|
|
58
|
-
/** The web host for an API host: `api.github.com` and `api.<name>.ghe.com` drop the `api.` prefix. */
|
|
59
|
-
function webHost(host) {
|
|
60
|
-
return host === "api.github.com" || isGheCom(host) ? host.slice(4) : host;
|
|
61
|
-
}
|
|
62
|
-
const GITHUB_WEB = {
|
|
63
|
-
forge: "github",
|
|
64
|
-
baseUrl: "https://api.github.com",
|
|
65
|
-
instance: webHost,
|
|
66
|
-
links: ({ baseUrl }) => {
|
|
67
|
-
const host = new URL(baseUrl).host;
|
|
68
|
-
const enterprise = host !== "api.github.com" && !isGheCom(host);
|
|
69
|
-
return githubShapedWeb(enterprise ? baseUrl.replace(/\/api\/v3$/, "") : `https://${webHost(host)}`, {
|
|
70
|
-
pull: "pull",
|
|
71
|
-
discussions: true,
|
|
72
|
-
...host === "api.github.com" ? { rawOrigin: "https://raw.githubusercontent.com" } : {},
|
|
73
|
-
commentFragment: "issuecomment-",
|
|
74
|
-
file: (at) => `/blob/${encodeURIComponent(at)}`,
|
|
75
|
-
lineFragment: (line) => `L${line}`,
|
|
76
|
-
reserved: RESERVED_PATHS,
|
|
77
|
-
references: REFERENCES
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
const TOKEN_PREFIXES = [
|
|
82
|
-
["ghp_", "classic"],
|
|
83
|
-
["gho_", "classic"],
|
|
84
|
-
["github_pat_", "fine-grained"],
|
|
85
|
-
["ghu_", "app-user"],
|
|
86
|
-
["ghs_", "installation"]
|
|
87
|
-
];
|
|
88
|
-
/** The kind of a GitHub token, from its `kind` or the prefix of `token`; `undefined` when neither tells. */
|
|
89
|
-
function tokenKindOf(auth, token = typeof auth.token === "string" ? auth.token : void 0) {
|
|
90
|
-
return auth.kind ?? (token === void 0 ? void 0 : TOKEN_PREFIXES.find(([prefix]) => token.startsWith(prefix))?.[1]);
|
|
91
|
-
}
|
|
92
|
-
const JWT_LIFETIME_SECONDS = 540;
|
|
93
|
-
const REFRESH_MARGIN_MS = 6e4;
|
|
94
|
-
function createAppCredentials(auth, context) {
|
|
95
|
-
let jwt;
|
|
96
|
-
const tokens = /* @__PURE__ */ new Map();
|
|
97
|
-
const exchanges = /* @__PURE__ */ new Map();
|
|
98
|
-
async function appJwt() {
|
|
99
|
-
if (jwt && jwt.expiresAt > Date.now() + REFRESH_MARGIN_MS) return jwt.value;
|
|
100
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
101
|
-
const value = signRs256Jwt(auth.privateKey, {
|
|
102
|
-
iss: String(auth.appId),
|
|
103
|
-
iat: now - 60,
|
|
104
|
-
exp: now + JWT_LIFETIME_SECONDS
|
|
105
|
-
});
|
|
106
|
-
const entry = {
|
|
107
|
-
value,
|
|
108
|
-
expiresAt: (now + JWT_LIFETIME_SECONDS) * 1e3
|
|
109
|
-
};
|
|
110
|
-
jwt = entry;
|
|
111
|
-
value.catch(() => {
|
|
112
|
-
if (jwt === entry) jwt = void 0;
|
|
113
|
-
});
|
|
114
|
-
return value;
|
|
115
|
-
}
|
|
116
|
-
const fetcher = createFetcher({
|
|
117
|
-
...context,
|
|
118
|
-
authHeaders: async () => ({ authorization: `Bearer ${await appJwt()}` })
|
|
119
|
-
});
|
|
120
|
-
async function installationTokenDetails(installationId, options) {
|
|
121
|
-
options?.signal?.throwIfAborted();
|
|
122
|
-
const cached = tokens.get(installationId);
|
|
123
|
-
if (cached && cached.expiresAt.getTime() > Date.now() + REFRESH_MARGIN_MS) return cached;
|
|
124
|
-
let exchange = exchanges.get(installationId);
|
|
125
|
-
if (!exchange) {
|
|
126
|
-
exchange = fetcher.json(`/app/installations/${installationId}/access_tokens`, { method: "POST" }).then(({ data }) => {
|
|
127
|
-
const token = {
|
|
128
|
-
token: data.token,
|
|
129
|
-
expiresAt: new Date(data.expires_at),
|
|
130
|
-
permissions: data.permissions ?? {},
|
|
131
|
-
repositorySelection: data.repository_selection
|
|
132
|
-
};
|
|
133
|
-
tokens.set(installationId, token);
|
|
134
|
-
return token;
|
|
135
|
-
});
|
|
136
|
-
const forget = () => exchanges.delete(installationId);
|
|
137
|
-
exchange.then(forget, forget);
|
|
138
|
-
exchanges.set(installationId, exchange);
|
|
139
|
-
}
|
|
140
|
-
return abortable(exchange, options?.signal);
|
|
141
|
-
}
|
|
142
|
-
return {
|
|
143
|
-
appJwt,
|
|
144
|
-
installationTokenDetails,
|
|
145
|
-
installationToken: async (installationId, options) => (await installationTokenDetails(installationId, options)).token
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
function createAuthHeaders(auth, credentials) {
|
|
149
|
-
if (!auth || auth.type === "anonymous") return async () => ({});
|
|
150
|
-
if (auth.type === "token") return async () => ({ authorization: `Bearer ${await resolveToken(auth)}` });
|
|
151
|
-
const app = credentials;
|
|
152
|
-
const installationId = auth.installationId;
|
|
153
|
-
if (installationId === void 0) return async () => ({ authorization: `Bearer ${await app.appJwt()}` });
|
|
154
|
-
return async () => ({ authorization: `Bearer ${await app.installationToken(String(installationId))}` });
|
|
155
|
-
}
|
|
156
|
-
/** Native GitHub event names per normalised kind, for hook subscriptions. */
|
|
157
|
-
const GITHUB_NATIVE_EVENTS = {
|
|
158
|
-
comment: [
|
|
159
|
-
"issue_comment",
|
|
160
|
-
"commit_comment",
|
|
161
|
-
"discussion_comment"
|
|
162
|
-
],
|
|
163
|
-
review: ["pull_request_review"],
|
|
164
|
-
review_comment: ["pull_request_review_comment"],
|
|
165
|
-
state_change: [
|
|
166
|
-
"issues",
|
|
167
|
-
"pull_request",
|
|
168
|
-
"discussion"
|
|
169
|
-
],
|
|
170
|
-
label: [
|
|
171
|
-
"issues",
|
|
172
|
-
"pull_request",
|
|
173
|
-
"label"
|
|
174
|
-
],
|
|
175
|
-
assignment: ["issues", "pull_request"],
|
|
176
|
-
push: ["push"],
|
|
177
|
-
ref: ["create", "delete"],
|
|
178
|
-
repo: ["repository", "public"],
|
|
179
|
-
installation: ["installation", "installation_repositories"],
|
|
180
|
-
membership: [
|
|
181
|
-
"member",
|
|
182
|
-
"membership",
|
|
183
|
-
"organization",
|
|
184
|
-
"team"
|
|
185
|
-
],
|
|
186
|
-
release: ["release"],
|
|
187
|
-
star: ["star"],
|
|
188
|
-
fork: ["fork"],
|
|
189
|
-
wiki: ["gollum"],
|
|
190
|
-
issue_type: ["issues"]
|
|
191
|
-
};
|
|
192
|
-
/** Normalised kinds and actions GitHub deliveries translate into. */
|
|
193
|
-
const GITHUB_WEBHOOK_EVENTS = [
|
|
194
|
-
{
|
|
195
|
-
kind: "comment",
|
|
196
|
-
action: "created"
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
kind: "comment",
|
|
200
|
-
action: "edited"
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
kind: "comment",
|
|
204
|
-
action: "deleted"
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
kind: "review",
|
|
208
|
-
action: "submitted"
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
kind: "review_comment",
|
|
212
|
-
action: "created"
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
kind: "review_comment",
|
|
216
|
-
action: "edited"
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
kind: "review_comment",
|
|
220
|
-
action: "deleted"
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
kind: "state_change",
|
|
224
|
-
action: "opened"
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
kind: "state_change",
|
|
228
|
-
action: "closed"
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
kind: "state_change",
|
|
232
|
-
action: "reopened"
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
kind: "state_change",
|
|
236
|
-
action: "merged"
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
kind: "state_change",
|
|
240
|
-
action: "ready_for_review"
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
kind: "state_change",
|
|
244
|
-
action: "converted_to_draft"
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
kind: "label",
|
|
248
|
-
action: "labelled"
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
kind: "label",
|
|
252
|
-
action: "unlabelled"
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
kind: "assignment",
|
|
256
|
-
action: "assigned"
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
kind: "assignment",
|
|
260
|
-
action: "unassigned"
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
kind: "assignment",
|
|
264
|
-
action: "review_requested"
|
|
265
|
-
},
|
|
266
|
-
{ kind: "push" },
|
|
267
|
-
{
|
|
268
|
-
kind: "ref",
|
|
269
|
-
action: "created"
|
|
270
|
-
},
|
|
271
|
-
{
|
|
272
|
-
kind: "ref",
|
|
273
|
-
action: "deleted"
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
kind: "repo",
|
|
277
|
-
action: "renamed"
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
kind: "repo",
|
|
281
|
-
action: "transferred"
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
kind: "repo",
|
|
285
|
-
action: "archived"
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
kind: "repo",
|
|
289
|
-
action: "unarchived"
|
|
290
|
-
},
|
|
291
|
-
{
|
|
292
|
-
kind: "repo",
|
|
293
|
-
action: "edited"
|
|
294
|
-
},
|
|
295
|
-
{ kind: "installation" },
|
|
296
|
-
{ kind: "membership" },
|
|
297
|
-
{
|
|
298
|
-
kind: "release",
|
|
299
|
-
action: "created"
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
kind: "release",
|
|
303
|
-
action: "published"
|
|
304
|
-
},
|
|
305
|
-
{
|
|
306
|
-
kind: "release",
|
|
307
|
-
action: "edited"
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
kind: "release",
|
|
311
|
-
action: "deleted"
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
kind: "release",
|
|
315
|
-
action: "other"
|
|
316
|
-
},
|
|
317
|
-
{
|
|
318
|
-
kind: "star",
|
|
319
|
-
action: "created"
|
|
320
|
-
},
|
|
321
|
-
{
|
|
322
|
-
kind: "star",
|
|
323
|
-
action: "deleted"
|
|
324
|
-
},
|
|
325
|
-
{
|
|
326
|
-
kind: "fork",
|
|
327
|
-
action: "created"
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
kind: "wiki",
|
|
331
|
-
action: "created"
|
|
332
|
-
},
|
|
333
|
-
{
|
|
334
|
-
kind: "wiki",
|
|
335
|
-
action: "edited"
|
|
336
|
-
},
|
|
337
|
-
{
|
|
338
|
-
kind: "issue_type",
|
|
339
|
-
action: "typed"
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
kind: "issue_type",
|
|
343
|
-
action: "untyped"
|
|
344
|
-
}
|
|
345
|
-
];
|
|
346
|
-
const FORGE = "github";
|
|
347
|
-
function toActor(instance, user) {
|
|
348
|
-
if (!user?.login) return;
|
|
349
|
-
return {
|
|
350
|
-
forge: FORGE,
|
|
351
|
-
instance,
|
|
352
|
-
login: user.login,
|
|
353
|
-
id: String(user.id ?? user.login),
|
|
354
|
-
name: user.name ?? void 0,
|
|
355
|
-
avatarUrl: user.avatar_url,
|
|
356
|
-
url: user.html_url,
|
|
357
|
-
typeRaw: user.type,
|
|
358
|
-
isBotHint: user.type === "Bot" || user.login.endsWith("[bot]"),
|
|
359
|
-
...user.type === "Bot" && user.login.endsWith("[bot]") ? { app: { slug: user.login.slice(0, -5) } } : {}
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
function toUser(instance, user) {
|
|
363
|
-
return {
|
|
364
|
-
...toActor(instance, user),
|
|
365
|
-
bio: user.bio ?? void 0,
|
|
366
|
-
company: user.company ?? void 0,
|
|
367
|
-
location: user.location ?? void 0,
|
|
368
|
-
websiteUrl: user.blog || void 0,
|
|
369
|
-
createdAt: toDate(user.created_at),
|
|
370
|
-
followers: user.followers,
|
|
371
|
-
following: user.following,
|
|
372
|
-
publicRepos: user.public_repos,
|
|
373
|
-
raw: user
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
function toRepoRef(instance, repo) {
|
|
377
|
-
const [owner, name] = repo.full_name.split("/");
|
|
378
|
-
return {
|
|
379
|
-
forge: FORGE,
|
|
380
|
-
instance,
|
|
381
|
-
owner: repo.owner?.login ?? owner ?? "",
|
|
382
|
-
name: repo.name ?? name ?? "",
|
|
383
|
-
externalId: repo.id === void 0 ? void 0 : String(repo.id)
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
/** Reads `owner` and `name` out of an API repository URL, which search results carry instead of a nested repository. */
|
|
387
|
-
function repoRefFromApiUrl(instance, url) {
|
|
388
|
-
const [, owner, name] = url?.match(/\/repos\/([^/]+)\/([^/]+)$/) ?? [];
|
|
389
|
-
return owner && name ? {
|
|
390
|
-
forge: FORGE,
|
|
391
|
-
instance,
|
|
392
|
-
owner,
|
|
393
|
-
name
|
|
394
|
-
} : void 0;
|
|
395
|
-
}
|
|
396
|
-
const MERGE_COMMIT_TITLES = {
|
|
397
|
-
PR_TITLE: "pull_request_title",
|
|
398
|
-
COMMIT_OR_PR_TITLE: "commit_or_pull_request_title",
|
|
399
|
-
MERGE_MESSAGE: "merge_message"
|
|
400
|
-
};
|
|
401
|
-
const MERGE_COMMIT_MESSAGES = {
|
|
402
|
-
PR_BODY: "pull_request_body",
|
|
403
|
-
PR_TITLE: "pull_request_title",
|
|
404
|
-
COMMIT_MESSAGES: "commit_messages",
|
|
405
|
-
BLANK: "blank"
|
|
406
|
-
};
|
|
407
|
-
function toMergeCommitDefaults(title, message) {
|
|
408
|
-
return title || message ? {
|
|
409
|
-
title: MERGE_COMMIT_TITLES[title ?? ""],
|
|
410
|
-
titleRaw: title,
|
|
411
|
-
message: MERGE_COMMIT_MESSAGES[message ?? ""],
|
|
412
|
-
messageRaw: message
|
|
413
|
-
} : void 0;
|
|
414
|
-
}
|
|
415
|
-
function toMergeCommit(raw) {
|
|
416
|
-
const merge = toMergeCommitDefaults(raw.merge_commit_title, raw.merge_commit_message);
|
|
417
|
-
const squash = toMergeCommitDefaults(raw.squash_merge_commit_title, raw.squash_merge_commit_message);
|
|
418
|
-
return merge || squash ? {
|
|
419
|
-
merge,
|
|
420
|
-
squash
|
|
421
|
-
} : void 0;
|
|
422
|
-
}
|
|
423
|
-
function toRepo(instance, raw) {
|
|
424
|
-
const visibility = raw.visibility === "internal" ? "internal" : raw.private || raw.visibility === "private" ? "private" : "public";
|
|
425
|
-
return {
|
|
426
|
-
ref: toRepoRef(instance, raw),
|
|
427
|
-
description: raw.description ?? void 0,
|
|
428
|
-
defaultBranch: raw.default_branch,
|
|
429
|
-
visibility,
|
|
430
|
-
visibilityRaw: raw.visibility ?? (raw.private === void 0 ? void 0 : raw.private ? "private" : "public"),
|
|
431
|
-
isFork: raw.fork ?? false,
|
|
432
|
-
isArchived: raw.archived ?? false,
|
|
433
|
-
parent: raw.parent ? toRepoRef(instance, raw.parent) : void 0,
|
|
434
|
-
topics: raw.topics ?? [],
|
|
435
|
-
url: raw.html_url,
|
|
436
|
-
cloneUrls: raw.clone_url || raw.ssh_url ? {
|
|
437
|
-
https: raw.clone_url,
|
|
438
|
-
ssh: raw.ssh_url
|
|
439
|
-
} : void 0,
|
|
440
|
-
createdAt: toDate(raw.created_at),
|
|
441
|
-
updatedAt: toDate(raw.updated_at),
|
|
442
|
-
pushedAt: toDate(raw.pushed_at),
|
|
443
|
-
owner: toActor(instance, raw.owner),
|
|
444
|
-
language: raw.language ?? void 0,
|
|
445
|
-
homepage: raw.homepage || void 0,
|
|
446
|
-
licence: raw.license?.spdx_id && raw.license.spdx_id !== "NOASSERTION" ? raw.license.spdx_id : void 0,
|
|
447
|
-
stars: raw.stargazers_count,
|
|
448
|
-
forks: raw.forks_count,
|
|
449
|
-
watchers: raw.subscribers_count,
|
|
450
|
-
mergeMethods: raw.allow_merge_commit === void 0 && raw.allow_squash_merge === void 0 && raw.allow_rebase_merge === void 0 ? void 0 : [
|
|
451
|
-
...raw.allow_merge_commit ? ["merge"] : [],
|
|
452
|
-
...raw.allow_squash_merge ? ["squash"] : [],
|
|
453
|
-
...raw.allow_rebase_merge ? ["rebase"] : []
|
|
454
|
-
],
|
|
455
|
-
deleteBranchOnMerge: raw.delete_branch_on_merge,
|
|
456
|
-
mergeCommit: toMergeCommit(raw),
|
|
457
|
-
features: raw.has_issues === void 0 ? void 0 : {
|
|
458
|
-
issues: raw.has_issues,
|
|
459
|
-
pullRequests: true,
|
|
460
|
-
discussions: raw.has_discussions ?? false,
|
|
461
|
-
wiki: raw.has_wiki ?? false,
|
|
462
|
-
projects: raw.has_projects ?? false,
|
|
463
|
-
releases: true
|
|
464
|
-
},
|
|
465
|
-
permissions: raw.permissions ? {
|
|
466
|
-
admin: raw.permissions.admin,
|
|
467
|
-
maintain: raw.permissions.maintain ?? raw.permissions.admin,
|
|
468
|
-
push: raw.permissions.push,
|
|
469
|
-
triage: raw.permissions.triage ?? raw.permissions.push,
|
|
470
|
-
pull: raw.permissions.pull
|
|
471
|
-
} : void 0,
|
|
472
|
-
raw
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
function toReactions(raw) {
|
|
476
|
-
if (!raw) return;
|
|
477
|
-
const counts = Object.fromEntries(REACTION_CONTENTS.flatMap((name) => raw[name] ? [[name, raw[name]]] : []));
|
|
478
|
-
return {
|
|
479
|
-
total: raw.total_count ?? Object.values(counts).reduce((sum, count) => sum + count, 0),
|
|
480
|
-
counts
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
function toMilestone(raw) {
|
|
484
|
-
return raw ? {
|
|
485
|
-
id: String(raw.number ?? raw.id ?? ""),
|
|
486
|
-
title: raw.title,
|
|
487
|
-
state: raw.state === "closed" ? "closed" : "open",
|
|
488
|
-
description: raw.description ?? void 0,
|
|
489
|
-
dueOn: toDate(raw.due_on),
|
|
490
|
-
url: raw.html_url,
|
|
491
|
-
raw
|
|
492
|
-
} : void 0;
|
|
493
|
-
}
|
|
494
|
-
function toIssueType(raw) {
|
|
495
|
-
return raw ? {
|
|
496
|
-
id: raw.node_id,
|
|
497
|
-
name: raw.name,
|
|
498
|
-
description: raw.description || void 0,
|
|
499
|
-
colour: raw.color ?? void 0,
|
|
500
|
-
enabled: raw.is_enabled,
|
|
501
|
-
raw
|
|
502
|
-
} : void 0;
|
|
503
|
-
}
|
|
504
|
-
/** GitHub's `role_name`, or the permission block when a listing reports only that. */
|
|
505
|
-
function toRole(raw) {
|
|
506
|
-
switch (raw.role_name) {
|
|
507
|
-
case "admin":
|
|
508
|
-
case "maintain":
|
|
509
|
-
case "write":
|
|
510
|
-
case "triage":
|
|
511
|
-
case "read": return raw.role_name;
|
|
512
|
-
}
|
|
513
|
-
const permissions = raw.permissions;
|
|
514
|
-
if (!permissions) return "none";
|
|
515
|
-
return permissions.admin ? "admin" : permissions.maintain ? "maintain" : permissions.push ? "write" : permissions.triage ? "triage" : permissions.pull ? "read" : "none";
|
|
516
|
-
}
|
|
517
|
-
function toCollaborator(instance, raw) {
|
|
518
|
-
return {
|
|
519
|
-
actor: toActor(instance, raw),
|
|
520
|
-
role: toRole(raw),
|
|
521
|
-
roleRaw: raw.role_name,
|
|
522
|
-
raw
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
function toContributor(instance, raw) {
|
|
526
|
-
if (!("login" in raw)) return {
|
|
527
|
-
name: raw.name || void 0,
|
|
528
|
-
email: raw.email || void 0,
|
|
529
|
-
contributions: raw.contributions,
|
|
530
|
-
raw
|
|
531
|
-
};
|
|
532
|
-
return {
|
|
533
|
-
actor: toActor(instance, raw),
|
|
534
|
-
contributions: raw.contributions,
|
|
535
|
-
raw
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
function toContributorStats(instance, raw) {
|
|
539
|
-
return {
|
|
540
|
-
actor: toActor(instance, raw.author),
|
|
541
|
-
commits: raw.total,
|
|
542
|
-
weeks: raw.weeks.map((week) => ({
|
|
543
|
-
week: /* @__PURE__ */ new Date(week.w * 1e3),
|
|
544
|
-
additions: week.a ?? 0,
|
|
545
|
-
deletions: week.d ?? 0,
|
|
546
|
-
commits: week.c ?? 0
|
|
547
|
-
})),
|
|
548
|
-
raw
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
function toTeam(instance, org, raw) {
|
|
552
|
-
const parent = raw.parent ? {
|
|
553
|
-
forge: FORGE,
|
|
554
|
-
instance,
|
|
555
|
-
org,
|
|
556
|
-
id: String(raw.parent.id),
|
|
557
|
-
slug: raw.parent.slug
|
|
558
|
-
} : void 0;
|
|
559
|
-
return {
|
|
560
|
-
ref: {
|
|
561
|
-
forge: FORGE,
|
|
562
|
-
instance,
|
|
563
|
-
org,
|
|
564
|
-
id: String(raw.id),
|
|
565
|
-
slug: raw.slug
|
|
566
|
-
},
|
|
567
|
-
name: raw.name,
|
|
568
|
-
description: raw.description ?? void 0,
|
|
569
|
-
permission: raw.permission,
|
|
570
|
-
visibilityRaw: raw.privacy,
|
|
571
|
-
parent,
|
|
572
|
-
url: raw.html_url,
|
|
573
|
-
raw
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
function toThreadKind(subjectType) {
|
|
577
|
-
switch (subjectType) {
|
|
578
|
-
case "PullRequest": return "pull_request";
|
|
579
|
-
case "Discussion": return "discussion";
|
|
580
|
-
case "Issue": return "issue";
|
|
581
|
-
default: return;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
function toThreadState(issue) {
|
|
585
|
-
if (issue.merged || issue.merged_at || issue.pull_request?.merged_at) return "merged";
|
|
586
|
-
if (issue.state === "open" || issue.state === "closed") return issue.state;
|
|
587
|
-
return "unknown";
|
|
588
|
-
}
|
|
589
|
-
function numberFromUrl(url) {
|
|
590
|
-
return /\/(?:issues|pulls|commits|discussions)\/([^/?#]+)/.exec(url ?? "")?.[1];
|
|
591
|
-
}
|
|
592
|
-
const REASONS = {
|
|
593
|
-
approval_requested: "approval_requested",
|
|
594
|
-
assign: "assigned",
|
|
595
|
-
author: "author",
|
|
596
|
-
ci_activity: "ci_activity",
|
|
597
|
-
comment: "comment",
|
|
598
|
-
invitation: "invitation",
|
|
599
|
-
manual: "manual",
|
|
600
|
-
mention: "mention",
|
|
601
|
-
review_requested: "review_requested",
|
|
602
|
-
security_alert: "security_alert",
|
|
603
|
-
security_advisory_credit: "security_alert",
|
|
604
|
-
state_change: "state_change",
|
|
605
|
-
subscribed: "subscribed",
|
|
606
|
-
team_mention: "team_mention"
|
|
607
|
-
};
|
|
608
|
-
function toReason(reason) {
|
|
609
|
-
return REASONS[reason] ?? "unknown";
|
|
610
|
-
}
|
|
611
|
-
const SECURITY_SUBJECTS = /* @__PURE__ */ new Set([
|
|
612
|
-
"RepositoryVulnerabilityAlert",
|
|
613
|
-
"RepositoryDependabotAlertsThread",
|
|
614
|
-
"SecretScanningAlert",
|
|
615
|
-
"RepositoryAdvisory"
|
|
616
|
-
]);
|
|
617
|
-
const SECURITY_SUBJECTS_KIND = {
|
|
618
|
-
RepositoryVulnerabilityAlert: "dependency",
|
|
619
|
-
RepositoryDependabotAlertsThread: "dependency",
|
|
620
|
-
SecretScanningAlert: "secret",
|
|
621
|
-
RepositoryAdvisory: "advisory"
|
|
622
|
-
};
|
|
623
|
-
function lastSegment(url) {
|
|
624
|
-
return /\/([^/?#]+)\/?$/.exec(url ?? "")?.[1];
|
|
625
|
-
}
|
|
626
|
-
function toSubject(instance, raw) {
|
|
627
|
-
const repo = toRepoRef(instance, raw.repository);
|
|
628
|
-
const type = raw.subject.type;
|
|
629
|
-
const kind = toThreadKind(type);
|
|
630
|
-
if (kind) return {
|
|
631
|
-
type: "thread",
|
|
632
|
-
thread: {
|
|
633
|
-
forge: FORGE,
|
|
634
|
-
instance,
|
|
635
|
-
repo,
|
|
636
|
-
kind,
|
|
637
|
-
typeRaw: type,
|
|
638
|
-
number: numberFromUrl(raw.subject.url)
|
|
639
|
-
}
|
|
640
|
-
};
|
|
641
|
-
const sha = type === "Commit" ? numberFromUrl(raw.subject.url) : void 0;
|
|
642
|
-
if (sha) return {
|
|
643
|
-
type: "commit",
|
|
644
|
-
commit: {
|
|
645
|
-
forge: FORGE,
|
|
646
|
-
instance,
|
|
647
|
-
repo,
|
|
648
|
-
sha
|
|
649
|
-
}
|
|
650
|
-
};
|
|
651
|
-
if (type === "Release") return {
|
|
652
|
-
type: "release",
|
|
653
|
-
release: {
|
|
654
|
-
forge: FORGE,
|
|
655
|
-
instance,
|
|
656
|
-
repo,
|
|
657
|
-
id: lastSegment(raw.subject.url) ?? raw.id
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
if (SECURITY_SUBJECTS.has(type)) {
|
|
661
|
-
const kind = SECURITY_SUBJECTS_KIND[type];
|
|
662
|
-
return {
|
|
663
|
-
type: "security_alert",
|
|
664
|
-
alert: {
|
|
665
|
-
forge: FORGE,
|
|
666
|
-
instance,
|
|
667
|
-
repo,
|
|
668
|
-
id: lastSegment(raw.subject.url) ?? raw.id,
|
|
669
|
-
...kind ? { kind } : {}
|
|
670
|
-
}
|
|
671
|
-
};
|
|
672
|
-
}
|
|
673
|
-
if (type === "RepositoryInvitation") return {
|
|
674
|
-
type: "repo",
|
|
675
|
-
repo
|
|
676
|
-
};
|
|
677
|
-
return {
|
|
678
|
-
type: "other",
|
|
679
|
-
typeRaw: type,
|
|
680
|
-
repo,
|
|
681
|
-
id: lastSegment(raw.subject.url),
|
|
682
|
-
url: raw.subject.url ?? void 0
|
|
683
|
-
};
|
|
684
|
-
}
|
|
685
|
-
function toNotification(instance, raw) {
|
|
686
|
-
const subject = toSubject(instance, raw);
|
|
687
|
-
const latestComment = latestCommentOf(subject, raw.subject.latest_comment_url);
|
|
688
|
-
return {
|
|
689
|
-
ref: {
|
|
690
|
-
forge: FORGE,
|
|
691
|
-
instance,
|
|
692
|
-
id: raw.id
|
|
693
|
-
},
|
|
694
|
-
subject,
|
|
695
|
-
subjectTypeRaw: raw.subject.type,
|
|
696
|
-
reason: toReason(raw.reason),
|
|
697
|
-
reasonRaw: raw.reason,
|
|
698
|
-
unread: raw.unread,
|
|
699
|
-
title: raw.subject.title,
|
|
700
|
-
subjectState: "unknown",
|
|
701
|
-
updatedAt: toDate(raw.updated_at) ?? /* @__PURE__ */ new Date(0),
|
|
702
|
-
lastReadAt: toDate(raw.last_read_at),
|
|
703
|
-
url: raw.subject.url ?? raw.url,
|
|
704
|
-
...latestComment ? { latestComment } : {},
|
|
705
|
-
raw
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
function toLabel(raw) {
|
|
709
|
-
return {
|
|
710
|
-
name: raw.name,
|
|
711
|
-
colour: raw.color ?? void 0,
|
|
712
|
-
description: raw.description ?? void 0
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
function toLabels(labels) {
|
|
716
|
-
return (labels ?? []).flatMap((label) => {
|
|
717
|
-
if (typeof label === "string") return [{ name: label }];
|
|
718
|
-
return label.name ? [{
|
|
719
|
-
name: label.name,
|
|
720
|
-
colour: label.color ?? void 0,
|
|
721
|
-
description: label.description ?? void 0
|
|
722
|
-
}] : [];
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
function toReviewers(instance, raw) {
|
|
726
|
-
const users = (raw.requested_reviewers ?? []).flatMap((user) => {
|
|
727
|
-
const actor = toActor(instance, user);
|
|
728
|
-
return actor ? [{
|
|
729
|
-
actor,
|
|
730
|
-
state: "pending",
|
|
731
|
-
stateRaw: "requested"
|
|
732
|
-
}] : [];
|
|
733
|
-
});
|
|
734
|
-
const teams = (raw.requested_teams ?? []).map((team) => ({
|
|
735
|
-
actor: {
|
|
736
|
-
forge: FORGE,
|
|
737
|
-
instance,
|
|
738
|
-
login: team.slug,
|
|
739
|
-
id: String(team.id),
|
|
740
|
-
name: team.name,
|
|
741
|
-
url: team.html_url,
|
|
742
|
-
typeRaw: "Team",
|
|
743
|
-
isBotHint: false
|
|
744
|
-
},
|
|
745
|
-
state: "pending",
|
|
746
|
-
stateRaw: "requested",
|
|
747
|
-
isTeam: true
|
|
748
|
-
}));
|
|
749
|
-
return [...users, ...teams];
|
|
750
|
-
}
|
|
751
|
-
/** Builds a thread from an issue, a pull request, or a pull request as returned by the issues API. */
|
|
752
|
-
function toThread(ref, raw) {
|
|
753
|
-
const kind = raw.pull_request || raw.head ? "pull_request" : ref.kind;
|
|
754
|
-
return {
|
|
755
|
-
ref: {
|
|
756
|
-
...ref,
|
|
757
|
-
kind,
|
|
758
|
-
externalId: raw.node_id ?? ref.externalId
|
|
759
|
-
},
|
|
760
|
-
kind,
|
|
761
|
-
title: raw.title,
|
|
762
|
-
body: raw.body ?? void 0,
|
|
763
|
-
state: toThreadState(raw),
|
|
764
|
-
stateRaw: raw.state,
|
|
765
|
-
stateReason: raw.state_reason ?? void 0,
|
|
766
|
-
isDraft: raw.draft ?? false,
|
|
767
|
-
author: toActor(ref.instance, raw.user),
|
|
768
|
-
...toAuthorAssociation(raw.author_association),
|
|
769
|
-
assignees: (raw.assignees ?? []).flatMap((user) => toActor(ref.instance, user) ?? []),
|
|
770
|
-
reviewers: toReviewers(ref.instance, raw),
|
|
771
|
-
labels: toLabels(raw.labels),
|
|
772
|
-
url: raw.html_url,
|
|
773
|
-
createdAt: toDate(raw.created_at),
|
|
774
|
-
updatedAt: toDate(raw.updated_at),
|
|
775
|
-
closedAt: toDate(raw.closed_at),
|
|
776
|
-
mergedAt: toDate(raw.merged_at ?? raw.pull_request?.merged_at),
|
|
777
|
-
mergedBy: toActor(ref.instance, raw.merged_by),
|
|
778
|
-
lastActivityAt: toDate(raw.updated_at),
|
|
779
|
-
locked: raw.locked,
|
|
780
|
-
commentCount: raw.comments,
|
|
781
|
-
milestone: toMilestone(raw.milestone),
|
|
782
|
-
issueType: toIssueType(raw.type),
|
|
783
|
-
reactions: toReactions(raw.reactions),
|
|
784
|
-
branches: raw.head && raw.base ? {
|
|
785
|
-
head: {
|
|
786
|
-
ref: raw.head.ref,
|
|
787
|
-
sha: raw.head.sha,
|
|
788
|
-
repo: raw.head.repo ? toRepoRef(ref.instance, raw.head.repo) : void 0
|
|
789
|
-
},
|
|
790
|
-
base: {
|
|
791
|
-
ref: raw.base.ref,
|
|
792
|
-
sha: raw.base.sha
|
|
793
|
-
},
|
|
794
|
-
mergeCommitSha: raw.merge_commit_sha ?? void 0
|
|
795
|
-
} : void 0,
|
|
796
|
-
stats: toPullStats({
|
|
797
|
-
additions: raw.additions,
|
|
798
|
-
deletions: raw.deletions,
|
|
799
|
-
changedFileCount: raw.changed_files,
|
|
800
|
-
commitCount: raw.commits
|
|
801
|
-
}),
|
|
802
|
-
raw
|
|
803
|
-
};
|
|
804
|
-
}
|
|
805
|
-
function toComment(thread, raw) {
|
|
806
|
-
return {
|
|
807
|
-
ref: {
|
|
808
|
-
forge: FORGE,
|
|
809
|
-
instance: thread.instance,
|
|
810
|
-
thread,
|
|
811
|
-
id: String(raw.id)
|
|
812
|
-
},
|
|
813
|
-
...commentFields(thread.instance, raw)
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
function toCommitComment(commit, raw) {
|
|
817
|
-
return {
|
|
818
|
-
ref: {
|
|
819
|
-
forge: FORGE,
|
|
820
|
-
instance: commit.instance,
|
|
821
|
-
commit,
|
|
822
|
-
id: String(raw.id)
|
|
823
|
-
},
|
|
824
|
-
...commentFields(commit.instance, raw)
|
|
825
|
-
};
|
|
826
|
-
}
|
|
827
|
-
function commentFields(instance, raw) {
|
|
828
|
-
return {
|
|
829
|
-
body: raw.body ?? "",
|
|
830
|
-
author: toActor(instance, raw.user),
|
|
831
|
-
...toAuthorAssociation(raw.author_association),
|
|
832
|
-
createdAt: toDate(raw.created_at),
|
|
833
|
-
updatedAt: toDate(raw.updated_at),
|
|
834
|
-
url: raw.html_url,
|
|
835
|
-
reactions: toReactions(raw.reactions),
|
|
836
|
-
raw
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
const EVENT_KINDS = {
|
|
840
|
-
"commented": "comment",
|
|
841
|
-
"reviewed": "review",
|
|
842
|
-
"line_commented": "review_comment",
|
|
843
|
-
"review_requested": "assignment",
|
|
844
|
-
"review_request_removed": "assignment",
|
|
845
|
-
"committed": "commit",
|
|
846
|
-
"labeled": "label",
|
|
847
|
-
"unlabeled": "label",
|
|
848
|
-
"closed": "state_change",
|
|
849
|
-
"reopened": "state_change",
|
|
850
|
-
"merged": "state_change",
|
|
851
|
-
"convert_to_draft": "state_change",
|
|
852
|
-
"ready_for_review": "state_change",
|
|
853
|
-
"assigned": "assignment",
|
|
854
|
-
"unassigned": "assignment",
|
|
855
|
-
"mentioned": "mention",
|
|
856
|
-
"cross-referenced": "referenced",
|
|
857
|
-
"referenced": "referenced",
|
|
858
|
-
"reaction": "reaction"
|
|
859
|
-
};
|
|
860
|
-
function toEventKind(event) {
|
|
861
|
-
return EVENT_KINDS[event ?? ""] ?? "other";
|
|
862
|
-
}
|
|
863
|
-
function summarise(entry, kind, actor) {
|
|
864
|
-
const who = actor?.login ?? "someone";
|
|
865
|
-
switch (kind) {
|
|
866
|
-
case "comment": return `${who} commented`;
|
|
867
|
-
case "review": return `${who} reviewed (${entry.state ?? "commented"})`;
|
|
868
|
-
case "review_comment": return `${who} commented on a line`;
|
|
869
|
-
case "commit": return `${entry.author?.name ?? who} committed ${entry.sha?.slice(0, 7) ?? "a commit"}`;
|
|
870
|
-
case "label": return `${who} ${entry.event === "unlabeled" ? "removed" : "added"} label ${entry.label?.name ?? ""}`.trim();
|
|
871
|
-
case "state_change": return `${who} ${entry.event ?? "changed state"}`;
|
|
872
|
-
case "referenced": return `${who} referenced this`;
|
|
873
|
-
case "assignment":
|
|
874
|
-
if (entry.event === "review_requested" || entry.event === "review_request_removed") return `${who} ${entry.event === "review_requested" ? "requested review from" : "removed the review request for"} ${entry.requested_reviewer?.login ?? ""}`.trim();
|
|
875
|
-
return `${who} ${entry.event === "unassigned" ? "unassigned" : "assigned"} ${entry.assignee?.login ?? ""}`.trim();
|
|
876
|
-
default: return `${who} ${entry.event ?? "acted"}`;
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
/** A `cross-referenced` entry names the thread that mentioned this one; a `referenced` entry names a commit. */
|
|
880
|
-
function crossReference(instance, thread, entry) {
|
|
881
|
-
const source = entry.source?.issue;
|
|
882
|
-
if (source) {
|
|
883
|
-
const repo = source.repository ? toRepoRef(instance, source.repository) : thread.repo;
|
|
884
|
-
return {
|
|
885
|
-
type: "referenced",
|
|
886
|
-
from: {
|
|
887
|
-
forge: FORGE,
|
|
888
|
-
instance,
|
|
889
|
-
repo,
|
|
890
|
-
kind: source.pull_request ? "pull_request" : "issue",
|
|
891
|
-
number: String(source.number)
|
|
892
|
-
},
|
|
893
|
-
fromRepo: repo
|
|
894
|
-
};
|
|
895
|
-
}
|
|
896
|
-
return entry.commit_id ? {
|
|
897
|
-
type: "referenced",
|
|
898
|
-
from: {
|
|
899
|
-
forge: FORGE,
|
|
900
|
-
instance,
|
|
901
|
-
repo: thread.repo,
|
|
902
|
-
sha: entry.commit_id
|
|
903
|
-
},
|
|
904
|
-
fromRepo: thread.repo
|
|
905
|
-
} : { type: "referenced" };
|
|
906
|
-
}
|
|
907
|
-
function timelineDetail(instance, thread, entry, kind) {
|
|
908
|
-
switch (kind) {
|
|
909
|
-
case "comment": return {
|
|
910
|
-
type: "comment",
|
|
911
|
-
comment: entry.id !== void 0 ? {
|
|
912
|
-
forge: FORGE,
|
|
913
|
-
instance,
|
|
914
|
-
thread,
|
|
915
|
-
id: String(entry.id)
|
|
916
|
-
} : void 0,
|
|
917
|
-
body: entry.body ?? void 0
|
|
918
|
-
};
|
|
919
|
-
case "review": return {
|
|
920
|
-
type: "review",
|
|
921
|
-
state: reviewState(entry.state),
|
|
922
|
-
stateRaw: entry.state,
|
|
923
|
-
body: entry.body ?? void 0,
|
|
924
|
-
review: entry.id !== void 0 ? {
|
|
925
|
-
forge: FORGE,
|
|
926
|
-
instance,
|
|
927
|
-
thread,
|
|
928
|
-
id: String(entry.id)
|
|
929
|
-
} : void 0
|
|
930
|
-
};
|
|
931
|
-
case "label": return entry.label ? {
|
|
932
|
-
type: "label",
|
|
933
|
-
label: entry.label.name
|
|
934
|
-
} : void 0;
|
|
935
|
-
case "assignment": return {
|
|
936
|
-
type: "assignment",
|
|
937
|
-
assignee: toActor(instance, entry.assignee ?? entry.requested_reviewer)
|
|
938
|
-
};
|
|
939
|
-
case "referenced": return crossReference(instance, thread, entry);
|
|
940
|
-
case "state_change": return entry.event === "convert_to_draft" || entry.event === "ready_for_review" ? {
|
|
941
|
-
type: "state_change",
|
|
942
|
-
state: "open",
|
|
943
|
-
draft: entry.event === "convert_to_draft"
|
|
944
|
-
} : {
|
|
945
|
-
type: "state_change",
|
|
946
|
-
state: entry.event === "merged" ? "merged" : entry.event === "closed" ? "closed" : "open",
|
|
947
|
-
reason: entry.state_reason ?? void 0
|
|
948
|
-
};
|
|
949
|
-
default: return;
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
function toEvent(instance, thread, entry, source = "poll") {
|
|
953
|
-
const kind = toEventKind(entry.event);
|
|
954
|
-
const actor = toActor(instance, entry.actor ?? entry.user);
|
|
955
|
-
return {
|
|
956
|
-
forge: FORGE,
|
|
957
|
-
instance,
|
|
958
|
-
id: String(entry.node_id ?? entry.id ?? entry.sha ?? `${thread.number ?? ""}-${entry.event}-${entry.created_at}`),
|
|
959
|
-
kind,
|
|
960
|
-
kindRaw: entry.event,
|
|
961
|
-
detail: timelineDetail(instance, thread, entry, kind),
|
|
962
|
-
summary: summarise(entry, kind, actor),
|
|
963
|
-
...eventTime(toDate(entry.created_at ?? entry.submitted_at ?? entry.author?.date ?? entry.committer?.date), /* @__PURE__ */ new Date(0)),
|
|
964
|
-
actor,
|
|
965
|
-
repo: thread.repo,
|
|
966
|
-
thread,
|
|
967
|
-
source,
|
|
968
|
-
payload: entry
|
|
969
|
-
};
|
|
970
|
-
}
|
|
971
|
-
function statusState(state) {
|
|
972
|
-
return state === "success" ? "success" : state === "pending" ? "pending" : state === "failure" || state === "error" ? "failure" : "unknown";
|
|
973
|
-
}
|
|
974
|
-
const ACTIONS_JOB_URL = /\/actions\/runs\/(\d+)\/job\/\d+$/;
|
|
975
|
-
function toCheckRun(repo, raw) {
|
|
976
|
-
const runId = raw.html_url?.match(ACTIONS_JOB_URL)?.[1];
|
|
977
|
-
return {
|
|
978
|
-
ref: {
|
|
979
|
-
forge: FORGE,
|
|
980
|
-
instance: repo.instance,
|
|
981
|
-
repo,
|
|
982
|
-
id: String(raw.id),
|
|
983
|
-
type: "check_run",
|
|
984
|
-
...raw.app?.slug ? { app: raw.app.slug } : {}
|
|
985
|
-
},
|
|
986
|
-
name: raw.name,
|
|
987
|
-
state: checkRunState(raw.status, raw.conclusion),
|
|
988
|
-
stateRaw: raw.status,
|
|
989
|
-
conclusionRaw: raw.conclusion ?? void 0,
|
|
990
|
-
url: raw.html_url ?? raw.details_url ?? void 0,
|
|
991
|
-
startedAt: toDate(raw.started_at),
|
|
992
|
-
completedAt: toDate(raw.completed_at),
|
|
993
|
-
...runId ? { run: {
|
|
994
|
-
forge: FORGE,
|
|
995
|
-
instance: repo.instance,
|
|
996
|
-
repo,
|
|
997
|
-
id: runId
|
|
998
|
-
} } : {},
|
|
999
|
-
raw
|
|
1000
|
-
};
|
|
1001
|
-
}
|
|
1002
|
-
function toStatusCheck(repo, raw) {
|
|
1003
|
-
const state = statusState(raw.state);
|
|
1004
|
-
return {
|
|
1005
|
-
ref: {
|
|
1006
|
-
forge: FORGE,
|
|
1007
|
-
instance: repo.instance,
|
|
1008
|
-
repo,
|
|
1009
|
-
id: String(raw.id),
|
|
1010
|
-
type: "status"
|
|
1011
|
-
},
|
|
1012
|
-
name: raw.context,
|
|
1013
|
-
state,
|
|
1014
|
-
stateRaw: raw.state,
|
|
1015
|
-
url: raw.target_url ?? void 0,
|
|
1016
|
-
startedAt: toDate(raw.created_at),
|
|
1017
|
-
completedAt: state === "pending" ? void 0 : toDate(raw.updated_at),
|
|
1018
|
-
raw
|
|
1019
|
-
};
|
|
1020
|
-
}
|
|
1021
|
-
function toRelease(repo, raw) {
|
|
1022
|
-
const ref = {
|
|
1023
|
-
forge: FORGE,
|
|
1024
|
-
instance: repo.instance,
|
|
1025
|
-
repo,
|
|
1026
|
-
id: String(raw.id),
|
|
1027
|
-
tag: raw.tag_name
|
|
1028
|
-
};
|
|
1029
|
-
return {
|
|
1030
|
-
ref,
|
|
1031
|
-
name: raw.name ?? void 0,
|
|
1032
|
-
tag: raw.tag_name,
|
|
1033
|
-
body: raw.body ?? void 0,
|
|
1034
|
-
isDraft: raw.draft,
|
|
1035
|
-
isPrerelease: raw.prerelease,
|
|
1036
|
-
immutable: raw.immutable,
|
|
1037
|
-
author: toActor(repo.instance, raw.author),
|
|
1038
|
-
publishedAt: toDate(raw.published_at),
|
|
1039
|
-
createdAt: toDate(raw.created_at),
|
|
1040
|
-
url: raw.html_url,
|
|
1041
|
-
assets: raw.assets?.map((asset) => ({
|
|
1042
|
-
...asset.id === void 0 ? {} : { ref: {
|
|
1043
|
-
forge: FORGE,
|
|
1044
|
-
instance: repo.instance,
|
|
1045
|
-
repo,
|
|
1046
|
-
release: ref,
|
|
1047
|
-
id: String(asset.id)
|
|
1048
|
-
} },
|
|
1049
|
-
name: asset.name,
|
|
1050
|
-
url: asset.browser_download_url,
|
|
1051
|
-
size: asset.size,
|
|
1052
|
-
downloadCount: asset.download_count,
|
|
1053
|
-
contentType: asset.content_type
|
|
1054
|
-
})),
|
|
1055
|
-
raw
|
|
1056
|
-
};
|
|
1057
|
-
}
|
|
1058
|
-
function toSeverity(raw) {
|
|
1059
|
-
switch (raw?.toLowerCase()) {
|
|
1060
|
-
case "critical": return "critical";
|
|
1061
|
-
case "high":
|
|
1062
|
-
case "error": return "high";
|
|
1063
|
-
case "medium":
|
|
1064
|
-
case "moderate":
|
|
1065
|
-
case "warning": return "medium";
|
|
1066
|
-
case "low":
|
|
1067
|
-
case "note": return "low";
|
|
1068
|
-
default: return "unknown";
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
function alertState(raw) {
|
|
1072
|
-
return raw === "open" ? "open" : raw === "fixed" ? "fixed" : raw === "dismissed" || raw === "auto_dismissed" ? "dismissed" : "unknown";
|
|
1073
|
-
}
|
|
1074
|
-
function toDependabotAlert(repo, raw) {
|
|
1075
|
-
const severityRaw = raw.security_vulnerability?.severity ?? raw.security_advisory?.severity;
|
|
1076
|
-
const pkg = raw.dependency?.package;
|
|
1077
|
-
return {
|
|
1078
|
-
ref: {
|
|
1079
|
-
forge: FORGE,
|
|
1080
|
-
instance: repo.instance,
|
|
1081
|
-
repo,
|
|
1082
|
-
id: String(raw.number),
|
|
1083
|
-
kind: "dependency",
|
|
1084
|
-
severityRaw
|
|
1085
|
-
},
|
|
1086
|
-
kind: "dependency",
|
|
1087
|
-
kindRaw: "dependabot",
|
|
1088
|
-
severity: toSeverity(severityRaw),
|
|
1089
|
-
severityRaw,
|
|
1090
|
-
state: alertState(raw.state),
|
|
1091
|
-
stateRaw: raw.state,
|
|
1092
|
-
title: raw.security_advisory?.summary ?? `Vulnerable dependency ${pkg?.name ?? ""}`.trim(),
|
|
1093
|
-
...pkg ? { package: {
|
|
1094
|
-
ecosystem: pkg.ecosystem,
|
|
1095
|
-
name: pkg.name,
|
|
1096
|
-
vulnerableRange: raw.security_vulnerability?.vulnerable_version_range,
|
|
1097
|
-
fixedIn: raw.security_vulnerability?.first_patched_version?.identifier
|
|
1098
|
-
} } : {},
|
|
1099
|
-
url: raw.html_url,
|
|
1100
|
-
createdAt: toDate(raw.created_at),
|
|
1101
|
-
updatedAt: toDate(raw.updated_at),
|
|
1102
|
-
dismissedAt: toDate(raw.dismissed_at),
|
|
1103
|
-
raw
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
function toCodeScanningAlert(repo, raw) {
|
|
1107
|
-
const severityRaw = raw.rule?.security_severity_level ?? raw.rule?.severity ?? void 0;
|
|
1108
|
-
return {
|
|
1109
|
-
ref: {
|
|
1110
|
-
forge: FORGE,
|
|
1111
|
-
instance: repo.instance,
|
|
1112
|
-
repo,
|
|
1113
|
-
id: String(raw.number),
|
|
1114
|
-
kind: "code_scanning",
|
|
1115
|
-
severityRaw
|
|
1116
|
-
},
|
|
1117
|
-
kind: "code_scanning",
|
|
1118
|
-
kindRaw: raw.tool?.name ?? "code_scanning",
|
|
1119
|
-
severity: toSeverity(severityRaw),
|
|
1120
|
-
severityRaw,
|
|
1121
|
-
state: alertState(raw.state),
|
|
1122
|
-
stateRaw: raw.state,
|
|
1123
|
-
title: raw.rule?.description ?? raw.rule?.name ?? raw.rule?.id ?? "Code scanning alert",
|
|
1124
|
-
url: raw.html_url,
|
|
1125
|
-
createdAt: toDate(raw.created_at),
|
|
1126
|
-
updatedAt: toDate(raw.updated_at),
|
|
1127
|
-
dismissedAt: toDate(raw.dismissed_at),
|
|
1128
|
-
raw
|
|
1129
|
-
};
|
|
1130
|
-
}
|
|
1131
|
-
/** Secret scanning reports no severity. A revoked secret is fixed; any other resolution dismisses the alert. */
|
|
1132
|
-
function toSecretScanningAlert(repo, raw) {
|
|
1133
|
-
const state = raw.state === "open" ? "open" : raw.state === "resolved" ? raw.resolution === "revoked" ? "fixed" : "dismissed" : "unknown";
|
|
1134
|
-
return {
|
|
1135
|
-
ref: {
|
|
1136
|
-
forge: FORGE,
|
|
1137
|
-
instance: repo.instance,
|
|
1138
|
-
repo,
|
|
1139
|
-
id: String(raw.number),
|
|
1140
|
-
kind: "secret"
|
|
1141
|
-
},
|
|
1142
|
-
kind: "secret",
|
|
1143
|
-
kindRaw: raw.secret_type ?? "secret_scanning",
|
|
1144
|
-
severity: "unknown",
|
|
1145
|
-
state,
|
|
1146
|
-
stateRaw: raw.resolution ? `${raw.state}:${raw.resolution}` : raw.state,
|
|
1147
|
-
title: raw.secret_type_display_name ?? raw.secret_type ?? "Secret scanning alert",
|
|
1148
|
-
url: raw.html_url,
|
|
1149
|
-
createdAt: toDate(raw.created_at),
|
|
1150
|
-
updatedAt: toDate(raw.updated_at),
|
|
1151
|
-
dismissedAt: state === "dismissed" ? toDate(raw.resolved_at) : void 0,
|
|
1152
|
-
raw
|
|
1153
|
-
};
|
|
1154
|
-
}
|
|
1155
|
-
/** A private vulnerability report in triage, or a draft, is open; a published advisory is fixed; a closed or withdrawn one is dismissed. */
|
|
1156
|
-
function toRepositoryAdvisory(repo, raw) {
|
|
1157
|
-
const state = raw.state === "triage" || raw.state === "draft" ? "open" : raw.state === "published" ? "fixed" : raw.state === "closed" || raw.state === "withdrawn" ? "dismissed" : "unknown";
|
|
1158
|
-
const severityRaw = raw.severity ?? void 0;
|
|
1159
|
-
const vulnerability = raw.vulnerabilities?.find((item) => item.package?.name);
|
|
1160
|
-
return {
|
|
1161
|
-
ref: {
|
|
1162
|
-
forge: FORGE,
|
|
1163
|
-
instance: repo.instance,
|
|
1164
|
-
repo,
|
|
1165
|
-
id: raw.ghsa_id,
|
|
1166
|
-
kind: "advisory",
|
|
1167
|
-
severityRaw
|
|
1168
|
-
},
|
|
1169
|
-
kind: "advisory",
|
|
1170
|
-
kindRaw: "repository_advisory",
|
|
1171
|
-
severity: toSeverity(severityRaw),
|
|
1172
|
-
severityRaw,
|
|
1173
|
-
state,
|
|
1174
|
-
stateRaw: raw.state,
|
|
1175
|
-
title: raw.summary,
|
|
1176
|
-
...vulnerability?.package?.name ? { package: {
|
|
1177
|
-
ecosystem: vulnerability.package.ecosystem,
|
|
1178
|
-
name: vulnerability.package.name,
|
|
1179
|
-
vulnerableRange: vulnerability.vulnerable_version_range ?? void 0,
|
|
1180
|
-
fixedIn: vulnerability.patched_versions ?? void 0
|
|
1181
|
-
} } : {},
|
|
1182
|
-
url: raw.html_url,
|
|
1183
|
-
createdAt: toDate(raw.created_at),
|
|
1184
|
-
updatedAt: toDate(raw.updated_at),
|
|
1185
|
-
dismissedAt: state === "dismissed" ? toDate(raw.withdrawn_at ?? raw.closed_at) : void 0,
|
|
1186
|
-
raw
|
|
1187
|
-
};
|
|
1188
|
-
}
|
|
1189
|
-
function toReviewComment(thread, raw, reviewThread) {
|
|
1190
|
-
return {
|
|
1191
|
-
ref: {
|
|
1192
|
-
forge: FORGE,
|
|
1193
|
-
instance: thread.instance,
|
|
1194
|
-
thread,
|
|
1195
|
-
id: String(raw.id)
|
|
1196
|
-
},
|
|
1197
|
-
body: raw.body ?? "",
|
|
1198
|
-
author: toActor(thread.instance, raw.user),
|
|
1199
|
-
path: raw.path,
|
|
1200
|
-
line: raw.line ?? raw.original_line ?? void 0,
|
|
1201
|
-
side: raw.side?.toLowerCase() === "left" ? "left" : raw.side ? "right" : void 0,
|
|
1202
|
-
inReplyTo: raw.in_reply_to_id === null || raw.in_reply_to_id === void 0 ? void 0 : String(raw.in_reply_to_id),
|
|
1203
|
-
thread: reviewThread,
|
|
1204
|
-
createdAt: toDate(raw.created_at),
|
|
1205
|
-
url: raw.html_url,
|
|
1206
|
-
raw
|
|
1207
|
-
};
|
|
1208
|
-
}
|
|
1209
|
-
function toReview(thread, raw, comments) {
|
|
1210
|
-
return {
|
|
1211
|
-
ref: {
|
|
1212
|
-
forge: FORGE,
|
|
1213
|
-
instance: thread.instance,
|
|
1214
|
-
thread,
|
|
1215
|
-
id: String(raw.id)
|
|
1216
|
-
},
|
|
1217
|
-
author: toActor(thread.instance, raw.user),
|
|
1218
|
-
state: reviewState(raw.state),
|
|
1219
|
-
stateRaw: raw.state,
|
|
1220
|
-
body: raw.body || void 0,
|
|
1221
|
-
submittedAt: toDate(raw.submitted_at ?? void 0),
|
|
1222
|
-
comments,
|
|
1223
|
-
url: raw.html_url,
|
|
1224
|
-
raw
|
|
1225
|
-
};
|
|
1226
|
-
}
|
|
1227
|
-
function toWorkflowRun(repo, raw) {
|
|
1228
|
-
return {
|
|
1229
|
-
ref: {
|
|
1230
|
-
forge: FORGE,
|
|
1231
|
-
instance: repo.instance,
|
|
1232
|
-
repo,
|
|
1233
|
-
id: String(raw.id)
|
|
1234
|
-
},
|
|
1235
|
-
name: raw.name || raw.display_title || String(raw.id),
|
|
1236
|
-
state: checkRunState(raw.status ?? "queued", raw.conclusion),
|
|
1237
|
-
stateRaw: raw.status ?? "unknown",
|
|
1238
|
-
number: raw.run_number === void 0 ? void 0 : String(raw.run_number),
|
|
1239
|
-
eventRaw: raw.event,
|
|
1240
|
-
branch: raw.head_branch ?? void 0,
|
|
1241
|
-
sha: raw.head_sha,
|
|
1242
|
-
url: raw.html_url,
|
|
1243
|
-
actor: toActor(repo.instance, raw.actor),
|
|
1244
|
-
createdAt: toDate(raw.created_at),
|
|
1245
|
-
startedAt: toDate(raw.run_started_at),
|
|
1246
|
-
completedAt: raw.status === "completed" ? toDate(raw.updated_at) : void 0,
|
|
1247
|
-
raw
|
|
1248
|
-
};
|
|
1249
|
-
}
|
|
1250
|
-
function toWorkflowJob(run, raw) {
|
|
1251
|
-
return {
|
|
1252
|
-
ref: {
|
|
1253
|
-
forge: FORGE,
|
|
1254
|
-
instance: run.instance,
|
|
1255
|
-
repo: run.repo,
|
|
1256
|
-
id: String(raw.id),
|
|
1257
|
-
run
|
|
1258
|
-
},
|
|
1259
|
-
name: raw.name,
|
|
1260
|
-
state: checkRunState(raw.status ?? "queued", raw.conclusion),
|
|
1261
|
-
stateRaw: raw.status ?? "unknown",
|
|
1262
|
-
url: raw.html_url ?? void 0,
|
|
1263
|
-
startedAt: toDate(raw.started_at),
|
|
1264
|
-
completedAt: toDate(raw.completed_at),
|
|
1265
|
-
raw
|
|
1266
|
-
};
|
|
1267
|
-
}
|
|
1268
|
-
function toChangedFile(raw) {
|
|
1269
|
-
return {
|
|
1270
|
-
path: raw.filename,
|
|
1271
|
-
previousPath: raw.previous_filename,
|
|
1272
|
-
status: toFileStatus(raw.status),
|
|
1273
|
-
statusRaw: raw.status,
|
|
1274
|
-
additions: raw.additions,
|
|
1275
|
-
deletions: raw.deletions,
|
|
1276
|
-
patch: raw.patch,
|
|
1277
|
-
sha: raw.sha
|
|
1278
|
-
};
|
|
1279
|
-
}
|
|
1280
|
-
function toCommit(repo, raw) {
|
|
1281
|
-
return {
|
|
1282
|
-
ref: {
|
|
1283
|
-
forge: FORGE,
|
|
1284
|
-
instance: repo.instance,
|
|
1285
|
-
repo,
|
|
1286
|
-
sha: raw.sha
|
|
1287
|
-
},
|
|
1288
|
-
sha: raw.sha,
|
|
1289
|
-
message: raw.commit.message,
|
|
1290
|
-
author: {
|
|
1291
|
-
actor: toActor(repo.instance, raw.author),
|
|
1292
|
-
name: raw.commit.author?.name,
|
|
1293
|
-
email: raw.commit.author?.email,
|
|
1294
|
-
date: toDate(raw.commit.author?.date)
|
|
1295
|
-
},
|
|
1296
|
-
committer: {
|
|
1297
|
-
actor: toActor(repo.instance, raw.committer),
|
|
1298
|
-
name: raw.commit.committer?.name,
|
|
1299
|
-
email: raw.commit.committer?.email,
|
|
1300
|
-
date: toDate(raw.commit.committer?.date)
|
|
1301
|
-
},
|
|
1302
|
-
parents: raw.parents?.map((parent) => parent.sha) ?? [],
|
|
1303
|
-
url: raw.html_url,
|
|
1304
|
-
...raw.stats ? { stats: {
|
|
1305
|
-
additions: raw.stats.additions ?? 0,
|
|
1306
|
-
deletions: raw.stats.deletions ?? 0,
|
|
1307
|
-
total: raw.stats.total
|
|
1308
|
-
} } : {},
|
|
1309
|
-
...raw.files ? { files: raw.files.map(toChangedFile) } : {},
|
|
1310
|
-
raw
|
|
1311
|
-
};
|
|
1312
|
-
}
|
|
1313
|
-
/** A commit from the Git database API, which matches no accounts. */
|
|
1314
|
-
function toGitCommit(repo, raw) {
|
|
1315
|
-
return {
|
|
1316
|
-
ref: {
|
|
1317
|
-
forge: FORGE,
|
|
1318
|
-
instance: repo.instance,
|
|
1319
|
-
repo,
|
|
1320
|
-
sha: raw.sha
|
|
1321
|
-
},
|
|
1322
|
-
sha: raw.sha,
|
|
1323
|
-
message: raw.message,
|
|
1324
|
-
author: {
|
|
1325
|
-
name: raw.author?.name,
|
|
1326
|
-
email: raw.author?.email,
|
|
1327
|
-
date: toDate(raw.author?.date)
|
|
1328
|
-
},
|
|
1329
|
-
committer: {
|
|
1330
|
-
name: raw.committer?.name,
|
|
1331
|
-
email: raw.committer?.email,
|
|
1332
|
-
date: toDate(raw.committer?.date)
|
|
1333
|
-
},
|
|
1334
|
-
parents: raw.parents?.map((parent) => parent.sha) ?? [],
|
|
1335
|
-
url: raw.html_url,
|
|
1336
|
-
raw
|
|
1337
|
-
};
|
|
1338
|
-
}
|
|
1339
|
-
function toBranch(raw, defaultBranch) {
|
|
1340
|
-
return {
|
|
1341
|
-
name: raw.name,
|
|
1342
|
-
sha: raw.commit.sha,
|
|
1343
|
-
isDefault: defaultBranch === void 0 ? void 0 : raw.name === defaultBranch,
|
|
1344
|
-
isProtected: raw.protected,
|
|
1345
|
-
raw
|
|
1346
|
-
};
|
|
1347
|
-
}
|
|
1348
|
-
/** Merges rulesets with classic protection; `protection` is undefined when it's off or only an admin could read it. */
|
|
1349
|
-
function toBranchRules(branch, rules, protection, warnings) {
|
|
1350
|
-
const checks = /* @__PURE__ */ new Map();
|
|
1351
|
-
const add = (name, appId) => {
|
|
1352
|
-
const check = appId == null ? { name } : {
|
|
1353
|
-
name,
|
|
1354
|
-
appId: String(appId)
|
|
1355
|
-
};
|
|
1356
|
-
checks.set(`${check.appId ?? ""}\0${name}`, check);
|
|
1357
|
-
};
|
|
1358
|
-
const approvals = [];
|
|
1359
|
-
for (const rule of rules) {
|
|
1360
|
-
if (rule.type === "required_status_checks") for (const check of rule.parameters?.required_status_checks ?? []) add(check.context, check.integration_id);
|
|
1361
|
-
if (rule.type === "pull_request") approvals.push(rule.parameters?.required_approving_review_count ?? 0);
|
|
1362
|
-
}
|
|
1363
|
-
const classic = branch.protection?.enabled ? branch.protection.required_status_checks : void 0;
|
|
1364
|
-
if (classic && classic.enforcement_level !== "off") for (const check of classic.checks?.length ? classic.checks : classic.contexts?.map((context) => ({
|
|
1365
|
-
context,
|
|
1366
|
-
app_id: void 0
|
|
1367
|
-
})) ?? []) add(check.context, check.app_id);
|
|
1368
|
-
if (protection) approvals.push(protection.required_pull_request_reviews?.required_approving_review_count ?? 0);
|
|
1369
|
-
const known = protection || !branch.protection?.enabled;
|
|
1370
|
-
const pinned = new Set([...checks.values()].filter((check) => check.appId).map((check) => check.name));
|
|
1371
|
-
return {
|
|
1372
|
-
branch: branch.name,
|
|
1373
|
-
requiredChecks: [...checks.values()].filter((check) => check.appId || !pinned.has(check.name)),
|
|
1374
|
-
requiredApprovals: known ? Math.max(0, ...approvals) : approvals.length ? Math.max(...approvals) : void 0,
|
|
1375
|
-
...warnings.length ? { warnings } : {},
|
|
1376
|
-
raw: {
|
|
1377
|
-
branch,
|
|
1378
|
-
rules,
|
|
1379
|
-
protection
|
|
1380
|
-
}
|
|
1381
|
-
};
|
|
1382
|
-
}
|
|
1383
|
-
function toTag(raw) {
|
|
1384
|
-
return {
|
|
1385
|
-
name: raw.name,
|
|
1386
|
-
sha: raw.commit.sha,
|
|
1387
|
-
raw
|
|
1388
|
-
};
|
|
1389
|
-
}
|
|
1390
|
-
const TREE_TYPES = {
|
|
1391
|
-
blob: "file",
|
|
1392
|
-
tree: "directory",
|
|
1393
|
-
commit: "submodule"
|
|
1394
|
-
};
|
|
1395
|
-
function toTreeEntry(raw) {
|
|
1396
|
-
return {
|
|
1397
|
-
path: raw.path,
|
|
1398
|
-
type: raw.mode === "120000" ? "symlink" : TREE_TYPES[raw.type ?? ""] ?? "file",
|
|
1399
|
-
sha: raw.sha,
|
|
1400
|
-
size: raw.size,
|
|
1401
|
-
mode: raw.mode
|
|
1402
|
-
};
|
|
1403
|
-
}
|
|
1404
|
-
function toWebhook(target, raw) {
|
|
1405
|
-
const nativeEvents = raw.events ?? [];
|
|
1406
|
-
return {
|
|
1407
|
-
ref: {
|
|
1408
|
-
forge: FORGE,
|
|
1409
|
-
instance: target.instance,
|
|
1410
|
-
target,
|
|
1411
|
-
id: String(raw.id)
|
|
1412
|
-
},
|
|
1413
|
-
url: raw.config?.url ?? "",
|
|
1414
|
-
events: eventKindsOf(GITHUB_NATIVE_EVENTS, nativeEvents),
|
|
1415
|
-
nativeEvents,
|
|
1416
|
-
active: raw.active ?? true,
|
|
1417
|
-
contentType: raw.config?.content_type === "form" ? "form" : "json",
|
|
1418
|
-
createdAt: toDate(raw.created_at),
|
|
1419
|
-
updatedAt: toDate(raw.updated_at),
|
|
1420
|
-
raw
|
|
1421
|
-
};
|
|
1422
|
-
}
|
|
1423
|
-
function toWebhookDelivery(hook, raw) {
|
|
1424
|
-
const status = raw.status_code ?? 0;
|
|
1425
|
-
return {
|
|
1426
|
-
ref: {
|
|
1427
|
-
forge: FORGE,
|
|
1428
|
-
instance: hook.instance,
|
|
1429
|
-
hook,
|
|
1430
|
-
id: String(raw.id),
|
|
1431
|
-
guid: raw.guid
|
|
1432
|
-
},
|
|
1433
|
-
event: raw.action ? `${raw.event}.${raw.action}` : raw.event ?? "",
|
|
1434
|
-
status,
|
|
1435
|
-
ok: status >= 200 && status < 300,
|
|
1436
|
-
deliveredAt: toDate(raw.delivered_at),
|
|
1437
|
-
duration: raw.duration,
|
|
1438
|
-
raw
|
|
1439
|
-
};
|
|
1440
|
-
}
|
|
1441
|
-
function graphqlUrl(baseUrl) {
|
|
1442
|
-
const url = new URL(baseUrl);
|
|
1443
|
-
if (url.host === "api.github.com") return "https://api.github.com/graphql";
|
|
1444
|
-
return `${url.origin}${url.pathname.replace(/\/v3\/?$/, "")}/graphql`;
|
|
1445
|
-
}
|
|
1446
|
-
/**
|
|
1447
|
-
* A failed GraphQL response as an error: `InsufficientScopeError` when the token lacks a scope a field needs, and
|
|
1448
|
-
* `RateLimitedError` for a rate limit, which GitHub reports with a `200`.
|
|
1449
|
-
*/
|
|
1450
|
-
function graphqlError(operationName, errors, url, context, response) {
|
|
1451
|
-
const message = `GraphQL ${operationName ?? "request"} failed: ${errors?.map((error) => error.message).join("; ") || "Empty GraphQL response"}`;
|
|
1452
|
-
const body = JSON.stringify(errors ?? null).slice(0, 512);
|
|
1453
|
-
const errorContext = {
|
|
1454
|
-
forge: FORGE,
|
|
1455
|
-
instance: context.instance,
|
|
1456
|
-
url,
|
|
1457
|
-
method: "POST"
|
|
1458
|
-
};
|
|
1459
|
-
const secondary = errors?.some((error) => isSecondaryRateLimit(error.message)) ?? false;
|
|
1460
|
-
if (secondary || errors?.some((error) => error.type === "RATE_LIMITED")) {
|
|
1461
|
-
const budget = response && rateLimitOf(response);
|
|
1462
|
-
const resetAt = response && (rateLimitReset(response, budget) ?? (secondary ? void 0 : budget?.resetAt));
|
|
1463
|
-
return new RateLimitedError(message, 200, body, {
|
|
1464
|
-
...errorContext,
|
|
1465
|
-
resetAt,
|
|
1466
|
-
secondary
|
|
1467
|
-
});
|
|
1468
|
-
}
|
|
1469
|
-
const scopeError = errors?.find((error) => error.type === "INSUFFICIENT_SCOPES");
|
|
1470
|
-
if (!scopeError) return new ForgeApiError(message, 200, body, errorContext);
|
|
1471
|
-
return new InsufficientScopeError(message, 200, body, {
|
|
1472
|
-
...errorContext,
|
|
1473
|
-
acceptedScopes: quotedScopes(scopeError.message.match(/requires one of the following scopes: \[([^\]]*)\]/)?.[1]),
|
|
1474
|
-
grantedScopes: quotedScopes(scopeError.message.match(/has only been granted the: \[([^\]]*)\]/)?.[1])
|
|
1475
|
-
});
|
|
1476
|
-
}
|
|
1477
|
-
function quotedScopes(list) {
|
|
1478
|
-
return list === void 0 ? void 0 : [...list.matchAll(/'([^']+)'/g)].map((match) => match[1]);
|
|
1479
|
-
}
|
|
1480
|
-
const OPERATION_TYPES = /* @__PURE__ */ new Set([
|
|
1481
|
-
"query",
|
|
1482
|
-
"mutation",
|
|
1483
|
-
"subscription"
|
|
1484
|
-
]);
|
|
1485
|
-
/** The operations a GraphQL document declares, read from its top level so that fields, variables, strings and comments don't count. */
|
|
1486
|
-
function graphqlOperations(document) {
|
|
1487
|
-
const operations = [];
|
|
1488
|
-
let depth = 0;
|
|
1489
|
-
let definitionStart = true;
|
|
1490
|
-
let awaitingName;
|
|
1491
|
-
for (const [token] of document.matchAll(/"""(?:\\"""|[\s\S])*?"""|"(?:\\.|[^"\\\n\r])*"|#[^\n\r]*|[{}()]|[$@]?[_a-z]\w*/gi)) {
|
|
1492
|
-
if (token[0] === "\"" || token[0] === "#") continue;
|
|
1493
|
-
if (token === "{" || token === "(") {
|
|
1494
|
-
if (depth === 0 && definitionStart && token === "{") operations.push({ type: "query" });
|
|
1495
|
-
depth++;
|
|
1496
|
-
definitionStart = false;
|
|
1497
|
-
awaitingName = void 0;
|
|
1498
|
-
} else if (token === "}" || token === ")") {
|
|
1499
|
-
depth--;
|
|
1500
|
-
definitionStart = depth === 0 && token === "}";
|
|
1501
|
-
} else if (depth === 0) {
|
|
1502
|
-
if (awaitingName && /^[_a-z]/i.test(token)) awaitingName.name = token;
|
|
1503
|
-
awaitingName = definitionStart && OPERATION_TYPES.has(token) ? { type: token } : void 0;
|
|
1504
|
-
if (awaitingName) operations.push(awaitingName);
|
|
1505
|
-
definitionStart = false;
|
|
1506
|
-
}
|
|
1507
|
-
}
|
|
1508
|
-
return operations;
|
|
1509
|
-
}
|
|
1510
|
-
function createGraphQLClient(fetcher, url, context) {
|
|
1511
|
-
return async (document, variables, options) => {
|
|
1512
|
-
const query = typeof document === "string" ? (await import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js"))[document] : document.query;
|
|
1513
|
-
const operationName = graphqlOperations(query)[0]?.name;
|
|
1514
|
-
const { data, response } = await fetcher.json(url, {
|
|
1515
|
-
method: "POST",
|
|
1516
|
-
json: {
|
|
1517
|
-
query,
|
|
1518
|
-
variables,
|
|
1519
|
-
operationName
|
|
1520
|
-
},
|
|
1521
|
-
signal: options?.signal
|
|
1522
|
-
});
|
|
1523
|
-
if (data.errors?.length || !data.data) throw graphqlError(operationName, data.errors, url, context, response);
|
|
1524
|
-
return data.data;
|
|
1525
|
-
};
|
|
1526
|
-
}
|
|
1527
|
-
const SIGNATURE_HEADER = "x-hub-signature-256";
|
|
1528
|
-
function verifyGitHubSignature(delivery, secret) {
|
|
1529
|
-
return verifyHmacSignature(delivery, secret, {
|
|
1530
|
-
header: SIGNATURE_HEADER,
|
|
1531
|
-
prefix: "sha256="
|
|
1532
|
-
});
|
|
1533
|
-
}
|
|
1534
|
-
const githubWebhooks = ({ options, instance }) => ({
|
|
1535
|
-
events: GITHUB_WEBHOOK_EVENTS,
|
|
1536
|
-
verify: (delivery) => verifyGitHubSignature(delivery, options.webhookSecret),
|
|
1537
|
-
translate: async (delivery) => (await import("./events-CeChclTf-CX-gD8oy-4aL2j6V-.js")).translateGitHubWebhook(instance, delivery)
|
|
1538
|
-
});
|
|
1539
|
-
const DISCUSSION_CLOSE_REASONS = {
|
|
1540
|
-
completed: "resolved",
|
|
1541
|
-
duplicate: "duplicate"
|
|
1542
|
-
};
|
|
1543
|
-
const COLLABORATOR_PERMISSIONS = {
|
|
1544
|
-
read: "pull",
|
|
1545
|
-
write: "push"
|
|
1546
|
-
};
|
|
1547
|
-
/** GitHub Enterprise Server versions that support marking a notification done. */
|
|
1548
|
-
const GHES_MARK_DONE = "3.13";
|
|
1549
|
-
/** GitHub Enterprise Server versions with the Dependabot alerts REST API. */
|
|
1550
|
-
const GHES_DEPENDABOT_ALERTS = "3.8";
|
|
1551
|
-
const GRAPHQL_BATCH = 20;
|
|
1552
|
-
const LOCK_REASONS = {
|
|
1553
|
-
off_topic: "off-topic",
|
|
1554
|
-
too_heated: "too heated",
|
|
1555
|
-
resolved: "resolved",
|
|
1556
|
-
spam: "spam"
|
|
1557
|
-
};
|
|
1558
|
-
const REVIEW_CONTEXT_TTL = 3e5;
|
|
1559
|
-
const POLL_DELAYS = [
|
|
1560
|
-
500,
|
|
1561
|
-
1e3,
|
|
1562
|
-
2e3
|
|
1563
|
-
];
|
|
1564
|
-
const CONTRIBUTOR_STATS_DELAYS = [
|
|
1565
|
-
500,
|
|
1566
|
-
1e3,
|
|
1567
|
-
2e3,
|
|
1568
|
-
4e3,
|
|
1569
|
-
8e3
|
|
1570
|
-
];
|
|
1571
|
-
const ISSUE_LIKE = {
|
|
1572
|
-
issue: true,
|
|
1573
|
-
pull_request: true,
|
|
1574
|
-
discussion: true
|
|
1575
|
-
};
|
|
1576
|
-
function repoPath(repo) {
|
|
1577
|
-
return `/repos/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}`;
|
|
1578
|
-
}
|
|
1579
|
-
function branchPath(branch) {
|
|
1580
|
-
return branch.split("/").map(encodeURIComponent).join("/");
|
|
1581
|
-
}
|
|
1582
|
-
const ZERO_OID = "0".repeat(40);
|
|
1583
|
-
/**
|
|
1584
|
-
* GitHub's refusal to move a branch that is no longer at the commit a write built on, as a 409 `BranchMovedError`,
|
|
1585
|
-
* and to delete a file that does not exist, as a 404 `NotFoundError`, whatever the status of the response.
|
|
1586
|
-
*/
|
|
1587
|
-
function commitError(error) {
|
|
1588
|
-
if (!(error instanceof ForgeApiError) || error.constructor !== ForgeApiError) return error;
|
|
1589
|
-
const text = `${error.message} ${error.body}`;
|
|
1590
|
-
const context = {
|
|
1591
|
-
forge: error.forge,
|
|
1592
|
-
instance: error.instance,
|
|
1593
|
-
url: error.url,
|
|
1594
|
-
method: error.method
|
|
1595
|
-
};
|
|
1596
|
-
if (/Expected branch to point to|not a fast[- ]forward/i.test(text)) return new BranchMovedError("The branch no longer points at the commit the change was made on", 409, error.body, context, { cause: error });
|
|
1597
|
-
if (/requested for deletion which does not exist/i.test(text)) return new NotFoundError("A file to delete does not exist", 404, error.body, context, { cause: error });
|
|
1598
|
-
return error;
|
|
1599
|
-
}
|
|
1600
|
-
/** GitHub's `422` for a head that moved since `expected_head_sha`, as `BranchMovedError`, and for a conflict, as `MergeConflictError`. */
|
|
1601
|
-
function updateBranchError(error) {
|
|
1602
|
-
if (!(error instanceof ForgeApiError) || error.constructor !== ForgeApiError || error.status !== 422) return error;
|
|
1603
|
-
const context = {
|
|
1604
|
-
forge: error.forge,
|
|
1605
|
-
instance: error.instance,
|
|
1606
|
-
url: error.url,
|
|
1607
|
-
method: error.method
|
|
1608
|
-
};
|
|
1609
|
-
if (/expected head sha/i.test(error.body)) return new BranchMovedError("The head branch no longer points at the expected sha", error.status, error.body, context, { cause: error });
|
|
1610
|
-
if (/conflict/i.test(error.body)) return new MergeConflictError("The head branch conflicts with its base", error.status, error.body, context, { cause: error });
|
|
1611
|
-
return error;
|
|
1612
|
-
}
|
|
1613
|
-
function threadPath(ref) {
|
|
1614
|
-
switch (ref.kind) {
|
|
1615
|
-
case "pull_request": return `${repoPath(ref.repo)}/pulls/${encodeURIComponent(ref.number)}`;
|
|
1616
|
-
default: return `${repoPath(ref.repo)}/issues/${encodeURIComponent(ref.number)}`;
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1619
|
-
function installationId(installation) {
|
|
1620
|
-
return typeof installation === "string" ? installation : installation.id;
|
|
1621
|
-
}
|
|
1622
|
-
/**
|
|
1623
|
-
* Free text as legacy search reads it: advanced search parses parentheses and
|
|
1624
|
-
* an unclosed quote as syntax, so those are dropped outside quoted phrases.
|
|
1625
|
-
*/
|
|
1626
|
-
function advancedFreeText(text) {
|
|
1627
|
-
const parts = text.split("\"");
|
|
1628
|
-
if (parts.length % 2 === 0) {
|
|
1629
|
-
const unclosed = parts.pop();
|
|
1630
|
-
parts.push(`${parts.pop()} ${unclosed}`);
|
|
1631
|
-
}
|
|
1632
|
-
return parts.map((part, index) => index % 2 ? part : part.replace(/[()\s]+/g, " ")).join("\"").trim();
|
|
1633
|
-
}
|
|
1634
|
-
function setupGitHub({ options, baseUrl, instance, origin: context, fetcher, createFetcher, derive, state: credentials }) {
|
|
1635
|
-
const list = createListing(fetcher, "per_page");
|
|
1636
|
-
const auth = options.auth ?? { type: "anonymous" };
|
|
1637
|
-
/** GitHub GraphQL needs a credential, so anonymous providers stay on REST. */
|
|
1638
|
-
const anonymous = auth.type === "anonymous";
|
|
1639
|
-
/** An app without an installation reaches only the `/app` endpoints. */
|
|
1640
|
-
const appItself = auth.type === "app" && auth.installationId === void 0;
|
|
1641
|
-
const tokenKind = auth.type === "token" ? tokenKindOf(auth) : void 0;
|
|
1642
|
-
/** An installation, whether from app credentials or its token, acts as no account. */
|
|
1643
|
-
const installation = auth.type === "app" || tokenKind === "installation";
|
|
1644
|
-
/** GitHub serves notifications only to classic personal access tokens and OAuth app tokens. */
|
|
1645
|
-
const notificationsAuth = auth.type === "token" && (tokenKind === void 0 || tokenKind === "classic");
|
|
1646
|
-
const host = hostOf(baseUrl);
|
|
1647
|
-
/** GitHub Enterprise Server; `ghe.com` data residency hosts follow github.com. */
|
|
1648
|
-
const enterprise = host !== "api.github.com" && !isGheCom(host);
|
|
1649
|
-
const graphql = createGraphQLClient(fetcher, graphqlUrl(baseUrl), { instance });
|
|
1650
|
-
/**
|
|
1651
|
-
* Discussion notification subjects carry no URL. The repo's most recently
|
|
1652
|
-
* updated discussions are listed and matched on an exact, unique title.
|
|
1653
|
-
*/
|
|
1654
|
-
async function resolveDiscussionNumbers(items) {
|
|
1655
|
-
const pending = items.filter((item) => item.subject.type === "thread" && item.subject.thread.kind === "discussion" && !item.subject.thread.number);
|
|
1656
|
-
if (!pending.length) return [];
|
|
1657
|
-
const repos = [...new Map(pending.map((item) => {
|
|
1658
|
-
const repo = item.subject.thread.repo;
|
|
1659
|
-
return [`${repo.owner}/${repo.name}`, repo];
|
|
1660
|
-
})).values()];
|
|
1661
|
-
let result;
|
|
1662
|
-
try {
|
|
1663
|
-
const { query, variables } = (await import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js")).recentDiscussionsQuery(repos);
|
|
1664
|
-
result = await graphql({ query }, variables);
|
|
1665
|
-
} catch (error) {
|
|
1666
|
-
if (error instanceof InsufficientScopeError || error instanceof ForgeApiError && error.status === 200) return [toWarning("discussion_unresolved", error)];
|
|
1667
|
-
throw error;
|
|
1668
|
-
}
|
|
1669
|
-
for (const item of pending) {
|
|
1670
|
-
const thread = item.subject.thread;
|
|
1671
|
-
const index = repos.findIndex((repo) => repo.owner === thread.repo.owner && repo.name === thread.repo.name);
|
|
1672
|
-
const matches = (result[`r${index}`]?.discussions.nodes ?? []).filter((node) => node.title === item.title);
|
|
1673
|
-
if (matches.length === 1) item.subject = {
|
|
1674
|
-
type: "thread",
|
|
1675
|
-
thread: {
|
|
1676
|
-
...thread,
|
|
1677
|
-
number: String(matches[0].number),
|
|
1678
|
-
externalId: matches[0].id
|
|
1679
|
-
}
|
|
1680
|
-
};
|
|
1681
|
-
}
|
|
1682
|
-
return [];
|
|
1683
|
-
}
|
|
1684
|
-
/** When each polled path may be read again, from GitHub's `X-Poll-Interval`. */
|
|
1685
|
-
const nextPoll = /* @__PURE__ */ new Map();
|
|
1686
|
-
function throttledPage(path, listOptions, subject) {
|
|
1687
|
-
const at = nextPoll.get(path) ?? 0;
|
|
1688
|
-
const wait = at - Date.now();
|
|
1689
|
-
if (!isFirstPage(listOptions.cursor) || listOptions.force || wait <= 0) return;
|
|
1690
|
-
const warning = {
|
|
1691
|
-
code: "feed_throttled",
|
|
1692
|
-
message: `GitHub asked to wait ${Math.ceil(wait / 1e3)}s more before reading ${subject} again; no request was sent. Read it later, or pass force: true`
|
|
1693
|
-
};
|
|
1694
|
-
return {
|
|
1695
|
-
items: [],
|
|
1696
|
-
throttled: true,
|
|
1697
|
-
nextPollAt: new Date(at),
|
|
1698
|
-
warnings: [warning],
|
|
1699
|
-
...listOptions.cursor?.etag ? { etag: listOptions.cursor.etag } : {}
|
|
1700
|
-
};
|
|
1701
|
-
}
|
|
1702
|
-
function recordPoll(path, cursor, response) {
|
|
1703
|
-
const interval = Number(response.headers.get("x-poll-interval"));
|
|
1704
|
-
if (!isFirstPage(cursor) || !(interval > 0)) return {};
|
|
1705
|
-
const at = Date.now() + interval * 1e3;
|
|
1706
|
-
nextPoll.set(path, at);
|
|
1707
|
-
return { nextPollAt: new Date(at) };
|
|
1708
|
-
}
|
|
1709
|
-
async function notificationPage(listOptions = {}) {
|
|
1710
|
-
const throttled = throttledPage("/notifications", listOptions, "notifications");
|
|
1711
|
-
if (throttled) return throttled;
|
|
1712
|
-
const result = await fetcher.json(listOptions.cursor?.nextUrl ?? "/notifications", {
|
|
1713
|
-
query: listOptions.cursor?.nextUrl ? void 0 : {
|
|
1714
|
-
all: listOptions.all ?? false,
|
|
1715
|
-
since: listOptions.since?.toISOString(),
|
|
1716
|
-
per_page: listOptions.perPage
|
|
1717
|
-
},
|
|
1718
|
-
etag: listOptions.cursor?.nextUrl ? void 0 : listOptions.cursor?.etag,
|
|
1719
|
-
signal: listOptions.signal
|
|
1720
|
-
});
|
|
1721
|
-
const items = (result.data ?? []).map((raw) => toNotification(instance, raw));
|
|
1722
|
-
const warnings = await resolveDiscussionNumbers(items);
|
|
1723
|
-
const etag = listOptions.cursor?.nextUrl ? void 0 : result.cursor?.etag ?? listOptions.cursor?.etag;
|
|
1724
|
-
return {
|
|
1725
|
-
items,
|
|
1726
|
-
cursor: result.cursor?.nextUrl ? result.cursor : void 0,
|
|
1727
|
-
...etag ? { etag } : {},
|
|
1728
|
-
notModified: result.notModified,
|
|
1729
|
-
warnings: warnings.length ? warnings : void 0,
|
|
1730
|
-
...recordPoll("/notifications", listOptions.cursor, result.response),
|
|
1731
|
-
...rateLimitPart(result.response)
|
|
1732
|
-
};
|
|
1733
|
-
}
|
|
1734
|
-
async function discussionId(ref, options) {
|
|
1735
|
-
if (ref.externalId) return ref.externalId;
|
|
1736
|
-
return (await getDiscussion(ref, options)).ref.externalId;
|
|
1737
|
-
}
|
|
1738
|
-
async function getDiscussion(ref, options) {
|
|
1739
|
-
const discussion = (await graphql("DISCUSSION_THREAD", {
|
|
1740
|
-
owner: ref.repo.owner,
|
|
1741
|
-
name: ref.repo.name,
|
|
1742
|
-
number: Number(ref.number)
|
|
1743
|
-
}, options)).repository?.discussion;
|
|
1744
|
-
if (!discussion) throw new NotFoundError(`Discussion ${ref.number} not found`, 404, "", context);
|
|
1745
|
-
return (await import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js")).toDiscussionThread(ref, discussion);
|
|
1746
|
-
}
|
|
1747
|
-
async function discussionCommentPage(ref, listOptions) {
|
|
1748
|
-
const comments = (await graphql("DISCUSSION_COMMENTS", {
|
|
1749
|
-
owner: ref.repo.owner,
|
|
1750
|
-
name: ref.repo.name,
|
|
1751
|
-
number: Number(ref.number),
|
|
1752
|
-
after: listOptions.cursor?.token ?? null
|
|
1753
|
-
}, listOptions)).repository?.discussion?.comments;
|
|
1754
|
-
return {
|
|
1755
|
-
items: (comments?.nodes ?? []).flatMap((comment) => [{
|
|
1756
|
-
comment,
|
|
1757
|
-
isReply: false
|
|
1758
|
-
}, ...(comment.replies?.nodes ?? []).map((reply) => ({
|
|
1759
|
-
comment: reply,
|
|
1760
|
-
isReply: true
|
|
1761
|
-
}))]),
|
|
1762
|
-
cursor: comments?.pageInfo.hasNextPage && comments.pageInfo.endCursor ? { token: comments.pageInfo.endCursor } : void 0
|
|
1763
|
-
};
|
|
1764
|
-
}
|
|
1765
|
-
async function get(thread, options) {
|
|
1766
|
-
const ref = requireThread(thread, context);
|
|
1767
|
-
if (ref.kind === "discussion") return getDiscussion(ref, options);
|
|
1768
|
-
const { data } = await fetcher.json(threadPath(ref), { signal: options?.signal });
|
|
1769
|
-
const result = toThread(ref, data);
|
|
1770
|
-
if (ref.kind === "pull_request" && data.head?.sha) try {
|
|
1771
|
-
const checks = await headChecks(ref.repo, data.head.sha, options?.signal);
|
|
1772
|
-
result.checks = summariseChecks(checks.items.map((check) => check.state), data.html_url ? `${data.html_url}/checks` : void 0);
|
|
1773
|
-
if (checks.warnings?.length) result.warnings = [...result.warnings ?? [], ...checks.warnings];
|
|
1774
|
-
} catch (error) {
|
|
1775
|
-
if (!degradesToWarning(error)) throw error;
|
|
1776
|
-
result.warnings = [...result.warnings ?? [], toWarning("checks_unreadable", error, ref.number)];
|
|
1777
|
-
}
|
|
1778
|
-
return result;
|
|
1779
|
-
}
|
|
1780
|
-
async function headChecks(repo, sha, signal) {
|
|
1781
|
-
let checkRunTotal;
|
|
1782
|
-
const [runs, status] = await Promise.allSettled([Array.fromAsync(fetcher.items(`${repoPath(repo)}/commits/${sha}/check-runs`, {
|
|
1783
|
-
query: { per_page: 100 },
|
|
1784
|
-
select: (body, next) => {
|
|
1785
|
-
const { check_runs, total_count } = body;
|
|
1786
|
-
checkRunTotal = total_count;
|
|
1787
|
-
return {
|
|
1788
|
-
items: check_runs,
|
|
1789
|
-
next
|
|
1790
|
-
};
|
|
1791
|
-
},
|
|
1792
|
-
signal
|
|
1793
|
-
}), (raw) => toCheckRun(repo, raw)), Array.fromAsync(fetcher.items(`${repoPath(repo)}/commits/${sha}/status`, {
|
|
1794
|
-
query: { per_page: 100 },
|
|
1795
|
-
select: (body, next) => ({
|
|
1796
|
-
items: body.statuses,
|
|
1797
|
-
next
|
|
1798
|
-
}),
|
|
1799
|
-
signal
|
|
1800
|
-
}), (raw) => toStatusCheck(repo, raw))]);
|
|
1801
|
-
if (signal?.aborted) throw signal.reason;
|
|
1802
|
-
if (runs.status === "rejected" && status.status === "rejected") throw runs.reason;
|
|
1803
|
-
for (const result of [runs, status]) if (result.status === "rejected" && !degradesToWarning(result.reason)) throw result.reason;
|
|
1804
|
-
const statuses = status.status === "fulfilled" ? status.value : [];
|
|
1805
|
-
const total = runs.status === "fulfilled" && status.status === "fulfilled" && checkRunTotal !== void 0 ? checkRunTotal + statuses.length : void 0;
|
|
1806
|
-
return {
|
|
1807
|
-
items: [...runs.status === "fulfilled" ? runs.value : [], ...statuses],
|
|
1808
|
-
...total !== void 0 ? { total } : {},
|
|
1809
|
-
warnings: [...runs.status === "rejected" ? [toWarning("checks_unreadable", runs.reason, "check-runs")] : [], ...status.status === "rejected" ? [toWarning("checks_unreadable", status.reason, "statuses")] : []]
|
|
1810
|
-
};
|
|
1811
|
-
}
|
|
1812
|
-
async function getMany(refs, options) {
|
|
1813
|
-
if (anonymous) return getManyConcurrently(refs, (ref, getOptions) => ref.kind === "discussion" ? Promise.reject(new UnsupportedOperationError("github does not read discussions without credentials", context)) : get(ref, getOptions), options);
|
|
1814
|
-
const results = Array.from({ length: refs.length });
|
|
1815
|
-
const batchable = [];
|
|
1816
|
-
for (const [index, ref] of refs.entries()) if (!isResolvedThread(ref)) results[index] = {
|
|
1817
|
-
ok: false,
|
|
1818
|
-
ref,
|
|
1819
|
-
warning: toWarning("thread_unresolved", /* @__PURE__ */ new Error("Thread ref has no number"), ref.number)
|
|
1820
|
-
};
|
|
1821
|
-
else batchable.push({
|
|
1822
|
-
index,
|
|
1823
|
-
ref
|
|
1824
|
-
});
|
|
1825
|
-
if (!batchable.length) return results;
|
|
1826
|
-
const g = await import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js");
|
|
1827
|
-
for (let start = 0; start < batchable.length; start += GRAPHQL_BATCH) {
|
|
1828
|
-
const chunk = batchable.slice(start, start + GRAPHQL_BATCH);
|
|
1829
|
-
const { query, variables } = g.threadsBatchQuery(chunk.map((item) => item.ref));
|
|
1830
|
-
const url = graphqlUrl(baseUrl);
|
|
1831
|
-
const { data, response } = await fetcher.json(url, {
|
|
1832
|
-
method: "POST",
|
|
1833
|
-
json: {
|
|
1834
|
-
query,
|
|
1835
|
-
variables,
|
|
1836
|
-
operationName: "ThreadsBatch"
|
|
1837
|
-
},
|
|
1838
|
-
signal: options?.signal
|
|
1839
|
-
});
|
|
1840
|
-
const failure = data.data ? void 0 : graphqlError("ThreadsBatch", data.errors, url, { instance }, response);
|
|
1841
|
-
if (failure instanceof RateLimitedError) throw failure;
|
|
1842
|
-
chunk.forEach(({ index, ref }, offset) => {
|
|
1843
|
-
const node = data.data?.[`t${offset}`];
|
|
1844
|
-
const discussion = ref.kind === "discussion" ? node?.discussion : void 0;
|
|
1845
|
-
const issueOrPullRequest = ref.kind === "discussion" ? void 0 : node?.issueOrPullRequest;
|
|
1846
|
-
if (failure) {
|
|
1847
|
-
results[index] = {
|
|
1848
|
-
ok: false,
|
|
1849
|
-
ref,
|
|
1850
|
-
warning: toWarning(failure instanceof InsufficientScopeError ? "insufficient_scope" : "thread_unreadable", failure, ref.number)
|
|
1851
|
-
};
|
|
1852
|
-
return;
|
|
1853
|
-
}
|
|
1854
|
-
if (!discussion && !issueOrPullRequest) {
|
|
1855
|
-
const error = data.errors?.find((error) => error.path?.[0] === `t${offset}`);
|
|
1856
|
-
if (error?.type === "INSUFFICIENT_SCOPES") {
|
|
1857
|
-
results[index] = {
|
|
1858
|
-
ok: false,
|
|
1859
|
-
ref,
|
|
1860
|
-
warning: toWarning("insufficient_scope", graphqlError("ThreadsBatch", [error], url, { instance }), ref.number)
|
|
1861
|
-
};
|
|
1862
|
-
return;
|
|
1863
|
-
}
|
|
1864
|
-
results[index] = {
|
|
1865
|
-
ok: false,
|
|
1866
|
-
ref,
|
|
1867
|
-
warning: {
|
|
1868
|
-
code: "thread_unreadable",
|
|
1869
|
-
message: error?.message ?? "Not found",
|
|
1870
|
-
subject: ref.number
|
|
1871
|
-
}
|
|
1872
|
-
};
|
|
1873
|
-
return;
|
|
1874
|
-
}
|
|
1875
|
-
results[index] = {
|
|
1876
|
-
ok: true,
|
|
1877
|
-
ref,
|
|
1878
|
-
thread: discussion ? g.toDiscussionThread(ref, discussion) : g.toGraphQLThread(ref, issueOrPullRequest)
|
|
1879
|
-
};
|
|
1880
|
-
});
|
|
1881
|
-
}
|
|
1882
|
-
return results;
|
|
1883
|
-
}
|
|
1884
|
-
async function listPage(repo, query = {}) {
|
|
1885
|
-
const state = query.state ?? "open";
|
|
1886
|
-
const direction = query.direction ?? "desc";
|
|
1887
|
-
const createdAfter = query.createdAfter?.getTime();
|
|
1888
|
-
if (query.kind === "discussion") {
|
|
1889
|
-
if (query.assignee) return {
|
|
1890
|
-
items: [],
|
|
1891
|
-
warnings: [{
|
|
1892
|
-
code: "filter_unsupported",
|
|
1893
|
-
message: "Discussions have no assignees"
|
|
1894
|
-
}]
|
|
1895
|
-
};
|
|
1896
|
-
if (query.milestone && query.milestone !== "none") return {
|
|
1897
|
-
items: [],
|
|
1898
|
-
warnings: [{
|
|
1899
|
-
code: "filter_unsupported",
|
|
1900
|
-
message: "Discussions have no milestones"
|
|
1901
|
-
}]
|
|
1902
|
-
};
|
|
1903
|
-
const warnings = isFirstPage(query.cursor) && query.sort === "comments" ? [{
|
|
1904
|
-
code: "sort_unsupported",
|
|
1905
|
-
message: "Discussions cannot be sorted by comments; sorted by update time"
|
|
1906
|
-
}] : [];
|
|
1907
|
-
for (const filter of ["involves", "mentions"]) if (isFirstPage(query.cursor) && query[filter]) warnings.push({
|
|
1908
|
-
code: "filter_unsupported",
|
|
1909
|
-
message: `GitHub lists discussions without a ${filter} filter; it was ignored`
|
|
1910
|
-
});
|
|
1911
|
-
const data = await graphql("DISCUSSIONS_LIST", {
|
|
1912
|
-
owner: repo.owner,
|
|
1913
|
-
name: repo.name,
|
|
1914
|
-
first: Math.min(query.perPage ?? 50, 100),
|
|
1915
|
-
after: query.cursor?.token ?? null,
|
|
1916
|
-
field: query.sort === "created" || !query.sort ? "CREATED_AT" : "UPDATED_AT",
|
|
1917
|
-
direction: direction.toUpperCase()
|
|
1918
|
-
}, query);
|
|
1919
|
-
const { toDiscussionThread } = await import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js");
|
|
1920
|
-
const discussions = data.repository?.discussions;
|
|
1921
|
-
return {
|
|
1922
|
-
items: (discussions?.nodes ?? []).map((node) => toDiscussionThread({
|
|
1923
|
-
forge: FORGE,
|
|
1924
|
-
instance,
|
|
1925
|
-
repo,
|
|
1926
|
-
kind: "discussion",
|
|
1927
|
-
number: String(node.number)
|
|
1928
|
-
}, node)).filter((thread) => (state === "all" || thread.state === state) && (!query.author || thread.author?.login === query.author) && (!query.labels?.length || query.labels.every((label) => thread.labels.some((item) => item.name === label))) && (!query.since || (thread.updatedAt?.getTime() ?? 0) >= query.since.getTime()) && (createdAfter === void 0 || (thread.createdAt?.getTime() ?? 0) >= createdAfter)),
|
|
1929
|
-
cursor: discussions?.pageInfo.hasNextPage && discussions.pageInfo.endCursor ? { token: discussions.pageInfo.endCursor } : void 0,
|
|
1930
|
-
...warnings.length ? { warnings } : {}
|
|
1931
|
-
};
|
|
1932
|
-
}
|
|
1933
|
-
if (state === "merged") {
|
|
1934
|
-
const page = await searchThreadsPage({
|
|
1935
|
-
repo,
|
|
1936
|
-
kind: "pull_request",
|
|
1937
|
-
labels: query.labels,
|
|
1938
|
-
author: query.author,
|
|
1939
|
-
assignee: query.assignee,
|
|
1940
|
-
involves: query.involves,
|
|
1941
|
-
since: query.since,
|
|
1942
|
-
queryRaw: [
|
|
1943
|
-
"is:merged",
|
|
1944
|
-
query.createdAfter && `created:>=${query.createdAfter.toISOString()}`,
|
|
1945
|
-
query.mentions && `mentions:${query.mentions}`,
|
|
1946
|
-
query.milestone && (query.milestone === "none" ? "no:milestone" : `milestone:"${query.milestone.replaceAll("\"", "")}"`)
|
|
1947
|
-
].filter(Boolean).join(" "),
|
|
1948
|
-
sort: query.sort ?? "created",
|
|
1949
|
-
direction,
|
|
1950
|
-
perPage: query.perPage,
|
|
1951
|
-
cursor: query.cursor,
|
|
1952
|
-
signal: query.signal
|
|
1953
|
-
});
|
|
1954
|
-
await withPullChecks(page, query);
|
|
1955
|
-
return page;
|
|
1956
|
-
}
|
|
1957
|
-
const milestone = query.milestone === void 0 || query.milestone === "none" || !isFirstPage(query.cursor) ? query.milestone : await milestoneNumber(repo, query.milestone, query);
|
|
1958
|
-
if (milestone === null) return { items: [] };
|
|
1959
|
-
const warnings = isFirstPage(query.cursor) && query.involves ? [{
|
|
1960
|
-
code: "filter_unsupported",
|
|
1961
|
-
message: "GitHub lists issues and pull requests without an involves filter; it was ignored. search.threads() has one"
|
|
1962
|
-
}] : [];
|
|
1963
|
-
const pullsOnly = query.kind === "pull_request" && !query.labels?.length && !query.author && !query.assignee && !query.mentions && !query.milestone && !query.since && query.sort !== "comments";
|
|
1964
|
-
const result = await fetcher.page(`${repoPath(repo)}/${pullsOnly ? "pulls" : "issues"}`, {
|
|
1965
|
-
query: {
|
|
1966
|
-
state,
|
|
1967
|
-
labels: query.labels?.join(","),
|
|
1968
|
-
creator: query.author,
|
|
1969
|
-
assignee: query.assignee,
|
|
1970
|
-
mentioned: query.mentions,
|
|
1971
|
-
milestone,
|
|
1972
|
-
since: query.since?.toISOString(),
|
|
1973
|
-
sort: query.sort ?? "created",
|
|
1974
|
-
direction,
|
|
1975
|
-
per_page: query.perPage
|
|
1976
|
-
},
|
|
1977
|
-
cursor: query.cursor,
|
|
1978
|
-
signal: query.signal
|
|
1979
|
-
});
|
|
1980
|
-
const older = (raw) => createdAfter !== void 0 && (Date.parse(raw.created_at ?? "") || 0) < createdAfter;
|
|
1981
|
-
const page = toPage(result, (raw) => {
|
|
1982
|
-
const isPull = Boolean(raw.pull_request || raw.head);
|
|
1983
|
-
if (query.kind === "issue" && isPull || query.kind === "pull_request" && !isPull || older(raw)) return;
|
|
1984
|
-
return toThread({
|
|
1985
|
-
forge: FORGE,
|
|
1986
|
-
instance,
|
|
1987
|
-
repo,
|
|
1988
|
-
kind: isPull ? "pull_request" : "issue",
|
|
1989
|
-
number: String(raw.number)
|
|
1990
|
-
}, raw);
|
|
1991
|
-
});
|
|
1992
|
-
const ordered = (query.sort ?? "created") === "created" && direction === "desc";
|
|
1993
|
-
await withPullChecks(page, query);
|
|
1994
|
-
const listed = warnings.length ? {
|
|
1995
|
-
...page,
|
|
1996
|
-
warnings: [...warnings, ...page.warnings ?? []]
|
|
1997
|
-
} : page;
|
|
1998
|
-
return ordered && (result.data ?? []).some(older) ? {
|
|
1999
|
-
...listed,
|
|
2000
|
-
cursor: void 0
|
|
2001
|
-
} : listed;
|
|
2002
|
-
}
|
|
2003
|
-
/** The number of the milestone titled `title`, or `null` when the repository has none by that title. */
|
|
2004
|
-
async function milestoneNumber(repo, title, options) {
|
|
2005
|
-
for await (const milestone of iteratePages((page) => milestonesPage(repo, page), {
|
|
2006
|
-
state: "all",
|
|
2007
|
-
signal: options.signal
|
|
2008
|
-
})) if (milestone.title === title) return milestone.id;
|
|
2009
|
-
return null;
|
|
2010
|
-
}
|
|
2011
|
-
/** Fills `checks`, and a missing `commentCount`, on every pull in the page with one batched read. */
|
|
2012
|
-
async function withPullChecks(page, options) {
|
|
2013
|
-
const pulls = page.items.filter((thread) => thread.kind === "pull_request");
|
|
2014
|
-
if (!pulls.length || anonymous) return;
|
|
2015
|
-
try {
|
|
2016
|
-
const results = await getMany(pulls.map((thread) => thread.ref), options);
|
|
2017
|
-
for (const [index, result] of results.entries()) if (result.ok) {
|
|
2018
|
-
pulls[index].checks = result.thread.checks ?? pulls[index].checks;
|
|
2019
|
-
pulls[index].commentCount ??= result.thread.commentCount;
|
|
2020
|
-
pulls[index].mergedBy ??= result.thread.mergedBy;
|
|
2021
|
-
}
|
|
2022
|
-
} catch (error) {
|
|
2023
|
-
if (!degradesToWarning(error)) throw error;
|
|
2024
|
-
page.warnings = [...page.warnings ?? [], toWarning("checks_unreadable", error)];
|
|
2025
|
-
}
|
|
2026
|
-
}
|
|
2027
|
-
async function commentsPage(thread, listOptions = {}) {
|
|
2028
|
-
const ref = requireThread(thread, context);
|
|
2029
|
-
if (ref.kind === "discussion") {
|
|
2030
|
-
const [page, { toDiscussionComment }] = await Promise.all([discussionCommentPage(ref, listOptions), import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js")]);
|
|
2031
|
-
return {
|
|
2032
|
-
...page,
|
|
2033
|
-
items: page.items.map(({ comment }) => toDiscussionComment(ref, comment))
|
|
2034
|
-
};
|
|
2035
|
-
}
|
|
2036
|
-
return list(`${repoPath(ref.repo)}/issues/${encodeURIComponent(ref.number)}/comments`, listOptions, (raw) => toComment(ref, raw), { query: { since: listOptions.since?.toISOString() } });
|
|
2037
|
-
}
|
|
2038
|
-
/** Discussion comment ids are node ids already; other comments are read for theirs. */
|
|
2039
|
-
async function commentNodeId(ref, options) {
|
|
2040
|
-
if ("thread" in ref && ref.thread.kind === "discussion") return ref.id;
|
|
2041
|
-
const { data } = await fetcher.json("commit" in ref ? commitCommentPath(ref) : commentPath(ref), { signal: options?.signal });
|
|
2042
|
-
if (!data.node_id) throw new NotFoundError(`Comment ${ref.id} has no node id`, 404, "", context);
|
|
2043
|
-
return data.node_id;
|
|
2044
|
-
}
|
|
2045
|
-
function commentPath(ref) {
|
|
2046
|
-
return `${repoPath(ref.thread.repo)}/issues/comments/${encodeURIComponent(ref.id)}`;
|
|
2047
|
-
}
|
|
2048
|
-
function commitCommentPath(ref) {
|
|
2049
|
-
return `${repoPath(ref.commit.repo)}/comments/${encodeURIComponent(ref.id)}`;
|
|
2050
|
-
}
|
|
2051
|
-
async function setState(thread, state, options_ = {}) {
|
|
2052
|
-
const ref = requireThread(thread, context);
|
|
2053
|
-
if (ref.kind === "discussion") {
|
|
2054
|
-
const reason = options_.reasonRaw ?? (options_.reason && DISCUSSION_CLOSE_REASONS[options_.reason]);
|
|
2055
|
-
if (state === "closed" && options_.reason && !reason) throw new UnsupportedOperationError(`GitHub discussions have no ${options_.reason} close reason; pass reasonRaw: 'outdated'`, context);
|
|
2056
|
-
const id = await discussionId(ref, options_);
|
|
2057
|
-
const data = state === "closed" ? (await graphql("CLOSE_DISCUSSION", {
|
|
2058
|
-
id,
|
|
2059
|
-
reason: reason?.toUpperCase() ?? null
|
|
2060
|
-
}, options_)).closeDiscussion : (await graphql("REOPEN_DISCUSSION", { id }, options_)).reopenDiscussion;
|
|
2061
|
-
return (await import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js")).toDiscussionThread(ref, data.discussion);
|
|
2062
|
-
}
|
|
2063
|
-
const reason = options_.reasonRaw ?? options_.reason;
|
|
2064
|
-
const { data } = await fetcher.json(threadPath(ref), {
|
|
2065
|
-
method: "PATCH",
|
|
2066
|
-
json: ref.kind === "issue" && state === "closed" && reason ? {
|
|
2067
|
-
state,
|
|
2068
|
-
state_reason: reason
|
|
2069
|
-
} : { state },
|
|
2070
|
-
signal: options_.signal
|
|
2071
|
-
});
|
|
2072
|
-
return toThread(ref, data);
|
|
2073
|
-
}
|
|
2074
|
-
async function merge(thread, options_ = {}) {
|
|
2075
|
-
const ref = requireThread(thread, context);
|
|
2076
|
-
if (ref.kind !== "pull_request") throw new UnsupportedOperationError("Only pull requests can be merged", context);
|
|
2077
|
-
if (options_.whenChecksPass) throw new UnsupportedOperationError("GitHub auto-merge is not available through the REST API", context);
|
|
2078
|
-
if (options_.method === "rebase_merge" || options_.method === "fast_forward_only") throw new UnsupportedOperationError(`GitHub does not support the ${options_.method} merge method`, context);
|
|
2079
|
-
let method = options_.method;
|
|
2080
|
-
if (!method) {
|
|
2081
|
-
const { data: repo } = await fetcher.json(repoPath(ref.repo), { signal: options_.signal });
|
|
2082
|
-
method = soleMergeMethod({
|
|
2083
|
-
merge: repo.allow_merge_commit,
|
|
2084
|
-
squash: repo.allow_squash_merge,
|
|
2085
|
-
rebase: repo.allow_rebase_merge
|
|
2086
|
-
}, context);
|
|
2087
|
-
}
|
|
2088
|
-
return directMerge(ref, method, options_);
|
|
2089
|
-
}
|
|
2090
|
-
async function directMerge(ref, method, mergeOptions) {
|
|
2091
|
-
const path = `${threadPath(ref)}/merge`;
|
|
2092
|
-
const { sha, title, message } = mergeOptions;
|
|
2093
|
-
const body = {
|
|
2094
|
-
merge_method: method,
|
|
2095
|
-
sha,
|
|
2096
|
-
commit_title: title,
|
|
2097
|
-
commit_message: message
|
|
2098
|
-
};
|
|
2099
|
-
const timeout = options.timeout ?? 3e4;
|
|
2100
|
-
const budget = new AbortController();
|
|
2101
|
-
const signal = mergeOptions.signal ? anySignal([budget.signal, mergeOptions.signal]) : budget.signal;
|
|
2102
|
-
const timer = setTimeout(() => budget.abort(new DOMException("Merge timed out", "TimeoutError")), timeout);
|
|
2103
|
-
const timedOut = (url, requestMethod, cause, uuid) => new ForgeTimeoutError(uuid ? `Merge request ${uuid} for pull request ${ref.number} was still pending after ${timeout}ms; GitHub may still complete it` : `Merge of pull request ${ref.number} got no response within ${timeout}ms; GitHub may still complete it`, timeout, {
|
|
2104
|
-
...context,
|
|
2105
|
-
url,
|
|
2106
|
-
method: requestMethod
|
|
2107
|
-
}, { cause });
|
|
2108
|
-
let url = fetcher.resolve(`${path}-async`);
|
|
2109
|
-
let requestMethod = "PUT";
|
|
2110
|
-
let uuid;
|
|
2111
|
-
try {
|
|
2112
|
-
let state;
|
|
2113
|
-
let status;
|
|
2114
|
-
try {
|
|
2115
|
-
const { data, response } = await fetcher.json(`${path}-async`, {
|
|
2116
|
-
method: "PUT",
|
|
2117
|
-
json: {
|
|
2118
|
-
...body,
|
|
2119
|
-
merge_action: "direct_merge"
|
|
2120
|
-
},
|
|
2121
|
-
signal
|
|
2122
|
-
});
|
|
2123
|
-
state = data;
|
|
2124
|
-
status = response.status;
|
|
2125
|
-
} catch (error) {
|
|
2126
|
-
if (budget.signal.aborted) throw error;
|
|
2127
|
-
if (enterprise && error instanceof NotFoundError) {
|
|
2128
|
-
url = fetcher.resolve(path);
|
|
2129
|
-
const { data } = await fetcher.json(path, {
|
|
2130
|
-
method: "PUT",
|
|
2131
|
-
json: body,
|
|
2132
|
-
mapError: toMergeError,
|
|
2133
|
-
signal
|
|
2134
|
-
});
|
|
2135
|
-
return {
|
|
2136
|
-
status: "merged",
|
|
2137
|
-
sha: data?.sha,
|
|
2138
|
-
raw: data
|
|
2139
|
-
};
|
|
2140
|
-
}
|
|
2141
|
-
state = pendingMergeFrom(error, method, sha, title, message);
|
|
2142
|
-
status = 409;
|
|
2143
|
-
}
|
|
2144
|
-
for (let attempt = 0; state.status === "pending"; attempt++) {
|
|
2145
|
-
uuid = state.details?.uuid;
|
|
2146
|
-
if (!uuid) throw new ForgeApiError("GitHub reported a pending merge without a request id", status, JSON.stringify(state).slice(0, 512), {
|
|
2147
|
-
...context,
|
|
2148
|
-
url,
|
|
2149
|
-
method: requestMethod
|
|
2150
|
-
});
|
|
2151
|
-
const poll = `${path}-async/${encodeURIComponent(uuid)}`;
|
|
2152
|
-
url = fetcher.resolve(poll);
|
|
2153
|
-
requestMethod = "GET";
|
|
2154
|
-
await sleep(POLL_DELAYS[Math.min(attempt, POLL_DELAYS.length - 1)], signal);
|
|
2155
|
-
const { data, response } = await fetcher.json(poll, { signal });
|
|
2156
|
-
state = data;
|
|
2157
|
-
status = response.status;
|
|
2158
|
-
}
|
|
2159
|
-
const errorContext = {
|
|
2160
|
-
...context,
|
|
2161
|
-
url,
|
|
2162
|
-
method: requestMethod
|
|
2163
|
-
};
|
|
2164
|
-
const excerpt = JSON.stringify(state).slice(0, 512);
|
|
2165
|
-
switch (state.status) {
|
|
2166
|
-
case "merged": return {
|
|
2167
|
-
status: "merged",
|
|
2168
|
-
sha: state.details?.sha,
|
|
2169
|
-
raw: state
|
|
2170
|
-
};
|
|
2171
|
-
case "enqueued": throw new MergeBlockedError("Pull request was added to a merge queue and has not merged", status, excerpt, errorContext);
|
|
2172
|
-
case "failed": throw new MergeBlockedError(state.details?.message || "GitHub could not merge the pull request", status, excerpt, errorContext);
|
|
2173
|
-
default: throw new ForgeApiError(`GitHub reported an unknown merge status ${JSON.stringify(state.status)}`, status, excerpt, errorContext);
|
|
2174
|
-
}
|
|
2175
|
-
} catch (error) {
|
|
2176
|
-
throw budget.signal.aborted ? timedOut(url, requestMethod, error, uuid) : error;
|
|
2177
|
-
} finally {
|
|
2178
|
-
clearTimeout(timer);
|
|
2179
|
-
}
|
|
2180
|
-
}
|
|
2181
|
-
function pendingMergeFrom(error, method, sha, title, message) {
|
|
2182
|
-
if (!(error instanceof ForgeApiError)) throw error;
|
|
2183
|
-
if (isPlainApiError(error, 400)) throw new MergeBlockedError("Pull request cannot be merged in its current state", 400, error.body, {
|
|
2184
|
-
...context,
|
|
2185
|
-
url: error.url,
|
|
2186
|
-
method: error.method
|
|
2187
|
-
}, { cause: error });
|
|
2188
|
-
if (!isPlainApiError(error, 409)) throw toMergeError(error);
|
|
2189
|
-
let pending;
|
|
2190
|
-
try {
|
|
2191
|
-
pending = JSON.parse(error.body);
|
|
2192
|
-
} catch {}
|
|
2193
|
-
const details = pending?.details;
|
|
2194
|
-
if (!details?.uuid) throw toMergeError(error);
|
|
2195
|
-
if (title !== void 0 || message !== void 0 || details.merge_action !== "direct_merge" || details.merge_method !== method || details.bypass_rules || sha !== void 0 && details.expected_head_sha !== sha) throw new MergeBlockedError("Another merge request is pending whose options do not match or cannot be verified", 409, error.body, {
|
|
2196
|
-
...context,
|
|
2197
|
-
url: error.url,
|
|
2198
|
-
method: error.method
|
|
2199
|
-
}, { cause: error });
|
|
2200
|
-
return {
|
|
2201
|
-
status: "pending",
|
|
2202
|
-
details
|
|
2203
|
-
};
|
|
2204
|
-
}
|
|
2205
|
-
function isPlainApiError(error, status) {
|
|
2206
|
-
return error instanceof ForgeApiError && error.constructor === ForgeApiError && error.status === status;
|
|
2207
|
-
}
|
|
2208
|
-
/** A merge goes through REST, which takes no method; a rebase goes through GraphQL, after a read for the pull request's node id. */
|
|
2209
|
-
async function updateBranch(thread, updateOptions = {}) {
|
|
2210
|
-
const ref = requirePull(thread, "updated");
|
|
2211
|
-
const { sha, signal } = updateOptions;
|
|
2212
|
-
if (updateOptions.method === "rebase") {
|
|
2213
|
-
const { data: pull } = await fetcher.json(threadPath(ref), { signal });
|
|
2214
|
-
if (sha !== void 0 && pull.head?.sha !== sha) throw new BranchMovedError(`Head branch of pull request ${ref.number} is at ${pull.head?.sha}, not ${sha}`, 409, "", context);
|
|
2215
|
-
return {
|
|
2216
|
-
status: "queued",
|
|
2217
|
-
raw: (await graphql("UPDATE_PULL_REQUEST_BRANCH", {
|
|
2218
|
-
id: pull.node_id,
|
|
2219
|
-
sha: sha ?? null,
|
|
2220
|
-
method: "REBASE"
|
|
2221
|
-
}, updateOptions)).updatePullRequestBranch
|
|
2222
|
-
};
|
|
2223
|
-
}
|
|
2224
|
-
const { data } = await fetcher.json(`${threadPath(ref)}/update-branch`, {
|
|
2225
|
-
method: "PUT",
|
|
2226
|
-
json: sha === void 0 ? {} : { expected_head_sha: sha },
|
|
2227
|
-
mapError: updateBranchError,
|
|
2228
|
-
signal
|
|
2229
|
-
});
|
|
2230
|
-
return {
|
|
2231
|
-
status: "queued",
|
|
2232
|
-
raw: data
|
|
2233
|
-
};
|
|
2234
|
-
}
|
|
2235
|
-
const REVIEW_EVENTS = {
|
|
2236
|
-
approve: "APPROVE",
|
|
2237
|
-
request_changes: "REQUEST_CHANGES",
|
|
2238
|
-
comment: "COMMENT"
|
|
2239
|
-
};
|
|
2240
|
-
function requirePull(thread, action) {
|
|
2241
|
-
const ref = requireThread(thread, context);
|
|
2242
|
-
if (ref.kind !== "pull_request") throw new UnsupportedOperationError(`Only pull requests can be ${action}`, context);
|
|
2243
|
-
return ref;
|
|
2244
|
-
}
|
|
2245
|
-
function reviewCommentInput(comments) {
|
|
2246
|
-
return comments?.map((comment) => ({
|
|
2247
|
-
path: comment.path,
|
|
2248
|
-
body: comment.body,
|
|
2249
|
-
line: comment.line,
|
|
2250
|
-
start_line: comment.startLine,
|
|
2251
|
-
side: comment.side?.toUpperCase()
|
|
2252
|
-
}));
|
|
2253
|
-
}
|
|
2254
|
-
/** Resolvable conversations, by the id of each comment in them; empty when GraphQL is unreachable. */
|
|
2255
|
-
async function reviewThreadsByComment(ref, options) {
|
|
2256
|
-
const byComment = /* @__PURE__ */ new Map();
|
|
2257
|
-
if (anonymous) return byComment;
|
|
2258
|
-
let data;
|
|
2259
|
-
try {
|
|
2260
|
-
data = await graphql("REVIEW_THREADS", {
|
|
2261
|
-
owner: ref.repo.owner,
|
|
2262
|
-
name: ref.repo.name,
|
|
2263
|
-
number: Number(ref.number)
|
|
2264
|
-
}, options);
|
|
2265
|
-
} catch (error) {
|
|
2266
|
-
if (error instanceof ForgeError) return byComment;
|
|
2267
|
-
throw error;
|
|
2268
|
-
}
|
|
2269
|
-
for (const node of data.repository?.pullRequest?.reviewThreads.nodes ?? []) for (const comment of node.comments.nodes) if (comment.databaseId !== null) byComment.set(String(comment.databaseId), {
|
|
2270
|
-
id: node.id,
|
|
2271
|
-
resolved: node.isResolved
|
|
2272
|
-
});
|
|
2273
|
-
return byComment;
|
|
2274
|
-
}
|
|
2275
|
-
/** Review comments and conversations read for a pull's first page of reviews, reused by its later pages. */
|
|
2276
|
-
const reviewContext = /* @__PURE__ */ new Map();
|
|
2277
|
-
async function reviewsPage(thread, listOptions = {}) {
|
|
2278
|
-
const ref = requirePull(thread, "reviewed");
|
|
2279
|
-
const result = await fetcher.page(`${threadPath(ref)}/reviews`, {
|
|
2280
|
-
query: { per_page: listOptions.perPage },
|
|
2281
|
-
cursor: listOptions.cursor,
|
|
2282
|
-
signal: listOptions.signal,
|
|
2283
|
-
conditional: false
|
|
2284
|
-
});
|
|
2285
|
-
const now = Date.now();
|
|
2286
|
-
for (const [path, entry] of reviewContext) if (now - entry.at >= REVIEW_CONTEXT_TTL) reviewContext.delete(path);
|
|
2287
|
-
const key = threadPath(ref);
|
|
2288
|
-
const kept = !isFirstPage(listOptions.cursor) && reviewContext.get(key) || {
|
|
2289
|
-
at: now,
|
|
2290
|
-
read: Promise.all([Array.fromAsync(fetcher.items(`${key}/comments`, {
|
|
2291
|
-
query: { per_page: 100 },
|
|
2292
|
-
signal: listOptions.signal
|
|
2293
|
-
})), reviewThreadsByComment(ref, listOptions)])
|
|
2294
|
-
};
|
|
2295
|
-
reviewContext.delete(key);
|
|
2296
|
-
const [comments, byComment] = await kept.read;
|
|
2297
|
-
if (result.cursor) reviewContext.set(key, kept);
|
|
2298
|
-
return toPage(result, (raw) => toReview(ref, raw, comments.filter((comment) => String(comment.pull_request_review_id ?? "") === String(raw.id)).map((comment) => toReviewComment(ref, comment, byComment.get(String(comment.id))))));
|
|
2299
|
-
}
|
|
2300
|
-
async function createReview(thread, input, options) {
|
|
2301
|
-
const ref = requirePull(thread, "reviewed");
|
|
2302
|
-
const { data } = await fetcher.json(`${threadPath(ref)}/reviews`, {
|
|
2303
|
-
method: "POST",
|
|
2304
|
-
json: {
|
|
2305
|
-
event: input.event ? REVIEW_EVENTS[input.event] : void 0,
|
|
2306
|
-
body: input.body,
|
|
2307
|
-
comments: reviewCommentInput(input.comments)
|
|
2308
|
-
},
|
|
2309
|
-
signal: options?.signal
|
|
2310
|
-
});
|
|
2311
|
-
return toReview(ref, data, []);
|
|
2312
|
-
}
|
|
2313
|
-
async function getComment(ref, options) {
|
|
2314
|
-
const thread = requireThread(ref.thread, context);
|
|
2315
|
-
if (thread.kind === "discussion") {
|
|
2316
|
-
const data = await graphql("GET_DISCUSSION_COMMENT", { id: ref.id }, options);
|
|
2317
|
-
if (!data.node?.id) throw new NotFoundError(`Comment ${ref.id} not found`, 404, "", context);
|
|
2318
|
-
return (await import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js")).toDiscussionComment(thread, data.node);
|
|
2319
|
-
}
|
|
2320
|
-
const { data } = await fetcher.json(commentPath(ref), { signal: options?.signal });
|
|
2321
|
-
return toComment(thread, data);
|
|
2322
|
-
}
|
|
2323
|
-
async function getReview(ref, options) {
|
|
2324
|
-
const pull = requirePull(ref.thread, "reviewed");
|
|
2325
|
-
const path = `${threadPath(pull)}/reviews/${encodeURIComponent(ref.id)}`;
|
|
2326
|
-
const [{ data }, comments, byComment] = await Promise.all([
|
|
2327
|
-
fetcher.json(path, { signal: options?.signal }),
|
|
2328
|
-
Array.fromAsync(fetcher.items(`${path}/comments`, {
|
|
2329
|
-
query: { per_page: 100 },
|
|
2330
|
-
signal: options?.signal
|
|
2331
|
-
})),
|
|
2332
|
-
reviewThreadsByComment(pull, options)
|
|
2333
|
-
]);
|
|
2334
|
-
return toReview(pull, data, comments.map((comment) => toReviewComment(pull, comment, byComment.get(String(comment.id)))));
|
|
2335
|
-
}
|
|
2336
|
-
async function getCheck(ref, options) {
|
|
2337
|
-
if (ref.type !== "check_run") throw new UnsupportedOperationError(`GitHub cannot read a ${ref.type} by id; only check runs can be read on their own`, context);
|
|
2338
|
-
const { data } = await fetcher.json(`${repoPath(ref.repo)}/check-runs/${encodeURIComponent(ref.id)}`, { signal: options?.signal });
|
|
2339
|
-
return toCheckRun(ref.repo, data);
|
|
2340
|
-
}
|
|
2341
|
-
async function getJob(ref, options) {
|
|
2342
|
-
const { data } = await fetcher.json(`${repoPath(ref.repo)}/actions/jobs/${encodeURIComponent(ref.id)}`, { signal: options?.signal });
|
|
2343
|
-
const run = ref.run ?? (data.run_id === void 0 ? void 0 : {
|
|
2344
|
-
forge: "github",
|
|
2345
|
-
instance,
|
|
2346
|
-
repo: ref.repo,
|
|
2347
|
-
id: String(data.run_id)
|
|
2348
|
-
});
|
|
2349
|
-
if (!run) throw new UnsupportedOperationError(`GitHub returned job ${ref.id} without its run, and the ref names no run`, context);
|
|
2350
|
-
return toWorkflowJob(run, data);
|
|
2351
|
-
}
|
|
2352
|
-
async function subscriptionNode(thread, options) {
|
|
2353
|
-
const ref = requireThread(thread, context);
|
|
2354
|
-
if (ref.kind !== "issue" && ref.kind !== "pull_request" && ref.kind !== "discussion") throw new UnsupportedOperationError(`GitHub has no subscription for a ${ref.kind}`, context);
|
|
2355
|
-
const data = await graphql("SUBSCRIPTION_STATE", {
|
|
2356
|
-
owner: ref.repo.owner,
|
|
2357
|
-
name: ref.repo.name,
|
|
2358
|
-
number: Number(ref.number),
|
|
2359
|
-
discussion: ref.kind === "discussion"
|
|
2360
|
-
}, options);
|
|
2361
|
-
const node = ref.kind === "discussion" ? data.repository?.discussion : data.repository?.issueOrPullRequest;
|
|
2362
|
-
if (!node) throw new NotFoundError(`Thread ${ref.number} not found`, 404, "", context);
|
|
2363
|
-
return {
|
|
2364
|
-
id: node.id,
|
|
2365
|
-
state: node.viewerSubscription
|
|
2366
|
-
};
|
|
2367
|
-
}
|
|
2368
|
-
async function closingPage(ref, document, listOptions) {
|
|
2369
|
-
const [data, { toGraphQLThread }] = await Promise.all([graphql(document, {
|
|
2370
|
-
owner: ref.repo.owner,
|
|
2371
|
-
name: ref.repo.name,
|
|
2372
|
-
number: Number(ref.number),
|
|
2373
|
-
first: Math.min(listOptions.perPage ?? 50, 100),
|
|
2374
|
-
after: listOptions.cursor?.token ?? null
|
|
2375
|
-
}, listOptions), import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js")]);
|
|
2376
|
-
const references = data.repository?.thread?.references;
|
|
2377
|
-
if (!references) throw new NotFoundError(`Thread ${ref.number} not found`, 404, "", context);
|
|
2378
|
-
return {
|
|
2379
|
-
items: references.nodes.map((node) => {
|
|
2380
|
-
const repo = {
|
|
2381
|
-
forge: FORGE,
|
|
2382
|
-
instance,
|
|
2383
|
-
owner: node.repository.owner.login,
|
|
2384
|
-
name: node.repository.name,
|
|
2385
|
-
externalId: node.repository.databaseId === void 0 ? void 0 : String(node.repository.databaseId)
|
|
2386
|
-
};
|
|
2387
|
-
return toGraphQLThread({
|
|
2388
|
-
forge: FORGE,
|
|
2389
|
-
instance,
|
|
2390
|
-
repo,
|
|
2391
|
-
kind: node.__typename === "PullRequest" ? "pull_request" : "issue",
|
|
2392
|
-
number: String(node.number)
|
|
2393
|
-
}, node);
|
|
2394
|
-
}),
|
|
2395
|
-
cursor: references.pageInfo.hasNextPage && references.pageInfo.endCursor ? { token: references.pageInfo.endCursor } : void 0
|
|
2396
|
-
};
|
|
2397
|
-
}
|
|
2398
|
-
async function setSubscription(thread, state, options) {
|
|
2399
|
-
const { id } = await subscriptionNode(thread, options);
|
|
2400
|
-
await graphql("UPDATE_SUBSCRIPTION", {
|
|
2401
|
-
id,
|
|
2402
|
-
state
|
|
2403
|
-
}, options);
|
|
2404
|
-
}
|
|
2405
|
-
async function reposPage(repoFetcher, path, wrapped, listOptions = {}) {
|
|
2406
|
-
return toPage(await repoFetcher.page(path, {
|
|
2407
|
-
query: { per_page: listOptions.perPage },
|
|
2408
|
-
cursor: listOptions.cursor,
|
|
2409
|
-
signal: listOptions.signal,
|
|
2410
|
-
select: wrapped ? (body, next) => ({
|
|
2411
|
-
items: body.repositories,
|
|
2412
|
-
next
|
|
2413
|
-
}) : void 0
|
|
2414
|
-
}), (raw) => toRepo(instance, raw));
|
|
2415
|
-
}
|
|
2416
|
-
/** The authenticated login, read once and reused; reactions are deleted by id, so removing one needs it. */
|
|
2417
|
-
const viewerLogin = memo(async () => (await fetcher.json("/user")).data.login);
|
|
2418
|
-
/** `/users/{owner}/repos` serves organisations too, but lists only public repositories. */
|
|
2419
|
-
async function ownerReposPage(owner, query = {}) {
|
|
2420
|
-
const visibility = query.visibility === "all" ? void 0 : query.visibility;
|
|
2421
|
-
const read = (path, params) => list(path, query, (raw) => toRepo(instance, raw), { query: {
|
|
2422
|
-
...params,
|
|
2423
|
-
sort: query.sort === "name" ? "full_name" : query.sort,
|
|
2424
|
-
direction: query.direction
|
|
2425
|
-
} });
|
|
2426
|
-
const userRepos = () => read(`/users/${encodeURIComponent(owner.owner)}/repos`, { type: "owner" });
|
|
2427
|
-
if (visibility === "public") return userRepos();
|
|
2428
|
-
try {
|
|
2429
|
-
return await read(`/orgs/${encodeURIComponent(owner.owner)}/repos`, { type: visibility === "internal" ? void 0 : visibility });
|
|
2430
|
-
} catch (error) {
|
|
2431
|
-
if (!(error instanceof NotFoundError) || !isFirstPage(query.cursor)) throw error;
|
|
2432
|
-
}
|
|
2433
|
-
if (auth.type === "token" && !installation && (await viewerLogin()).toLowerCase() === owner.owner.toLowerCase()) return read("/user/repos", {
|
|
2434
|
-
affiliation: "owner",
|
|
2435
|
-
visibility: visibility === "internal" ? void 0 : visibility
|
|
2436
|
-
});
|
|
2437
|
-
if (visibility) return {
|
|
2438
|
-
items: [],
|
|
2439
|
-
warnings: [{
|
|
2440
|
-
code: "filter_unsupported",
|
|
2441
|
-
message: "GitHub lists only the public repositories of another user"
|
|
2442
|
-
}]
|
|
2443
|
-
};
|
|
2444
|
-
return userRepos();
|
|
2445
|
-
}
|
|
2446
|
-
/** Repository hooks, or organisation hooks for a namespace ref. */
|
|
2447
|
-
function hooksPath(target) {
|
|
2448
|
-
return isNamespaceRef(target) ? `/orgs/${encodeURIComponent(target.owner)}/hooks` : `${repoPath(target)}/hooks`;
|
|
2449
|
-
}
|
|
2450
|
-
function hookConfig(input) {
|
|
2451
|
-
return {
|
|
2452
|
-
...input.url ? { url: input.url } : {},
|
|
2453
|
-
content_type: input.contentType ?? "json",
|
|
2454
|
-
...input.secret ? { secret: input.secret } : {}
|
|
2455
|
-
};
|
|
2456
|
-
}
|
|
2457
|
-
/**
|
|
2458
|
-
* The hook endpoints respond with `404` when the credential lacks
|
|
2459
|
-
* `admin:repo_hook` or `admin:org_hook`, so the status alone is misleading.
|
|
2460
|
-
*/
|
|
2461
|
-
function scopeIs404(error) {
|
|
2462
|
-
if (error instanceof NotFoundError) return new ForbiddenError("GitHub responded with 404 for a webhook endpoint, which it also does when the credential lacks admin:repo_hook or admin:org_hook", 404, error.body, "resource_protected", {
|
|
2463
|
-
forge: error.forge,
|
|
2464
|
-
instance: error.instance,
|
|
2465
|
-
url: error.url,
|
|
2466
|
-
method: error.method,
|
|
2467
|
-
reasonRaw: "hook_scope_404"
|
|
2468
|
-
}, { cause: error });
|
|
2469
|
-
return error;
|
|
2470
|
-
}
|
|
2471
|
-
/** GitHub responds with `403` to a re-request of another app's check run, and names a missing permission as `Resource not accessible by ...`. */
|
|
2472
|
-
function notOwnerOfCheckRun(error) {
|
|
2473
|
-
if (error.acceptedScopes?.length && !error.acceptedScopes.some((scope) => error.grantedScopes?.includes(scope)) || /not accessible by/i.test(error.body)) return error;
|
|
2474
|
-
return new ForbiddenError("GitHub refused to re-request a check run that another app created", error.status, error.body, "not_owner", {
|
|
2475
|
-
forge: error.forge,
|
|
2476
|
-
instance: error.instance,
|
|
2477
|
-
url: error.url,
|
|
2478
|
-
method: error.method
|
|
2479
|
-
}, { cause: error });
|
|
2480
|
-
}
|
|
2481
|
-
/** GitHub responds with `422` to a change of the tag, target or draft state of an immutable release. */
|
|
2482
|
-
function immutableReleaseIs422(error) {
|
|
2483
|
-
if (!(error instanceof ForgeApiError) || error.constructor !== ForgeApiError || error.status !== 422) return error;
|
|
2484
|
-
const reasonRaw = error.body.match(/\w+ cannot be changed when release is immutable/)?.[0];
|
|
2485
|
-
if (!reasonRaw) return error;
|
|
2486
|
-
return new ForbiddenError("GitHub refused the change because the release is immutable", error.status, error.body, "immutable_release", {
|
|
2487
|
-
forge: error.forge,
|
|
2488
|
-
instance: error.instance,
|
|
2489
|
-
url: error.url,
|
|
2490
|
-
method: error.method,
|
|
2491
|
-
reasonRaw
|
|
2492
|
-
}, { cause: error });
|
|
2493
|
-
}
|
|
2494
|
-
/** GitHub search qualifiers, in the order the docs list them. */
|
|
2495
|
-
function searchQualifiers(query) {
|
|
2496
|
-
const qualifiers = [];
|
|
2497
|
-
const advanced = !query.kind;
|
|
2498
|
-
/** In advanced search a bare `OR` binds looser than the other qualifiers, so caller syntax is grouped. */
|
|
2499
|
-
const group = (value) => advanced ? `(${value})` : value;
|
|
2500
|
-
const text = advanced && query.text ? advancedFreeText(query.text) : query.text;
|
|
2501
|
-
if (text) qualifiers.push(group(text));
|
|
2502
|
-
if (query.repo) qualifiers.push(`repo:${query.repo.owner}/${query.repo.name}`);
|
|
2503
|
-
else if (query.owner) qualifiers.push(`user:${query.owner}`);
|
|
2504
|
-
qualifiers.push(query.kind ? query.kind === "pull_request" ? "is:pr" : "is:issue" : "(is:issue OR is:pr)");
|
|
2505
|
-
if (query.state && query.state !== "all") qualifiers.push(`state:${query.state}`);
|
|
2506
|
-
for (const [name, value] of [
|
|
2507
|
-
["author", query.author],
|
|
2508
|
-
["involves", query.involves],
|
|
2509
|
-
["assignee", query.assignee]
|
|
2510
|
-
]) if (value) qualifiers.push(`${name}:${value}`);
|
|
2511
|
-
for (const label of query.labels ?? []) qualifiers.push(`label:"${label}"`);
|
|
2512
|
-
if (query.since) qualifiers.push(`updated:>=${query.since.toISOString()}`);
|
|
2513
|
-
if (query.queryRaw) qualifiers.push(group(query.queryRaw));
|
|
2514
|
-
return qualifiers;
|
|
2515
|
-
}
|
|
2516
|
-
/**
|
|
2517
|
-
* GitHub requires a kind in issue search; naming both needs advanced search.
|
|
2518
|
-
* GitHub Enterprise Server may predate it, and GitHub App user access tokens
|
|
2519
|
-
* can't search both kinds at once, so those read issues, then pull requests.
|
|
2520
|
-
*/
|
|
2521
|
-
async function searchThreadsPage(query) {
|
|
2522
|
-
if (!query.kind && (enterprise || auth.type === "token" && tokenKindOf(auth, await resolveToken(auth)) === "app-user")) return phased(["issue", "pull_request"].map((kind) => (cursor) => searchIssuesPage({
|
|
2523
|
-
...query,
|
|
2524
|
-
kind,
|
|
2525
|
-
cursor
|
|
2526
|
-
})), query.cursor);
|
|
2527
|
-
return searchIssuesPage(query);
|
|
2528
|
-
}
|
|
2529
|
-
async function searchIssuesPage(query) {
|
|
2530
|
-
const result = await fetcher.page("/search/issues", {
|
|
2531
|
-
query: {
|
|
2532
|
-
q: searchQualifiers(query).join(" "),
|
|
2533
|
-
advanced_search: query.kind ? void 0 : "true",
|
|
2534
|
-
sort: query.sort && query.sort !== "relevance" ? query.sort : void 0,
|
|
2535
|
-
order: query.direction,
|
|
2536
|
-
per_page: query.perPage
|
|
2537
|
-
},
|
|
2538
|
-
cursor: query.cursor,
|
|
2539
|
-
signal: query.signal,
|
|
2540
|
-
select: (body, next) => {
|
|
2541
|
-
const { items, total_count } = body;
|
|
2542
|
-
return {
|
|
2543
|
-
items,
|
|
2544
|
-
next,
|
|
2545
|
-
total: total_count
|
|
2546
|
-
};
|
|
2547
|
-
}
|
|
2548
|
-
});
|
|
2549
|
-
return toPage(result, (raw) => {
|
|
2550
|
-
const repo = query.repo ?? repoRefFromApiUrl(instance, raw.repository_url);
|
|
2551
|
-
if (!repo) return;
|
|
2552
|
-
const isPull = Boolean(raw.pull_request);
|
|
2553
|
-
return toThread({
|
|
2554
|
-
forge: FORGE,
|
|
2555
|
-
instance,
|
|
2556
|
-
repo,
|
|
2557
|
-
kind: isPull ? "pull_request" : "issue",
|
|
2558
|
-
number: String(raw.number)
|
|
2559
|
-
}, raw);
|
|
2560
|
-
});
|
|
2561
|
-
}
|
|
2562
|
-
function milestonesPage(repo, listOptions = {}) {
|
|
2563
|
-
return list(`${repoPath(repo)}/milestones`, listOptions, (raw) => toMilestone(raw), { query: { state: listOptions.state ?? "open" } });
|
|
2564
|
-
}
|
|
2565
|
-
async function contributorStats(repo, statsOptions = {}) {
|
|
2566
|
-
const path = `${repoPath(repo)}/stats/contributors`;
|
|
2567
|
-
for (let attempt = 0;; attempt++) {
|
|
2568
|
-
const { data, response } = await fetcher.json(path, { signal: statsOptions.signal });
|
|
2569
|
-
if (response.status !== 202) return (data ?? []).map((raw) => toContributorStats(instance, raw));
|
|
2570
|
-
if (attempt >= CONTRIBUTOR_STATS_DELAYS.length) throw new ForgeApiError(`GitHub is still computing the contributor statistics of ${repo.owner}/${repo.name}`, 202, "", {
|
|
2571
|
-
...context,
|
|
2572
|
-
url: fetcher.resolve(path),
|
|
2573
|
-
method: "GET"
|
|
2574
|
-
});
|
|
2575
|
-
await sleep(CONTRIBUTOR_STATS_DELAYS[attempt], statsOptions.signal);
|
|
2576
|
-
}
|
|
2577
|
-
}
|
|
2578
|
-
const REPO_SEARCH_SORTS = {
|
|
2579
|
-
updated: "updated",
|
|
2580
|
-
stars: "stars"
|
|
2581
|
-
};
|
|
2582
|
-
async function searchReposPage(query) {
|
|
2583
|
-
const qualifiers = [
|
|
2584
|
-
query.text,
|
|
2585
|
-
query.owner && `user:${query.owner}`,
|
|
2586
|
-
query.language && `language:${query.language}`,
|
|
2587
|
-
query.queryRaw
|
|
2588
|
-
].filter(Boolean);
|
|
2589
|
-
const warnings = query.sort === "created" ? [{
|
|
2590
|
-
code: "sort_unsupported",
|
|
2591
|
-
message: "GitHub repository search cannot sort by creation time; sorted by relevance"
|
|
2592
|
-
}] : [];
|
|
2593
|
-
const result = await fetcher.page("/search/repositories", {
|
|
2594
|
-
query: {
|
|
2595
|
-
q: qualifiers.join(" "),
|
|
2596
|
-
sort: query.sort ? REPO_SEARCH_SORTS[query.sort] : void 0,
|
|
2597
|
-
order: query.direction,
|
|
2598
|
-
per_page: query.perPage
|
|
2599
|
-
},
|
|
2600
|
-
cursor: query.cursor,
|
|
2601
|
-
signal: query.signal,
|
|
2602
|
-
select: (body, next) => {
|
|
2603
|
-
const { items, total_count } = body;
|
|
2604
|
-
return {
|
|
2605
|
-
items,
|
|
2606
|
-
next,
|
|
2607
|
-
total: total_count
|
|
2608
|
-
};
|
|
2609
|
-
}
|
|
2610
|
-
});
|
|
2611
|
-
return toPage(result, (raw) => toRepo(instance, raw), warnings);
|
|
2612
|
-
}
|
|
2613
|
-
const COMMIT_SEARCH_SORTS = {
|
|
2614
|
-
author_date: "author-date",
|
|
2615
|
-
committer_date: "committer-date"
|
|
2616
|
-
};
|
|
2617
|
-
async function searchCommitsPage(query) {
|
|
2618
|
-
const qualifiers = [
|
|
2619
|
-
query.text,
|
|
2620
|
-
query.repo && `repo:${query.repo.owner}/${query.repo.name}`,
|
|
2621
|
-
query.author && `author:${query.author}`,
|
|
2622
|
-
query.committer && `committer:${query.committer}`,
|
|
2623
|
-
query.since && `author-date:>=${query.since.toISOString()}`,
|
|
2624
|
-
query.until && `author-date:<=${query.until.toISOString()}`,
|
|
2625
|
-
query.queryRaw
|
|
2626
|
-
].filter(Boolean);
|
|
2627
|
-
const result = await fetcher.page("/search/commits", {
|
|
2628
|
-
query: {
|
|
2629
|
-
q: qualifiers.join(" "),
|
|
2630
|
-
sort: query.sort && COMMIT_SEARCH_SORTS[query.sort],
|
|
2631
|
-
order: query.direction,
|
|
2632
|
-
per_page: query.perPage
|
|
2633
|
-
},
|
|
2634
|
-
cursor: query.cursor,
|
|
2635
|
-
signal: query.signal,
|
|
2636
|
-
select: (body, next) => {
|
|
2637
|
-
const { items, total_count } = body;
|
|
2638
|
-
return {
|
|
2639
|
-
items,
|
|
2640
|
-
next,
|
|
2641
|
-
total: total_count
|
|
2642
|
-
};
|
|
2643
|
-
}
|
|
2644
|
-
});
|
|
2645
|
-
return toPage(result, (raw) => {
|
|
2646
|
-
const repo = query.repo ?? (raw.repository && toRepoRef(instance, raw.repository));
|
|
2647
|
-
return repo && toCommit(repo, raw);
|
|
2648
|
-
});
|
|
2649
|
-
}
|
|
2650
|
-
/** The excerpts only come with the text match media type. */
|
|
2651
|
-
async function searchCodePage(query) {
|
|
2652
|
-
const qualifiers = [
|
|
2653
|
-
query.text,
|
|
2654
|
-
query.repo ? `repo:${query.repo.owner}/${query.repo.name}` : query.owner && `user:${query.owner}`,
|
|
2655
|
-
query.queryRaw
|
|
2656
|
-
].filter(Boolean);
|
|
2657
|
-
let incomplete = false;
|
|
2658
|
-
const result = await fetcher.page("/search/code", {
|
|
2659
|
-
query: {
|
|
2660
|
-
q: qualifiers.join(" "),
|
|
2661
|
-
per_page: query.perPage
|
|
2662
|
-
},
|
|
2663
|
-
headers: { accept: "application/vnd.github.text-match+json" },
|
|
2664
|
-
cursor: query.cursor,
|
|
2665
|
-
signal: query.signal,
|
|
2666
|
-
select: (body, next) => {
|
|
2667
|
-
const { items, incomplete_results, total_count } = body;
|
|
2668
|
-
incomplete = incomplete_results === true;
|
|
2669
|
-
return {
|
|
2670
|
-
items,
|
|
2671
|
-
next,
|
|
2672
|
-
total: total_count
|
|
2673
|
-
};
|
|
2674
|
-
}
|
|
2675
|
-
});
|
|
2676
|
-
return toPage(result, (raw) => ({
|
|
2677
|
-
repo: query.repo ?? toRepoRef(instance, raw.repository),
|
|
2678
|
-
path: raw.path,
|
|
2679
|
-
ref: new URL(raw.url).searchParams.get("ref") ?? void 0,
|
|
2680
|
-
fragments: (raw.text_matches ?? []).filter((match) => match.property === "content").map((match) => ({ text: match.fragment })),
|
|
2681
|
-
url: raw.html_url,
|
|
2682
|
-
raw
|
|
2683
|
-
}), incomplete ? [{
|
|
2684
|
-
code: "search_incomplete",
|
|
2685
|
-
message: "GitHub stopped the search before it finished; the page may be missing matches"
|
|
2686
|
-
}] : []);
|
|
2687
|
-
}
|
|
2688
|
-
async function feedPage(path, listOptions = {}) {
|
|
2689
|
-
const throttled = throttledPage(path, listOptions, "this feed");
|
|
2690
|
-
if (throttled) return throttled;
|
|
2691
|
-
const result = await fetcher.page(path, {
|
|
2692
|
-
query: { per_page: listOptions.perPage },
|
|
2693
|
-
cursor: listOptions.cursor,
|
|
2694
|
-
signal: listOptions.signal
|
|
2695
|
-
});
|
|
2696
|
-
const poll = recordPoll(path, listOptions.cursor, result.response);
|
|
2697
|
-
const { toFeedEvents } = await import("./events-CeChclTf-CX-gD8oy-4aL2j6V-.js");
|
|
2698
|
-
const page = toPage(result, (raw) => toFeedEvents(instance, raw));
|
|
2699
|
-
return {
|
|
2700
|
-
...page,
|
|
2701
|
-
items: page.items.flat(),
|
|
2702
|
-
...poll
|
|
2703
|
-
};
|
|
2704
|
-
}
|
|
2705
|
-
function createInstallationsApi(app) {
|
|
2706
|
-
const appFetcher = createFetcher({
|
|
2707
|
-
baseUrl,
|
|
2708
|
-
authHeaders: async () => ({ authorization: `Bearer ${await app.appJwt()}` })
|
|
2709
|
-
});
|
|
2710
|
-
const auth = options.auth;
|
|
2711
|
-
function toInstallation(raw) {
|
|
2712
|
-
return {
|
|
2713
|
-
forge: FORGE,
|
|
2714
|
-
instance,
|
|
2715
|
-
id: String(raw.id),
|
|
2716
|
-
account: toActor(instance, raw.account),
|
|
2717
|
-
targetTypeRaw: raw.target_type,
|
|
2718
|
-
repositorySelectionRaw: raw.repository_selection,
|
|
2719
|
-
raw
|
|
2720
|
-
};
|
|
2721
|
-
}
|
|
2722
|
-
function provider(installation) {
|
|
2723
|
-
return derive({
|
|
2724
|
-
...options,
|
|
2725
|
-
auth: {
|
|
2726
|
-
...auth,
|
|
2727
|
-
installationId: installationId(installation)
|
|
2728
|
-
}
|
|
2729
|
-
}, app);
|
|
2730
|
-
}
|
|
2731
|
-
async function listPage(listOptions = {}) {
|
|
2732
|
-
return toPage(await appFetcher.page("/app/installations", {
|
|
2733
|
-
query: { per_page: listOptions.perPage },
|
|
2734
|
-
cursor: listOptions.cursor,
|
|
2735
|
-
signal: listOptions.signal
|
|
2736
|
-
}), toInstallation);
|
|
2737
|
-
}
|
|
2738
|
-
return {
|
|
2739
|
-
listPage,
|
|
2740
|
-
async get(installation, options) {
|
|
2741
|
-
return toInstallation((await appFetcher.json(`/app/installations/${installationId(installation)}`, { signal: options?.signal })).data);
|
|
2742
|
-
},
|
|
2743
|
-
token: (installation, options) => app.installationTokenDetails(installationId(installation), options),
|
|
2744
|
-
reposPage(installation, listOptions) {
|
|
2745
|
-
const id = installationId(installation);
|
|
2746
|
-
return reposPage(createFetcher({
|
|
2747
|
-
baseUrl,
|
|
2748
|
-
authHeaders: async () => ({ authorization: `Bearer ${await app.installationToken(id)}` })
|
|
2749
|
-
}), "/installation/repositories", true, listOptions);
|
|
2750
|
-
},
|
|
2751
|
-
provider,
|
|
2752
|
-
providers() {
|
|
2753
|
-
return forgeIterable(async function* () {
|
|
2754
|
-
for await (const installation of iteratePages(listPage)) yield {
|
|
2755
|
-
installation,
|
|
2756
|
-
provider: provider(installation)
|
|
2757
|
-
};
|
|
2758
|
-
});
|
|
2759
|
-
}
|
|
2760
|
-
};
|
|
2761
|
-
}
|
|
2762
|
-
/** github.com serves file bytes from a CDN outside the REST API rate limit. */
|
|
2763
|
-
const rawFetcher = host === "api.github.com" ? createFetcher({
|
|
2764
|
-
baseUrl: "https://raw.githubusercontent.com",
|
|
2765
|
-
authHeaders: createAuthHeaders(options.auth, credentials)
|
|
2766
|
-
}) : void 0;
|
|
2767
|
-
async function readFile(repo, path, fileOptions = {}) {
|
|
2768
|
-
const encoded = path.split("/").map(encodeURIComponent).join("/");
|
|
2769
|
-
if (fileOptions.metadata === false && rawFetcher) {
|
|
2770
|
-
const response = await rawFetcher.raw(`/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.name)}/${encodeURIComponent(fileOptions.ref ?? "HEAD")}/${encoded}`, { signal: fileOptions.signal });
|
|
2771
|
-
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
2772
|
-
return toFileContent(bytes, {
|
|
2773
|
-
path,
|
|
2774
|
-
size: bytes.byteLength
|
|
2775
|
-
}, fileOptions, context);
|
|
2776
|
-
}
|
|
2777
|
-
const { data } = await fetcher.json(`${repoPath(repo)}/contents/${encoded}`, {
|
|
2778
|
-
query: { ref: fileOptions.ref },
|
|
2779
|
-
signal: fileOptions.signal
|
|
2780
|
-
});
|
|
2781
|
-
const file = {
|
|
2782
|
-
path: data.path,
|
|
2783
|
-
sha: data.sha,
|
|
2784
|
-
size: data.size,
|
|
2785
|
-
url: data.html_url ?? void 0
|
|
2786
|
-
};
|
|
2787
|
-
const content = data.encoding === "base64" && data.content !== void 0 ? data.content : (await fetcher.json(`${repoPath(repo)}/git/blobs/${data.sha}`, { signal: fileOptions.signal })).data.content;
|
|
2788
|
-
return toFileContent(fromBase64(content), file, fileOptions, context);
|
|
2789
|
-
}
|
|
2790
|
-
async function templates(repo, options = {}) {
|
|
2791
|
-
const signal = options.signal;
|
|
2792
|
-
return (await import("./templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js")).readTemplates(repo, options.kind ? [options.kind] : ["issue", "pull_request"], {
|
|
2793
|
-
list: async (ref, path) => {
|
|
2794
|
-
const { data } = await fetcher.json(`${repoPath(ref)}/contents${path ? `/${path.split("/").map(encodeURIComponent).join("/")}` : ""}`, { signal });
|
|
2795
|
-
return Array.isArray(data) ? data : [];
|
|
2796
|
-
},
|
|
2797
|
-
read: async (ref, path) => (await readFile(ref, path, {
|
|
2798
|
-
as: "text",
|
|
2799
|
-
signal
|
|
2800
|
-
})).content,
|
|
2801
|
-
repository: async (ref) => (await fetcher.json(repoPath(ref), { signal })).data
|
|
2802
|
-
});
|
|
2803
|
-
}
|
|
2804
|
-
async function treePage(repo, treeOptions = {}) {
|
|
2805
|
-
const ref = treeOptions.ref ?? "HEAD";
|
|
2806
|
-
const target = treeOptions.path ? `${ref}:${treeOptions.path.replace(/^\/|\/$/g, "")}` : ref;
|
|
2807
|
-
const { data, response } = await fetcher.json(`${repoPath(repo)}/git/trees/${encodeURIComponent(target)}`, {
|
|
2808
|
-
query: treeOptions.recursive ? { recursive: "1" } : {},
|
|
2809
|
-
signal: treeOptions.signal
|
|
2810
|
-
});
|
|
2811
|
-
const warnings = data.truncated ? [{
|
|
2812
|
-
code: "tree_truncated",
|
|
2813
|
-
message: "GitHub truncated the tree; read it directory by directory instead",
|
|
2814
|
-
subject: target
|
|
2815
|
-
}] : [];
|
|
2816
|
-
return toPage({
|
|
2817
|
-
data: data.tree,
|
|
2818
|
-
response,
|
|
2819
|
-
notModified: false
|
|
2820
|
-
}, toTreeEntry, warnings);
|
|
2821
|
-
}
|
|
2822
|
-
async function compare(repo, base, head, options = {}) {
|
|
2823
|
-
const path = `${repoPath(repo)}/compare/${encodeURIComponent(base)}...${encodeURIComponent(head)}`;
|
|
2824
|
-
const limit = options.commitLimit;
|
|
2825
|
-
const perPage = limit === void 0 ? void 0 : Math.min(100, Math.max(1, limit));
|
|
2826
|
-
const { data } = await fetcher.json(path, {
|
|
2827
|
-
query: { per_page: perPage },
|
|
2828
|
-
signal: options.signal
|
|
2829
|
-
});
|
|
2830
|
-
let commits = data.commits ?? [];
|
|
2831
|
-
const total = data.total_commits ?? data.ahead_by;
|
|
2832
|
-
if (limit !== void 0 && perPage !== void 0 && total !== void 0 && total > commits.length) {
|
|
2833
|
-
const first = Math.floor(Math.max(0, total - limit) / perPage) + 1;
|
|
2834
|
-
const pages = Array.from({ length: Math.ceil(total / perPage) - first + 1 }, (_, index) => first + index);
|
|
2835
|
-
commits = (await Promise.all(pages.map(async (page) => page === 1 ? commits : (await fetcher.json(path, {
|
|
2836
|
-
query: {
|
|
2837
|
-
per_page: perPage,
|
|
2838
|
-
page
|
|
2839
|
-
},
|
|
2840
|
-
signal: options.signal
|
|
2841
|
-
})).data.commits ?? []))).flat();
|
|
2842
|
-
}
|
|
2843
|
-
return {
|
|
2844
|
-
base,
|
|
2845
|
-
head,
|
|
2846
|
-
aheadBy: data.ahead_by,
|
|
2847
|
-
behindBy: data.behind_by,
|
|
2848
|
-
mergeBaseSha: data.merge_base_commit?.sha,
|
|
2849
|
-
commits: commits.map((raw) => toCommit(repo, raw)).toReversed(),
|
|
2850
|
-
files: (data.files ?? []).map(toChangedFile),
|
|
2851
|
-
raw: data
|
|
2852
|
-
};
|
|
2853
|
-
}
|
|
2854
|
-
async function commitsPage(repo, query = {}) {
|
|
2855
|
-
return list(`${repoPath(repo)}/commits`, query, (raw) => toCommit(repo, raw), { query: {
|
|
2856
|
-
sha: query.ref,
|
|
2857
|
-
path: query.path,
|
|
2858
|
-
author: query.author,
|
|
2859
|
-
since: query.since?.toISOString(),
|
|
2860
|
-
until: query.until?.toISOString()
|
|
2861
|
-
} });
|
|
2862
|
-
}
|
|
2863
|
-
async function releasesPage(repo, listOptions = {}) {
|
|
2864
|
-
return list(`${repoPath(repo)}/releases`, listOptions, (raw) => toRelease(repo, raw));
|
|
2865
|
-
}
|
|
2866
|
-
/** The commit that `input` builds on: `createFrom` resolved, `expectedHead`, or the head of the branch. */
|
|
2867
|
-
async function commitParent(repo, input, options) {
|
|
2868
|
-
if (input.createFrom !== void 0) return isSha(input.createFrom) ? input.createFrom : (await fetcher.json(`${repoPath(repo)}/commits/${encodeURIComponent(input.createFrom)}`, { signal: options?.signal })).data.sha;
|
|
2869
|
-
return input.expectedHead ?? (await fetcher.json(`${repoPath(repo)}/git/ref/heads/${branchPath(input.branch)}`, { signal: options?.signal })).data.object.sha;
|
|
2870
|
-
}
|
|
2871
|
-
/** Moves `branch` from `before` to `after` only if it is still at `before`. The zero oid stands for a branch that does not exist. */
|
|
2872
|
-
async function swapBranch(repo, branch, before, after, options) {
|
|
2873
|
-
const { repository } = await graphql("REPOSITORY_ID", {
|
|
2874
|
-
owner: repo.owner,
|
|
2875
|
-
name: repo.name
|
|
2876
|
-
}, options);
|
|
2877
|
-
if (!repository) throw new NotFoundError(`${repo.owner}/${repo.name} does not exist`, 404, "", context);
|
|
2878
|
-
await graphql("UPDATE_REFS", { input: {
|
|
2879
|
-
repositoryId: repository.id,
|
|
2880
|
-
refUpdates: [{
|
|
2881
|
-
name: `refs/heads/${branch}`,
|
|
2882
|
-
beforeOid: before,
|
|
2883
|
-
afterOid: after
|
|
2884
|
-
}]
|
|
2885
|
-
} }, options);
|
|
2886
|
-
}
|
|
2887
|
-
/** One `createCommitOnBranch` mutation, which GitHub signs and attributes to the credential's account. */
|
|
2888
|
-
async function commitOnBranch(repo, input, options) {
|
|
2889
|
-
const head = await commitParent(repo, input, options);
|
|
2890
|
-
if (input.createFrom !== void 0) await fetcher.json(`${repoPath(repo)}/git/refs`, {
|
|
2891
|
-
method: "POST",
|
|
2892
|
-
json: {
|
|
2893
|
-
ref: `refs/heads/${input.branch}`,
|
|
2894
|
-
sha: head
|
|
2895
|
-
},
|
|
2896
|
-
signal: options?.signal
|
|
2897
|
-
});
|
|
2898
|
-
const fileChanges = {
|
|
2899
|
-
additions: input.changes.flatMap((change) => change.content === null ? [] : [{
|
|
2900
|
-
path: change.path,
|
|
2901
|
-
contents: changeBase64(change.content)
|
|
2902
|
-
}]),
|
|
2903
|
-
deletions: input.changes.flatMap((change) => change.content === null ? [{ path: change.path }] : [])
|
|
2904
|
-
};
|
|
2905
|
-
try {
|
|
2906
|
-
const [data, { toGraphQLCommit }] = await Promise.all([graphql("CREATE_COMMIT_ON_BRANCH", { input: {
|
|
2907
|
-
branch: {
|
|
2908
|
-
repositoryNameWithOwner: `${repo.owner}/${repo.name}`,
|
|
2909
|
-
branchName: input.branch
|
|
2910
|
-
},
|
|
2911
|
-
expectedHeadOid: head,
|
|
2912
|
-
message: splitMessage(input.message),
|
|
2913
|
-
fileChanges
|
|
2914
|
-
} }, options), import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js")]);
|
|
2915
|
-
return toGraphQLCommit(repo, data.createCommitOnBranch.commit);
|
|
2916
|
-
} catch (error) {
|
|
2917
|
-
if (input.createFrom !== void 0) await swapBranch(repo, input.branch, head, ZERO_OID).catch(() => {});
|
|
2918
|
-
throw commitError(error);
|
|
2919
|
-
}
|
|
2920
|
-
}
|
|
2921
|
-
/** Blobs, a tree, a commit and a ref update through the Git database API, which can name an author. */
|
|
2922
|
-
async function commitTree(repo, input, options) {
|
|
2923
|
-
const signal = options?.signal;
|
|
2924
|
-
const parent = await commitParent(repo, input, options);
|
|
2925
|
-
const tree = async (directory) => (await fetcher.json(`${repoPath(repo)}/git/trees/${encodeURIComponent(directory ? `${parent}:${directory}` : parent)}`, { signal })).data;
|
|
2926
|
-
const root = memo(() => tree(""));
|
|
2927
|
-
const existing = await existingFiles(input.changes, inDirectories(async (directory) => {
|
|
2928
|
-
try {
|
|
2929
|
-
const data = directory ? await tree(directory) : await root();
|
|
2930
|
-
return new Map(data.tree.filter((entry) => entry.type === "blob").map((entry) => [directory ? `${directory}/${entry.path}` : entry.path, entry]));
|
|
2931
|
-
} catch (error) {
|
|
2932
|
-
if (error instanceof NotFoundError) return;
|
|
2933
|
-
throw error;
|
|
2934
|
-
}
|
|
2935
|
-
}), context);
|
|
2936
|
-
const entries = await Promise.all(input.changes.map(async ({ path, content }) => {
|
|
2937
|
-
const mode = existing.get(path)?.mode ?? "100644";
|
|
2938
|
-
if (content === null || typeof content === "string") return {
|
|
2939
|
-
path,
|
|
2940
|
-
mode,
|
|
2941
|
-
type: "blob",
|
|
2942
|
-
...content === null ? { sha: null } : { content }
|
|
2943
|
-
};
|
|
2944
|
-
const { data } = await fetcher.json(`${repoPath(repo)}/git/blobs`, {
|
|
2945
|
-
method: "POST",
|
|
2946
|
-
json: {
|
|
2947
|
-
content: changeBase64(content),
|
|
2948
|
-
encoding: "base64"
|
|
2949
|
-
},
|
|
2950
|
-
signal
|
|
2951
|
-
});
|
|
2952
|
-
return {
|
|
2953
|
-
path,
|
|
2954
|
-
mode,
|
|
2955
|
-
type: "blob",
|
|
2956
|
-
sha: data.sha
|
|
2957
|
-
};
|
|
2958
|
-
}));
|
|
2959
|
-
const { data: created } = await fetcher.json(`${repoPath(repo)}/git/trees`, {
|
|
2960
|
-
method: "POST",
|
|
2961
|
-
json: {
|
|
2962
|
-
base_tree: (await root()).sha,
|
|
2963
|
-
tree: entries
|
|
2964
|
-
},
|
|
2965
|
-
signal
|
|
2966
|
-
});
|
|
2967
|
-
const { data: commit } = await fetcher.json(`${repoPath(repo)}/git/commits`, {
|
|
2968
|
-
method: "POST",
|
|
2969
|
-
json: {
|
|
2970
|
-
message: input.message,
|
|
2971
|
-
tree: created.sha,
|
|
2972
|
-
parents: [parent],
|
|
2973
|
-
author: input.author
|
|
2974
|
-
},
|
|
2975
|
-
signal
|
|
2976
|
-
});
|
|
2977
|
-
try {
|
|
2978
|
-
await swapBranch(repo, input.branch, input.createFrom === void 0 ? parent : ZERO_OID, commit.sha, options);
|
|
2979
|
-
} catch (error) {
|
|
2980
|
-
if (input.createFrom !== void 0) throw error;
|
|
2981
|
-
const { data } = await fetcher.json(`${repoPath(repo)}/git/ref/heads/${branchPath(input.branch)}`, { signal });
|
|
2982
|
-
if (data.object.sha !== parent && error instanceof ForgeApiError) throw new BranchMovedError(`${input.branch} is at ${data.object.sha}, not ${parent}`, 409, error.body, context, { cause: error });
|
|
2983
|
-
throw error;
|
|
2984
|
-
}
|
|
2985
|
-
return toGitCommit(repo, commit);
|
|
2986
|
-
}
|
|
2987
|
-
async function writeRelease(repo, path, method, input, options) {
|
|
2988
|
-
const { data } = await fetcher.json(path, {
|
|
2989
|
-
method,
|
|
2990
|
-
json: {
|
|
2991
|
-
tag_name: input.tag,
|
|
2992
|
-
target_commitish: input.target,
|
|
2993
|
-
name: input.name,
|
|
2994
|
-
body: input.body,
|
|
2995
|
-
draft: input.draft,
|
|
2996
|
-
prerelease: input.prerelease
|
|
2997
|
-
},
|
|
2998
|
-
mapError: immutableReleaseIs422,
|
|
2999
|
-
signal: options?.signal
|
|
3000
|
-
});
|
|
3001
|
-
return toRelease(repo, data);
|
|
3002
|
-
}
|
|
3003
|
-
const ALERT_SOURCES = {
|
|
3004
|
-
dependency: {
|
|
3005
|
-
path: "dependabot/alerts",
|
|
3006
|
-
states: {
|
|
3007
|
-
open: "open",
|
|
3008
|
-
closed: "fixed,dismissed,auto_dismissed"
|
|
3009
|
-
},
|
|
3010
|
-
map: toDependabotAlert
|
|
3011
|
-
},
|
|
3012
|
-
code_scanning: {
|
|
3013
|
-
path: "code-scanning/alerts",
|
|
3014
|
-
states: {
|
|
3015
|
-
open: "open",
|
|
3016
|
-
closed: "closed"
|
|
3017
|
-
},
|
|
3018
|
-
map: toCodeScanningAlert
|
|
3019
|
-
},
|
|
3020
|
-
secret: {
|
|
3021
|
-
path: "secret-scanning/alerts",
|
|
3022
|
-
states: {
|
|
3023
|
-
open: "open",
|
|
3024
|
-
closed: "resolved"
|
|
3025
|
-
},
|
|
3026
|
-
map: toSecretScanningAlert
|
|
3027
|
-
},
|
|
3028
|
-
advisory: {
|
|
3029
|
-
path: "security-advisories",
|
|
3030
|
-
states: {
|
|
3031
|
-
open: void 0,
|
|
3032
|
-
closed: void 0
|
|
3033
|
-
},
|
|
3034
|
-
map: toRepositoryAdvisory
|
|
3035
|
-
}
|
|
3036
|
-
};
|
|
3037
|
-
async function alertsPage(repo, listOptions = {}) {
|
|
3038
|
-
const kinds = listOptions.kind ? [listOptions.kind] : Object.keys(ALERT_SOURCES);
|
|
3039
|
-
return phased(kinds.map((kind) => async (cursor) => {
|
|
3040
|
-
const source = ALERT_SOURCES[kind];
|
|
3041
|
-
const state = listOptions.state ?? "open";
|
|
3042
|
-
const filter = state === "all" ? void 0 : source.states[state];
|
|
3043
|
-
try {
|
|
3044
|
-
const result = await fetcher.page(`${repoPath(repo)}/${source.path}`, {
|
|
3045
|
-
query: {
|
|
3046
|
-
state: filter,
|
|
3047
|
-
per_page: listOptions.perPage
|
|
3048
|
-
},
|
|
3049
|
-
cursor,
|
|
3050
|
-
signal: listOptions.signal
|
|
3051
|
-
});
|
|
3052
|
-
return toPage(result, (raw) => {
|
|
3053
|
-
const alert = source.map(repo, raw);
|
|
3054
|
-
return filter || state === "all" || alert.state === "open" === (state === "open") ? alert : void 0;
|
|
3055
|
-
});
|
|
3056
|
-
} catch (error) {
|
|
3057
|
-
if (!listOptions.kind && (error instanceof InsufficientScopeError || error instanceof NotFoundError)) return {
|
|
3058
|
-
items: [],
|
|
3059
|
-
warnings: [toWarning(error instanceof InsufficientScopeError ? "insufficient_scope" : "alerts_unavailable", error, kind)]
|
|
3060
|
-
};
|
|
3061
|
-
throw error;
|
|
3062
|
-
}
|
|
3063
|
-
}), listOptions.cursor);
|
|
3064
|
-
}
|
|
3065
|
-
/** The GraphQL node id of an issue, pull request or discussion. */
|
|
3066
|
-
async function nodeId(thread, options) {
|
|
3067
|
-
const ref = requireThread(thread, context);
|
|
3068
|
-
return ref.externalId ?? (await subscriptionNode(ref, options)).id;
|
|
3069
|
-
}
|
|
3070
|
-
function reactionPath(target) {
|
|
3071
|
-
if ("thread" in target) return `${repoPath(target.thread.repo)}/issues/comments/${encodeURIComponent(target.id)}/reactions`;
|
|
3072
|
-
const ref = requireIssueOrPull(target, context, "react to");
|
|
3073
|
-
return `${repoPath(ref.repo)}/issues/${encodeURIComponent(ref.number)}/reactions`;
|
|
3074
|
-
}
|
|
3075
|
-
async function reactionsPage(target, listOptions = {}) {
|
|
3076
|
-
const thread = "thread" in target ? target.thread : target;
|
|
3077
|
-
if (thread.kind === "discussion") {
|
|
3078
|
-
const id = "thread" in target ? target.id : await nodeId(thread, listOptions);
|
|
3079
|
-
const [data, { toGraphQLActor, GRAPHQL_REACTIONS }] = await Promise.all([graphql("NODE_REACTIONS", {
|
|
3080
|
-
id,
|
|
3081
|
-
after: listOptions.cursor?.token ?? null
|
|
3082
|
-
}, listOptions), import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js")]);
|
|
3083
|
-
const reactions = data.node?.reactions;
|
|
3084
|
-
return {
|
|
3085
|
-
items: (reactions?.nodes ?? []).flatMap((raw) => {
|
|
3086
|
-
const actor = toGraphQLActor(instance, raw.user);
|
|
3087
|
-
return actor ? [{
|
|
3088
|
-
content: reactionContent(GRAPHQL_REACTIONS[raw.content] ?? raw.content),
|
|
3089
|
-
contentRaw: raw.content,
|
|
3090
|
-
actor,
|
|
3091
|
-
createdAt: toDate(raw.createdAt),
|
|
3092
|
-
raw
|
|
3093
|
-
}] : [];
|
|
3094
|
-
}),
|
|
3095
|
-
cursor: reactions?.pageInfo.hasNextPage && reactions.pageInfo.endCursor ? { token: reactions.pageInfo.endCursor } : void 0,
|
|
3096
|
-
...reactions?.totalCount !== void 0 ? { total: reactions.totalCount } : {}
|
|
3097
|
-
};
|
|
3098
|
-
}
|
|
3099
|
-
const result = await fetcher.page(reactionPath(target), {
|
|
3100
|
-
query: { per_page: listOptions.perPage },
|
|
3101
|
-
cursor: listOptions.cursor,
|
|
3102
|
-
signal: listOptions.signal
|
|
3103
|
-
});
|
|
3104
|
-
return toPage(result, (raw) => {
|
|
3105
|
-
const actor = toActor(instance, raw.user);
|
|
3106
|
-
return actor && {
|
|
3107
|
-
content: reactionContent(raw.content),
|
|
3108
|
-
contentRaw: raw.content,
|
|
3109
|
-
actor,
|
|
3110
|
-
createdAt: toDate(raw.created_at),
|
|
3111
|
-
raw
|
|
3112
|
-
};
|
|
3113
|
-
});
|
|
3114
|
-
}
|
|
3115
|
-
async function react(target, reaction, options) {
|
|
3116
|
-
const thread = "thread" in target ? target.thread : target;
|
|
3117
|
-
if (thread.kind === "discussion") {
|
|
3118
|
-
await graphql("ADD_REACTION", {
|
|
3119
|
-
id: "thread" in target ? target.id : await nodeId(thread, options),
|
|
3120
|
-
content: (await import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js")).REACTION_CONTENT[reaction]
|
|
3121
|
-
}, options);
|
|
3122
|
-
return;
|
|
3123
|
-
}
|
|
3124
|
-
await fetcher.raw(reactionPath(target), {
|
|
3125
|
-
method: "POST",
|
|
3126
|
-
json: { content: reaction },
|
|
3127
|
-
signal: options?.signal
|
|
3128
|
-
});
|
|
3129
|
-
}
|
|
3130
|
-
async function unreact(target, reaction, options) {
|
|
3131
|
-
const thread = "thread" in target ? target.thread : target;
|
|
3132
|
-
if (thread.kind === "discussion") {
|
|
3133
|
-
await graphql("REMOVE_REACTION", {
|
|
3134
|
-
id: "thread" in target ? target.id : await nodeId(thread, options),
|
|
3135
|
-
content: (await import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js")).REACTION_CONTENT[reaction]
|
|
3136
|
-
}, options);
|
|
3137
|
-
return;
|
|
3138
|
-
}
|
|
3139
|
-
const path = reactionPath(target);
|
|
3140
|
-
const { data } = await fetcher.json(path, {
|
|
3141
|
-
query: {
|
|
3142
|
-
content: reaction,
|
|
3143
|
-
per_page: 100
|
|
3144
|
-
},
|
|
3145
|
-
signal: options?.signal
|
|
3146
|
-
});
|
|
3147
|
-
const login = await viewerLogin();
|
|
3148
|
-
const mine = data.find((item) => item.content === reaction && item.user?.login === login);
|
|
3149
|
-
if (mine) await fetcher.raw(`${path}/${encodeURIComponent(mine.id)}`, {
|
|
3150
|
-
method: "DELETE",
|
|
3151
|
-
signal: options?.signal
|
|
3152
|
-
});
|
|
3153
|
-
}
|
|
3154
|
-
async function issuePatch(thread, json, action, signal) {
|
|
3155
|
-
const ref = requireIssueOrPull(thread, context, action);
|
|
3156
|
-
return (await fetcher.json(`${repoPath(ref.repo)}/issues/${encodeURIComponent(ref.number)}`, {
|
|
3157
|
-
method: "PATCH",
|
|
3158
|
-
json,
|
|
3159
|
-
signal
|
|
3160
|
-
})).data;
|
|
3161
|
-
}
|
|
3162
|
-
/** Check runs need an installation credential; a token writes a commit status instead. */
|
|
3163
|
-
const canWriteCheckRuns = auth.type === "app" && auth.installationId !== void 0;
|
|
3164
|
-
const STATUS_STATES = {
|
|
3165
|
-
pending: "pending",
|
|
3166
|
-
success: "success",
|
|
3167
|
-
failure: "failure",
|
|
3168
|
-
neutral: "success",
|
|
3169
|
-
unknown: "pending"
|
|
3170
|
-
};
|
|
3171
|
-
const CHECK_RUN_CONCLUSIONS = {
|
|
3172
|
-
success: "success",
|
|
3173
|
-
failure: "failure",
|
|
3174
|
-
neutral: "neutral"
|
|
3175
|
-
};
|
|
3176
|
-
async function report(repo, sha, input, options) {
|
|
3177
|
-
if (canWriteCheckRuns) {
|
|
3178
|
-
const conclusion = CHECK_RUN_CONCLUSIONS[input.state];
|
|
3179
|
-
const { data } = await fetcher.json(`${repoPath(repo)}/check-runs`, {
|
|
3180
|
-
method: "POST",
|
|
3181
|
-
json: {
|
|
3182
|
-
name: input.name,
|
|
3183
|
-
head_sha: sha,
|
|
3184
|
-
status: conclusion ? "completed" : "in_progress",
|
|
3185
|
-
conclusion,
|
|
3186
|
-
details_url: input.url,
|
|
3187
|
-
external_id: input.externalId,
|
|
3188
|
-
output: input.description ? {
|
|
3189
|
-
title: input.name,
|
|
3190
|
-
summary: input.description
|
|
3191
|
-
} : void 0
|
|
3192
|
-
},
|
|
3193
|
-
signal: options?.signal
|
|
3194
|
-
});
|
|
3195
|
-
return toCheckRun(repo, data);
|
|
3196
|
-
}
|
|
3197
|
-
const { data } = await fetcher.json(`${repoPath(repo)}/statuses/${sha}`, {
|
|
3198
|
-
method: "POST",
|
|
3199
|
-
json: {
|
|
3200
|
-
state: STATUS_STATES[input.state],
|
|
3201
|
-
context: input.name,
|
|
3202
|
-
description: input.description,
|
|
3203
|
-
target_url: input.url
|
|
3204
|
-
},
|
|
3205
|
-
signal: options?.signal
|
|
3206
|
-
});
|
|
3207
|
-
return toStatusCheck(repo, data);
|
|
3208
|
-
}
|
|
3209
|
-
async function runsPage(repo, query = {}) {
|
|
3210
|
-
const result = await fetcher.page(`${repoPath(repo)}/actions/runs`, {
|
|
3211
|
-
query: {
|
|
3212
|
-
branch: query.branch,
|
|
3213
|
-
status: query.state === "pending" ? "in_progress" : query.state === "success" ? "success" : query.state === "failure" ? "failure" : void 0,
|
|
3214
|
-
per_page: query.perPage
|
|
3215
|
-
},
|
|
3216
|
-
cursor: query.cursor,
|
|
3217
|
-
signal: query.signal,
|
|
3218
|
-
select: (body, next) => {
|
|
3219
|
-
const { workflow_runs, total_count } = body;
|
|
3220
|
-
return {
|
|
3221
|
-
items: workflow_runs,
|
|
3222
|
-
next,
|
|
3223
|
-
total: total_count
|
|
3224
|
-
};
|
|
3225
|
-
}
|
|
3226
|
-
});
|
|
3227
|
-
return toPage(result, (raw) => toWorkflowRun(repo, raw));
|
|
3228
|
-
}
|
|
3229
|
-
const spec = {
|
|
3230
|
-
extensions: { graphql: ((document, variables = {}, graphqlOptions) => {
|
|
3231
|
-
const query = String(document);
|
|
3232
|
-
return options.readOnly && graphqlOperations(query).some(({ type }) => type === "mutation") ? Promise.reject(new ReadOnlyError("GraphQL mutations are writes and this github provider is read-only", context)) : graphql({ query }, variables, graphqlOptions);
|
|
3233
|
-
}) },
|
|
3234
|
-
checks: {
|
|
3235
|
-
list: verb(true, (repo, sha, options) => headChecks(repo, sha, options?.signal)),
|
|
3236
|
-
get: verb(true, getCheck),
|
|
3237
|
-
report: verb(true, report),
|
|
3238
|
-
rerun: verb(true, async (ref, options) => {
|
|
3239
|
-
if (ref.type !== "check_run") throw new UnsupportedOperationError(`GitHub cannot re-run a ${ref.type}; only check runs can be re-requested`, context);
|
|
3240
|
-
const rerunJob = () => fetcher.raw(`${repoPath(ref.repo)}/actions/jobs/${encodeURIComponent(ref.id)}/rerun`, {
|
|
3241
|
-
method: "POST",
|
|
3242
|
-
signal: options?.signal
|
|
3243
|
-
});
|
|
3244
|
-
if (ref.app === "github-actions") {
|
|
3245
|
-
await rerunJob();
|
|
3246
|
-
return;
|
|
3247
|
-
}
|
|
3248
|
-
try {
|
|
3249
|
-
await fetcher.raw(`${repoPath(ref.repo)}/check-runs/${encodeURIComponent(ref.id)}/rerequest`, {
|
|
3250
|
-
method: "POST",
|
|
3251
|
-
signal: options?.signal
|
|
3252
|
-
});
|
|
3253
|
-
} catch (error) {
|
|
3254
|
-
if (!(error instanceof InsufficientScopeError) && !(error instanceof ForgeApiError && error.status === 422)) throw error;
|
|
3255
|
-
try {
|
|
3256
|
-
await rerunJob();
|
|
3257
|
-
} catch (rerunError) {
|
|
3258
|
-
if (!(rerunError instanceof NotFoundError)) throw rerunError;
|
|
3259
|
-
throw error instanceof InsufficientScopeError ? notOwnerOfCheckRun(error) : error;
|
|
3260
|
-
}
|
|
3261
|
-
}
|
|
3262
|
-
})
|
|
3263
|
-
},
|
|
3264
|
-
ci: {
|
|
3265
|
-
runsPage: verb(true, runsPage),
|
|
3266
|
-
getRun: verb(true, async (ref, options) => toWorkflowRun(ref.repo, (await fetcher.json(`${repoPath(ref.repo)}/actions/runs/${encodeURIComponent(ref.id)}`, { signal: options?.signal })).data)),
|
|
3267
|
-
jobsPage: verb(true, (ref, listOptions = {}) => list(`${repoPath(ref.repo)}/actions/runs/${encodeURIComponent(ref.id)}/jobs`, listOptions, (raw) => toWorkflowJob(ref, raw), { select: (body, next) => {
|
|
3268
|
-
const { jobs, total_count } = body;
|
|
3269
|
-
return {
|
|
3270
|
-
items: jobs,
|
|
3271
|
-
next,
|
|
3272
|
-
total: total_count
|
|
3273
|
-
};
|
|
3274
|
-
} })),
|
|
3275
|
-
getJob: verb(true, getJob),
|
|
3276
|
-
log: verb(!anonymous, async (ref, options) => (await fetcher.stream(`${repoPath(ref.repo)}/actions/jobs/${encodeURIComponent(ref.id)}/logs`, { signal: options?.signal })).body),
|
|
3277
|
-
rerunFailed: verb(true, async (ref, options) => {
|
|
3278
|
-
await fetcher.raw(`${repoPath(ref.repo)}/actions/runs/${encodeURIComponent(ref.id)}/rerun-failed-jobs`, {
|
|
3279
|
-
method: "POST",
|
|
3280
|
-
signal: options?.signal
|
|
3281
|
-
});
|
|
3282
|
-
})
|
|
3283
|
-
},
|
|
3284
|
-
contents: {
|
|
3285
|
-
getFile: verb(true, readFile),
|
|
3286
|
-
treePage: verb(true, treePage),
|
|
3287
|
-
branchesPage: verb(true, (repo, listOptions = {}) => list(`${repoPath(repo)}/branches`, listOptions, (raw) => toBranch(raw))),
|
|
3288
|
-
tagsPage: verb(true, (repo, listOptions = {}) => list(`${repoPath(repo)}/tags`, listOptions, toTag)),
|
|
3289
|
-
resolveRef: verb(true, async (repo, ref, options) => (await fetcher.json(`${repoPath(repo)}/commits/${encodeURIComponent(ref)}`, { signal: options?.signal })).data.sha),
|
|
3290
|
-
commitFiles: verb(true, (repo, input, options) => input.author ? commitTree(repo, input, options) : commitOnBranch(repo, input, options)),
|
|
3291
|
-
compare: verb(true, compare)
|
|
3292
|
-
},
|
|
3293
|
-
commits: {
|
|
3294
|
-
listPage: verb(true, commitsPage),
|
|
3295
|
-
get: verb(true, async ({ repo, sha }, options) => toCommit(repo, (await fetcher.json(`${repoPath(repo)}/commits/${sha}`, { signal: options?.signal })).data)),
|
|
3296
|
-
commentsPage: verb(true, (commit, listOptions = {}) => list(`${repoPath(commit.repo)}/commits/${encodeURIComponent(commit.sha)}/comments`, listOptions, (raw) => toCommitComment(commit, raw))),
|
|
3297
|
-
getComment: verb(anonymous ? "unverified" : true, async (ref, options) => {
|
|
3298
|
-
const { data } = await fetcher.json(commitCommentPath(ref), { signal: options?.signal });
|
|
3299
|
-
return toCommitComment(ref.commit, data);
|
|
3300
|
-
}),
|
|
3301
|
-
createComment: verb(true, async (commit, body, options) => {
|
|
3302
|
-
const { data } = await fetcher.json(`${repoPath(commit.repo)}/commits/${encodeURIComponent(commit.sha)}/comments`, {
|
|
3303
|
-
method: "POST",
|
|
3304
|
-
json: { body },
|
|
3305
|
-
signal: options?.signal
|
|
3306
|
-
});
|
|
3307
|
-
return toCommitComment(commit, data);
|
|
3308
|
-
}),
|
|
3309
|
-
updateComment: verb(true, async (ref, body, options) => {
|
|
3310
|
-
const { data } = await fetcher.json(commitCommentPath(ref), {
|
|
3311
|
-
method: "PATCH",
|
|
3312
|
-
json: { body },
|
|
3313
|
-
signal: options?.signal
|
|
3314
|
-
});
|
|
3315
|
-
return toCommitComment(ref.commit, data);
|
|
3316
|
-
}),
|
|
3317
|
-
deleteComment: verb(true, async (ref, options) => {
|
|
3318
|
-
await fetcher.raw(commitCommentPath(ref), {
|
|
3319
|
-
method: "DELETE",
|
|
3320
|
-
signal: options?.signal
|
|
3321
|
-
});
|
|
3322
|
-
}),
|
|
3323
|
-
commentHiding: verb(true, {
|
|
3324
|
-
hideComment: async (ref, reason, options) => {
|
|
3325
|
-
await graphql("MINIMIZE_COMMENT", {
|
|
3326
|
-
id: await commentNodeId(ref, options),
|
|
3327
|
-
classifier: reason.toUpperCase()
|
|
3328
|
-
}, options);
|
|
3329
|
-
},
|
|
3330
|
-
unhideComment: async (ref, options) => {
|
|
3331
|
-
await graphql("UNMINIMIZE_COMMENT", { id: await commentNodeId(ref, options) }, options);
|
|
3332
|
-
}
|
|
3333
|
-
})
|
|
3334
|
-
},
|
|
3335
|
-
search: {
|
|
3336
|
-
threadsPage: verb(true, searchThreadsPage),
|
|
3337
|
-
reposPage: verb(true, searchReposPage),
|
|
3338
|
-
commitsPage: verb(true, searchCommitsPage),
|
|
3339
|
-
codePage: verb(!anonymous, searchCodePage),
|
|
3340
|
-
queryRaw: true
|
|
3341
|
-
},
|
|
3342
|
-
releases: {
|
|
3343
|
-
listPage: verb(true, releasesPage),
|
|
3344
|
-
get: verb(true, async (ref, options) => toRelease(ref.repo, (await fetcher.json(`${repoPath(ref.repo)}/releases/${encodeURIComponent(ref.id)}`, { signal: options?.signal })).data)),
|
|
3345
|
-
getByTag: verb(true, async (repo, tag, options) => toRelease(repo, (await fetcher.json(`${repoPath(repo)}/releases/tags/${encodeURIComponent(tag)}`, { signal: options?.signal })).data)),
|
|
3346
|
-
downloadAsset: verb(true, async (ref, downloadOptions = {}) => (await fetcher.stream(`${repoPath(ref.repo)}/releases/assets/${encodeURIComponent(ref.id)}`, {
|
|
3347
|
-
headers: { accept: "application/octet-stream" },
|
|
3348
|
-
signal: downloadOptions.signal
|
|
3349
|
-
})).body),
|
|
3350
|
-
latest: verb(true, async (repo, options) => {
|
|
3351
|
-
try {
|
|
3352
|
-
return toRelease(repo, (await fetcher.json(`${repoPath(repo)}/releases/latest`, { signal: options?.signal })).data);
|
|
3353
|
-
} catch (error) {
|
|
3354
|
-
if (error instanceof NotFoundError) return;
|
|
3355
|
-
throw error;
|
|
3356
|
-
}
|
|
3357
|
-
}),
|
|
3358
|
-
create: verb(true, (repo, input, options) => writeRelease(repo, `${repoPath(repo)}/releases`, "POST", input, options)),
|
|
3359
|
-
update: verb(true, (ref, update, options) => writeRelease(ref.repo, `${repoPath(ref.repo)}/releases/${encodeURIComponent(ref.id)}`, "PATCH", update, options))
|
|
3360
|
-
},
|
|
3361
|
-
securityAlerts: {
|
|
3362
|
-
kinds: {
|
|
3363
|
-
dependency: !anonymous && (enterprise ? ({ version }) => versionAtLeast(version, GHES_DEPENDABOT_ALERTS) && "unverified" : true),
|
|
3364
|
-
code_scanning: !anonymous,
|
|
3365
|
-
secret: !anonymous,
|
|
3366
|
-
advisory: !anonymous && !enterprise
|
|
3367
|
-
},
|
|
3368
|
-
listPage: alertsPage
|
|
3369
|
-
},
|
|
3370
|
-
traits: {
|
|
3371
|
-
eventKinds: "native",
|
|
3372
|
-
authKinds: [
|
|
3373
|
-
"token",
|
|
3374
|
-
"app",
|
|
3375
|
-
"anonymous"
|
|
3376
|
-
],
|
|
3377
|
-
limits: {
|
|
3378
|
-
bodyLength: 65536,
|
|
3379
|
-
commentLength: 65536,
|
|
3380
|
-
labelLength: 50
|
|
3381
|
-
}
|
|
3382
|
-
},
|
|
3383
|
-
probeVersion: enterprise ? async () => (await fetcher.json("/meta")).data.installed_version : void 0,
|
|
3384
|
-
installations: credentials ? verb(true, createInstallationsApi(credentials)) : void 0,
|
|
3385
|
-
web: GITHUB_WEB.links({
|
|
3386
|
-
baseUrl,
|
|
3387
|
-
instance
|
|
3388
|
-
}),
|
|
3389
|
-
webhooks: {
|
|
3390
|
-
listPage: verb(true, (target, listOptions = {}) => list(hooksPath(target), listOptions, (raw) => toWebhook(target, raw), { mapError: scopeIs404 })),
|
|
3391
|
-
create: verb(true, async (target, input, options) => toWebhook(target, (await fetcher.json(hooksPath(target), {
|
|
3392
|
-
method: "POST",
|
|
3393
|
-
json: {
|
|
3394
|
-
name: "web",
|
|
3395
|
-
active: input.active ?? true,
|
|
3396
|
-
events: nativeEventsFor(GITHUB_NATIVE_EVENTS, input.events, input.nativeEvents),
|
|
3397
|
-
config: hookConfig(input)
|
|
3398
|
-
},
|
|
3399
|
-
mapError: scopeIs404,
|
|
3400
|
-
signal: options?.signal
|
|
3401
|
-
})).data)),
|
|
3402
|
-
update: verb(true, async (ref, update, options) => toWebhook(ref.target, (await fetcher.json(`${hooksPath(ref.target)}/${encodeURIComponent(ref.id)}`, {
|
|
3403
|
-
method: "PATCH",
|
|
3404
|
-
json: {
|
|
3405
|
-
...update.active === void 0 ? {} : { active: update.active },
|
|
3406
|
-
...update.events || update.nativeEvents ? { events: nativeEventsFor(GITHUB_NATIVE_EVENTS, update.events, update.nativeEvents) } : {},
|
|
3407
|
-
...update.url || update.secret || update.contentType ? { config: hookConfig(update) } : {}
|
|
3408
|
-
},
|
|
3409
|
-
mapError: scopeIs404,
|
|
3410
|
-
signal: options?.signal
|
|
3411
|
-
})).data)),
|
|
3412
|
-
delete: verb(true, async (ref, options) => {
|
|
3413
|
-
await fetcher.raw(`${hooksPath(ref.target)}/${encodeURIComponent(ref.id)}`, {
|
|
3414
|
-
method: "DELETE",
|
|
3415
|
-
mapError: scopeIs404,
|
|
3416
|
-
signal: options?.signal
|
|
3417
|
-
});
|
|
3418
|
-
}),
|
|
3419
|
-
rotateSecret: verb(true, async (ref, secret, options) => {
|
|
3420
|
-
const current = toWebhook(ref.target, (await fetcher.json(`${hooksPath(ref.target)}/${encodeURIComponent(ref.id)}`, {
|
|
3421
|
-
mapError: scopeIs404,
|
|
3422
|
-
signal: options?.signal
|
|
3423
|
-
})).data);
|
|
3424
|
-
const { data } = await fetcher.json(`${hooksPath(ref.target)}/${encodeURIComponent(ref.id)}`, {
|
|
3425
|
-
method: "PATCH",
|
|
3426
|
-
json: { config: hookConfig({
|
|
3427
|
-
url: current.url,
|
|
3428
|
-
contentType: current.contentType,
|
|
3429
|
-
secret
|
|
3430
|
-
}) },
|
|
3431
|
-
mapError: scopeIs404,
|
|
3432
|
-
signal: options?.signal
|
|
3433
|
-
});
|
|
3434
|
-
return toWebhook(ref.target, data);
|
|
3435
|
-
}),
|
|
3436
|
-
deliveriesPage: verb(true, (ref, listOptions = {}) => list(`${hooksPath(ref.target)}/${encodeURIComponent(ref.id)}/deliveries`, listOptions, (raw) => toWebhookDelivery(ref, raw), { mapError: scopeIs404 })),
|
|
3437
|
-
redeliver: verb(true, async (ref, options) => {
|
|
3438
|
-
await fetcher.raw(`${hooksPath(ref.hook.target)}/${encodeURIComponent(ref.hook.id)}/deliveries/${encodeURIComponent(ref.id)}/attempts`, {
|
|
3439
|
-
method: "POST",
|
|
3440
|
-
mapError: scopeIs404,
|
|
3441
|
-
signal: options?.signal
|
|
3442
|
-
});
|
|
3443
|
-
})
|
|
3444
|
-
},
|
|
3445
|
-
scopes: githubScopesFor,
|
|
3446
|
-
users: {
|
|
3447
|
-
get: verb(true, async (login, options) => toUser(instance, (await fetcher.json(`/users/${encodeURIComponent(login)}`, { signal: options?.signal })).data)),
|
|
3448
|
-
me: verb(auth.type === "token" && !installation, async (options) => toUser(instance, (await fetcher.json("/user", { signal: options?.signal })).data)),
|
|
3449
|
-
sponsorable: verb(!enterprise && !anonymous, async (login, options) => {
|
|
3450
|
-
const data = await graphql("SPONSORABLE", { login }, options);
|
|
3451
|
-
if (!data.repositoryOwner) throw new NotFoundError(`Account ${login} not found`, 404, "", context);
|
|
3452
|
-
return data.repositoryOwner.hasSponsorsListing;
|
|
3453
|
-
}),
|
|
3454
|
-
eventsPage: verb(true, (login, listOptions) => feedPage(`/users/${encodeURIComponent(login)}/events`, listOptions)),
|
|
3455
|
-
blocking: verb(auth.type === "token" && !installation && (enterprise ? "unverified" : true), {
|
|
3456
|
-
block: async (login, options) => {
|
|
3457
|
-
await fetcher.raw(`/user/blocks/${encodeURIComponent(login)}`, {
|
|
3458
|
-
method: "PUT",
|
|
3459
|
-
signal: options?.signal
|
|
3460
|
-
});
|
|
3461
|
-
},
|
|
3462
|
-
unblock: async (login, options) => {
|
|
3463
|
-
await fetcher.raw(`/user/blocks/${encodeURIComponent(login)}`, {
|
|
3464
|
-
method: "DELETE",
|
|
3465
|
-
signal: options?.signal
|
|
3466
|
-
});
|
|
3467
|
-
}
|
|
3468
|
-
})
|
|
3469
|
-
},
|
|
3470
|
-
repos: {
|
|
3471
|
-
get: verb(true, async (ref, options) => {
|
|
3472
|
-
return toRepo(instance, (await fetcher.json(repoPath(ref), { signal: options?.signal })).data);
|
|
3473
|
-
}),
|
|
3474
|
-
listPage: verb(!anonymous, (listOptions = {}) => installation ? reposPage(fetcher, "/installation/repositories", true, listOptions) : reposPage(fetcher, "/user/repos", false, listOptions)),
|
|
3475
|
-
byOwnerPage: verb(true, ownerReposPage),
|
|
3476
|
-
labelsPage: verb(true, (repo, listOptions = {}) => list(`${repoPath(repo)}/labels`, listOptions, toLabel)),
|
|
3477
|
-
createLabel: verb(true, async (repo, label, options) => toLabel((await fetcher.json(`${repoPath(repo)}/labels`, {
|
|
3478
|
-
method: "POST",
|
|
3479
|
-
json: {
|
|
3480
|
-
name: label.name,
|
|
3481
|
-
color: label.colour,
|
|
3482
|
-
description: label.description
|
|
3483
|
-
},
|
|
3484
|
-
signal: options?.signal
|
|
3485
|
-
})).data)),
|
|
3486
|
-
milestonesPage: verb(true, milestonesPage),
|
|
3487
|
-
issueTypes: verb(!anonymous && !enterprise, async (repo, options) => {
|
|
3488
|
-
const { data } = await fetcher.json(`${repoPath(repo)}/issue-types`, { signal: options?.signal });
|
|
3489
|
-
return data.map((raw) => toIssueType(raw));
|
|
3490
|
-
}),
|
|
3491
|
-
collaboratorsPage: verb(!anonymous, (repo, listOptions = {}) => list(`${repoPath(repo)}/collaborators`, listOptions, (raw) => toCollaborator(instance, raw))),
|
|
3492
|
-
contributorsPage: verb(true, (repo, listOptions = {}) => list(`${repoPath(repo)}/contributors`, listOptions, (raw) => toContributor(instance, raw), { query: listOptions.includeUnlinked ? { anon: 1 } : {} })),
|
|
3493
|
-
contributorStats: verb(true, contributorStats),
|
|
3494
|
-
templates: verb(true, templates),
|
|
3495
|
-
permissionFor: verb(!anonymous, async (repo, actor, options) => {
|
|
3496
|
-
const { data } = await fetcher.json(`${repoPath(repo)}/collaborators/${encodeURIComponent(actorLogin(actor))}/permission`, { signal: options?.signal });
|
|
3497
|
-
return toRole({
|
|
3498
|
-
role_name: data.role_name ?? (data.permission === "none" ? void 0 : data.permission),
|
|
3499
|
-
permissions: data.user?.permissions
|
|
3500
|
-
});
|
|
3501
|
-
}),
|
|
3502
|
-
branchRules: verb(enterprise ? "unverified" : true, async (repo, name, options) => {
|
|
3503
|
-
const branchPath = `branches/${name.split("/").map(encodeURIComponent).join("/")}`;
|
|
3504
|
-
const path = `${repoPath(repo)}/${branchPath}`;
|
|
3505
|
-
const [{ data: branch }, rules] = await Promise.all([fetcher.json(path, { signal: options?.signal }), Array.fromAsync(fetcher.items(`${repoPath(repo)}/rules/${branchPath}`, {
|
|
3506
|
-
query: { per_page: 100 },
|
|
3507
|
-
signal: options?.signal
|
|
3508
|
-
}))]);
|
|
3509
|
-
const warnings = [];
|
|
3510
|
-
let protection;
|
|
3511
|
-
if (branch.protection?.enabled) try {
|
|
3512
|
-
if (anonymous) throw new AuthenticationRequiredError("Credentials are required for this request", 401, "", context);
|
|
3513
|
-
protection = (await fetcher.json(`${path}/protection`, { signal: options?.signal })).data;
|
|
3514
|
-
} catch (error) {
|
|
3515
|
-
if (!(error instanceof NotFoundError || error instanceof ForbiddenError || error instanceof InsufficientScopeError || error instanceof AuthenticationRequiredError)) throw error;
|
|
3516
|
-
warnings.push(toWarning("insufficient_scope", error, "protection"));
|
|
3517
|
-
}
|
|
3518
|
-
return toBranchRules(branch, rules, protection, warnings);
|
|
3519
|
-
}),
|
|
3520
|
-
addCollaborator: verb(true, async (repo, actor, role, options) => {
|
|
3521
|
-
return { status: (await fetcher.raw(`${repoPath(repo)}/collaborators/${encodeURIComponent(actorLogin(actor))}`, {
|
|
3522
|
-
method: "PUT",
|
|
3523
|
-
json: { permission: COLLABORATOR_PERMISSIONS[role] ?? role },
|
|
3524
|
-
signal: options?.signal
|
|
3525
|
-
})).status === 201 ? "invited" : "added" };
|
|
3526
|
-
}),
|
|
3527
|
-
assignableUsersPage: verb(true, (repo, listOptions = {}) => list(`${repoPath(repo)}/assignees`, listOptions, (raw) => toActor(instance, raw))),
|
|
3528
|
-
reviewerCandidatesPage: verb(!anonymous && "emulated", async (thread, listOptions = {}) => {
|
|
3529
|
-
const ref = requireThread(thread, context);
|
|
3530
|
-
const page = await fetcher.page(`${repoPath(ref.repo)}/collaborators`, {
|
|
3531
|
-
query: { per_page: listOptions.perPage },
|
|
3532
|
-
cursor: listOptions.cursor,
|
|
3533
|
-
signal: listOptions.signal
|
|
3534
|
-
});
|
|
3535
|
-
const author = page.notModified ? void 0 : (await get(ref, listOptions)).author?.login;
|
|
3536
|
-
return toPage(page, (raw) => raw.login === author ? void 0 : toActor(instance, raw));
|
|
3537
|
-
}),
|
|
3538
|
-
eventsPage: verb(true, (repo, listOptions) => feedPage(`${repoPath(repo)}/events`, listOptions))
|
|
3539
|
-
},
|
|
3540
|
-
orgs: {
|
|
3541
|
-
teamsPage: verb(!anonymous, (org, listOptions = {}) => list(`/orgs/${encodeURIComponent(org.owner)}/teams`, listOptions, (raw) => toTeam(instance, teamOrg(org), raw))),
|
|
3542
|
-
teamMembersPage: verb(!anonymous, (team, listOptions = {}) => list(`/orgs/${encodeURIComponent(team.org.owner)}/teams/${encodeURIComponent(team.slug)}/members`, listOptions, (raw) => toActor(instance, raw))),
|
|
3543
|
-
blocking: verb(enterprise ? "unverified" : true, {
|
|
3544
|
-
block: async (org, login, options) => {
|
|
3545
|
-
await fetcher.raw(`/orgs/${encodeURIComponent(org.owner)}/blocks/${encodeURIComponent(login)}`, {
|
|
3546
|
-
method: "PUT",
|
|
3547
|
-
signal: options?.signal
|
|
3548
|
-
});
|
|
3549
|
-
},
|
|
3550
|
-
unblock: async (org, login, options) => {
|
|
3551
|
-
await fetcher.raw(`/orgs/${encodeURIComponent(org.owner)}/blocks/${encodeURIComponent(login)}`, {
|
|
3552
|
-
method: "DELETE",
|
|
3553
|
-
signal: options?.signal
|
|
3554
|
-
});
|
|
3555
|
-
}
|
|
3556
|
-
})
|
|
3557
|
-
},
|
|
3558
|
-
notifications: {
|
|
3559
|
-
listPage: verb(notificationsAuth, notificationPage),
|
|
3560
|
-
markRead: verb(notificationsAuth, async (ref, options) => {
|
|
3561
|
-
await fetcher.raw(`/notifications/threads/${encodeURIComponent(ref.id)}`, {
|
|
3562
|
-
method: "PATCH",
|
|
3563
|
-
signal: options?.signal
|
|
3564
|
-
});
|
|
3565
|
-
}),
|
|
3566
|
-
markDone: verb(notificationsAuth && (enterprise ? ({ version }) => versionAtLeast(version, GHES_MARK_DONE) : true), async (ref, options) => {
|
|
3567
|
-
await fetcher.raw(`/notifications/threads/${encodeURIComponent(ref.id)}`, {
|
|
3568
|
-
method: "DELETE",
|
|
3569
|
-
signal: options?.signal
|
|
3570
|
-
});
|
|
3571
|
-
}),
|
|
3572
|
-
unsubscribe: verb(notificationsAuth, async (ref, options) => {
|
|
3573
|
-
await fetcher.raw(`/notifications/threads/${encodeURIComponent(ref.id)}/subscription`, {
|
|
3574
|
-
method: "DELETE",
|
|
3575
|
-
signal: options?.signal
|
|
3576
|
-
});
|
|
3577
|
-
}),
|
|
3578
|
-
markAllRead: verb(notificationsAuth, async (bulk = {}) => {
|
|
3579
|
-
await fetcher.raw(bulk.repo ? `${repoPath(bulk.repo)}/notifications` : "/notifications", {
|
|
3580
|
-
method: "PUT",
|
|
3581
|
-
...bulk.before ? { json: { last_read_at: bulk.before.toISOString() } } : {},
|
|
3582
|
-
signal: bulk.signal
|
|
3583
|
-
});
|
|
3584
|
-
})
|
|
3585
|
-
},
|
|
3586
|
-
threads: {
|
|
3587
|
-
get: perKind({
|
|
3588
|
-
issue: true,
|
|
3589
|
-
pull_request: true,
|
|
3590
|
-
discussion: !anonymous
|
|
3591
|
-
}, get),
|
|
3592
|
-
getMany: verb(true, getMany),
|
|
3593
|
-
listPage: perKind({
|
|
3594
|
-
...ISSUE_LIKE,
|
|
3595
|
-
discussion: !anonymous
|
|
3596
|
-
}, listPage),
|
|
3597
|
-
listFilters: [
|
|
3598
|
-
"involves",
|
|
3599
|
-
"mentions",
|
|
3600
|
-
"milestone"
|
|
3601
|
-
],
|
|
3602
|
-
eventsPage: verb(true, async (thread, listOptions = {}) => {
|
|
3603
|
-
const ref = requireThread(thread, context);
|
|
3604
|
-
if (ref.kind === "discussion") {
|
|
3605
|
-
const [page, { toDiscussionCommentEvent }] = await Promise.all([discussionCommentPage(ref, listOptions), import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js")]);
|
|
3606
|
-
return {
|
|
3607
|
-
...page,
|
|
3608
|
-
items: page.items.map(({ comment, isReply }) => toDiscussionCommentEvent(ref, comment, isReply))
|
|
3609
|
-
};
|
|
3610
|
-
}
|
|
3611
|
-
return list(`${repoPath(ref.repo)}/issues/${encodeURIComponent(ref.number)}/timeline`, listOptions, (entry) => toEvent(instance, ref, entry));
|
|
3612
|
-
}),
|
|
3613
|
-
commentsPage: perKind({
|
|
3614
|
-
issue: true,
|
|
3615
|
-
pull_request: true,
|
|
3616
|
-
discussion: !anonymous
|
|
3617
|
-
}, commentsPage),
|
|
3618
|
-
getComment: perKind({
|
|
3619
|
-
issue: anonymous ? "unverified" : true,
|
|
3620
|
-
pull_request: true,
|
|
3621
|
-
discussion: !anonymous
|
|
3622
|
-
}, getComment),
|
|
3623
|
-
reviewsPage: verb(true, reviewsPage),
|
|
3624
|
-
getReview: verb(anonymous ? "unverified" : true, getReview),
|
|
3625
|
-
filesPage: verb(true, (ref, listOptions = {}) => list(`${threadPath(requirePull(ref, "read for changed files"))}/files`, listOptions, toChangedFile)),
|
|
3626
|
-
commitsPage: verb(true, (ref, listOptions = {}) => list(`${threadPath(requirePull(ref, "read for commits"))}/commits`, listOptions, (raw) => toCommit(ref.repo, raw))),
|
|
3627
|
-
createReview: verb(true, createReview),
|
|
3628
|
-
submitReview: verb(true, async (ref, event, body, options) => {
|
|
3629
|
-
const pull = requirePull(ref.thread, "reviewed");
|
|
3630
|
-
const { data } = await fetcher.json(`${threadPath(pull)}/reviews/${encodeURIComponent(ref.id)}/events`, {
|
|
3631
|
-
method: "POST",
|
|
3632
|
-
json: {
|
|
3633
|
-
event: REVIEW_EVENTS[event],
|
|
3634
|
-
body
|
|
3635
|
-
},
|
|
3636
|
-
signal: options?.signal
|
|
3637
|
-
});
|
|
3638
|
-
return toReview(pull, data, []);
|
|
3639
|
-
}),
|
|
3640
|
-
replyToReviewComment: verb(true, async (thread, comment, body, options) => {
|
|
3641
|
-
const pull = requirePull(thread, "reviewed");
|
|
3642
|
-
const id = comment.inReplyTo ?? comment.ref?.id;
|
|
3643
|
-
if (id === void 0) throw new UnsupportedOperationError("GitHub replies to a review comment by its id; pass the comment with its `ref`", context);
|
|
3644
|
-
const { data } = await fetcher.json(`${threadPath(pull)}/comments/${encodeURIComponent(id)}/replies`, {
|
|
3645
|
-
method: "POST",
|
|
3646
|
-
json: { body },
|
|
3647
|
-
signal: options?.signal
|
|
3648
|
-
});
|
|
3649
|
-
return toReviewComment(pull, data, comment.thread);
|
|
3650
|
-
}),
|
|
3651
|
-
reviewThreads: verb(true, {
|
|
3652
|
-
resolveReviewThread: async (_ref, id, options) => {
|
|
3653
|
-
await graphql("RESOLVE_REVIEW_THREAD", { id }, options);
|
|
3654
|
-
},
|
|
3655
|
-
unresolveReviewThread: async (_ref, id, options) => {
|
|
3656
|
-
await graphql("UNRESOLVE_REVIEW_THREAD", { id }, options);
|
|
3657
|
-
}
|
|
3658
|
-
}),
|
|
3659
|
-
checks: perKind({ pull_request: true }, async (thread, options) => {
|
|
3660
|
-
const ref = requireThread(thread, context);
|
|
3661
|
-
const { data } = await fetcher.json(threadPath(ref), { signal: options?.signal });
|
|
3662
|
-
return data.head?.sha ? headChecks(ref.repo, data.head.sha, options?.signal) : { items: [] };
|
|
3663
|
-
}),
|
|
3664
|
-
createComment: perKind({
|
|
3665
|
-
issue: true,
|
|
3666
|
-
pull_request: true,
|
|
3667
|
-
discussion: true
|
|
3668
|
-
}, async (thread, body, options) => {
|
|
3669
|
-
const ref = requireThread(thread, context);
|
|
3670
|
-
if (ref.kind === "discussion") {
|
|
3671
|
-
const data = await graphql("ADD_DISCUSSION_COMMENT", {
|
|
3672
|
-
id: await discussionId(ref, options),
|
|
3673
|
-
body
|
|
3674
|
-
}, options);
|
|
3675
|
-
return (await import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js")).toDiscussionComment(ref, data.addDiscussionComment.comment);
|
|
3676
|
-
}
|
|
3677
|
-
const { data } = await fetcher.json(`${repoPath(ref.repo)}/issues/${encodeURIComponent(ref.number)}/comments`, {
|
|
3678
|
-
method: "POST",
|
|
3679
|
-
json: { body },
|
|
3680
|
-
signal: options?.signal
|
|
3681
|
-
});
|
|
3682
|
-
return toComment(ref, data);
|
|
3683
|
-
}),
|
|
3684
|
-
updateComment: perKind({
|
|
3685
|
-
issue: true,
|
|
3686
|
-
pull_request: true,
|
|
3687
|
-
discussion: true
|
|
3688
|
-
}, async (ref, body, options) => {
|
|
3689
|
-
const thread = requireThread(ref.thread, context);
|
|
3690
|
-
if (thread.kind === "discussion") {
|
|
3691
|
-
const data = await graphql("UPDATE_DISCUSSION_COMMENT", {
|
|
3692
|
-
id: ref.id,
|
|
3693
|
-
body
|
|
3694
|
-
}, options);
|
|
3695
|
-
return (await import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js")).toDiscussionComment(thread, data.updateDiscussionComment.comment);
|
|
3696
|
-
}
|
|
3697
|
-
const { data } = await fetcher.json(commentPath(ref), {
|
|
3698
|
-
method: "PATCH",
|
|
3699
|
-
json: { body },
|
|
3700
|
-
signal: options?.signal
|
|
3701
|
-
});
|
|
3702
|
-
return toComment(thread, data);
|
|
3703
|
-
}),
|
|
3704
|
-
deleteComment: perKind({
|
|
3705
|
-
issue: true,
|
|
3706
|
-
pull_request: true,
|
|
3707
|
-
discussion: true
|
|
3708
|
-
}, async (ref, options) => {
|
|
3709
|
-
if (ref.thread.kind === "discussion") {
|
|
3710
|
-
await graphql("DELETE_DISCUSSION_COMMENT", { id: ref.id }, options);
|
|
3711
|
-
return;
|
|
3712
|
-
}
|
|
3713
|
-
await fetcher.raw(commentPath(ref), {
|
|
3714
|
-
method: "DELETE",
|
|
3715
|
-
signal: options?.signal
|
|
3716
|
-
});
|
|
3717
|
-
}),
|
|
3718
|
-
create: perKind({
|
|
3719
|
-
issue: true,
|
|
3720
|
-
pull_request: true
|
|
3721
|
-
}, async (repo, input, options) => {
|
|
3722
|
-
const assignees = input.assignees?.map(actorLogin);
|
|
3723
|
-
if (input.kind === "issue") {
|
|
3724
|
-
const { data } = await fetcher.json(`${repoPath(repo)}/issues`, {
|
|
3725
|
-
method: "POST",
|
|
3726
|
-
json: {
|
|
3727
|
-
title: input.title,
|
|
3728
|
-
body: input.body,
|
|
3729
|
-
labels: input.labels,
|
|
3730
|
-
assignees
|
|
3731
|
-
},
|
|
3732
|
-
signal: options?.signal
|
|
3733
|
-
});
|
|
3734
|
-
return toThread({
|
|
3735
|
-
forge: FORGE,
|
|
3736
|
-
instance,
|
|
3737
|
-
repo,
|
|
3738
|
-
kind: "issue",
|
|
3739
|
-
number: String(data.number)
|
|
3740
|
-
}, data);
|
|
3741
|
-
}
|
|
3742
|
-
if (input.kind !== "pull_request") throw new UnsupportedOperationError("GitHub discussions cannot be created through this API yet", context);
|
|
3743
|
-
if (!input.head || !input.base) throw new UnsupportedOperationError("Creating a pull request needs head and base branches", context);
|
|
3744
|
-
const { data: pull } = await fetcher.json(`${repoPath(repo)}/pulls`, {
|
|
3745
|
-
method: "POST",
|
|
3746
|
-
json: {
|
|
3747
|
-
title: input.title,
|
|
3748
|
-
body: input.body,
|
|
3749
|
-
head: input.head,
|
|
3750
|
-
base: input.base,
|
|
3751
|
-
draft: input.draft
|
|
3752
|
-
},
|
|
3753
|
-
signal: options?.signal
|
|
3754
|
-
});
|
|
3755
|
-
const ref = {
|
|
3756
|
-
forge: FORGE,
|
|
3757
|
-
instance,
|
|
3758
|
-
repo,
|
|
3759
|
-
kind: "pull_request",
|
|
3760
|
-
number: String(pull.number)
|
|
3761
|
-
};
|
|
3762
|
-
if (!input.labels?.length && !assignees?.length) return toThread(ref, pull);
|
|
3763
|
-
const { data: issue } = await fetcher.json(`${repoPath(repo)}/issues/${encodeURIComponent(pull.number)}`, {
|
|
3764
|
-
method: "PATCH",
|
|
3765
|
-
json: {
|
|
3766
|
-
labels: input.labels,
|
|
3767
|
-
assignees
|
|
3768
|
-
},
|
|
3769
|
-
signal: options?.signal
|
|
3770
|
-
});
|
|
3771
|
-
return toThread(ref, {
|
|
3772
|
-
...pull,
|
|
3773
|
-
labels: issue.labels,
|
|
3774
|
-
assignees: issue.assignees
|
|
3775
|
-
});
|
|
3776
|
-
}),
|
|
3777
|
-
/** The pulls endpoint takes no labels or assignees, so a pull request with them is edited as an issue. */
|
|
3778
|
-
update: perKind({
|
|
3779
|
-
issue: true,
|
|
3780
|
-
pull_request: true,
|
|
3781
|
-
discussion: true
|
|
3782
|
-
}, async (thread, input, options) => {
|
|
3783
|
-
const ref = requireThread(thread, context);
|
|
3784
|
-
if (ref.kind === "discussion") {
|
|
3785
|
-
if (input.labels || input.assignees) throw new UnsupportedOperationError("Setting labels or assignees on a GitHub discussion is not supported", context);
|
|
3786
|
-
const id = await discussionId(ref, options);
|
|
3787
|
-
const changed = input.state && await setState({
|
|
3788
|
-
...ref,
|
|
3789
|
-
externalId: id
|
|
3790
|
-
}, input.state, options);
|
|
3791
|
-
if (input.title === void 0 && input.body === void 0) return changed || getDiscussion(ref, options);
|
|
3792
|
-
const data = await graphql("UPDATE_DISCUSSION", {
|
|
3793
|
-
id,
|
|
3794
|
-
title: input.title,
|
|
3795
|
-
body: input.body
|
|
3796
|
-
}, options);
|
|
3797
|
-
return (await import("./graphql-DG5aJBT3-DceyFYdM-C4saqX37.js")).toDiscussionThread(ref, data.updateDiscussion.discussion);
|
|
3798
|
-
}
|
|
3799
|
-
const target = requireIssueOrPull(ref, context, "update");
|
|
3800
|
-
const json = {
|
|
3801
|
-
title: input.title,
|
|
3802
|
-
body: input.body,
|
|
3803
|
-
state: input.state,
|
|
3804
|
-
labels: input.labels,
|
|
3805
|
-
assignees: input.assignees?.map(actorLogin)
|
|
3806
|
-
};
|
|
3807
|
-
if (target.kind === "pull_request" && (input.labels || input.assignees)) {
|
|
3808
|
-
await issuePatch(target, json, "update", options?.signal);
|
|
3809
|
-
return toThread(target, (await fetcher.json(threadPath(target), { signal: options?.signal })).data);
|
|
3810
|
-
}
|
|
3811
|
-
const { data } = await fetcher.json(threadPath(target), {
|
|
3812
|
-
method: "PATCH",
|
|
3813
|
-
json,
|
|
3814
|
-
signal: options?.signal
|
|
3815
|
-
});
|
|
3816
|
-
return toThread(target, data);
|
|
3817
|
-
}),
|
|
3818
|
-
addLabels: perKind({
|
|
3819
|
-
issue: true,
|
|
3820
|
-
pull_request: true
|
|
3821
|
-
}, async (thread, labels, options) => {
|
|
3822
|
-
const ref = requireIssueOrPull(thread, context, "label");
|
|
3823
|
-
return toLabels((await fetcher.json(`${repoPath(ref.repo)}/issues/${encodeURIComponent(ref.number)}/labels`, {
|
|
3824
|
-
method: "POST",
|
|
3825
|
-
json: { labels },
|
|
3826
|
-
signal: options?.signal
|
|
3827
|
-
})).data);
|
|
3828
|
-
}),
|
|
3829
|
-
removeLabels: perKind({
|
|
3830
|
-
issue: true,
|
|
3831
|
-
pull_request: true
|
|
3832
|
-
}, async (thread, labels, options) => {
|
|
3833
|
-
const ref = requireIssueOrPull(thread, context, "label");
|
|
3834
|
-
const path = `${repoPath(ref.repo)}/issues/${encodeURIComponent(ref.number)}/labels`;
|
|
3835
|
-
let remaining;
|
|
3836
|
-
for (const label of labels) try {
|
|
3837
|
-
remaining = (await fetcher.json(`${path}/${encodeURIComponent(label)}`, {
|
|
3838
|
-
method: "DELETE",
|
|
3839
|
-
signal: options?.signal
|
|
3840
|
-
})).data;
|
|
3841
|
-
} catch (error) {
|
|
3842
|
-
if (!(error instanceof NotFoundError && error.body.includes("Label does not exist"))) throw error;
|
|
3843
|
-
}
|
|
3844
|
-
return toLabels(remaining ?? (await fetcher.json(path, {
|
|
3845
|
-
query: { per_page: 100 },
|
|
3846
|
-
signal: options?.signal
|
|
3847
|
-
})).data);
|
|
3848
|
-
}),
|
|
3849
|
-
setMilestone: perKind({
|
|
3850
|
-
issue: true,
|
|
3851
|
-
pull_request: true
|
|
3852
|
-
}, async (thread, milestone, options) => toMilestone((await issuePatch(thread, { milestone: milestone === void 0 ? null : await milestoneId(milestone, (page) => milestonesPage(requireThread(thread, context).repo, page), context, options) }, "set the milestone of", options?.signal)).milestone)),
|
|
3853
|
-
setIssueType: perKind({ issue: enterprise ? "unverified" : true }, async (thread, issueType, options) => toIssueType((await issuePatch(thread, { type: typeof issueType === "object" ? issueType.name : issueType ?? null }, "set the type of", options?.signal)).type)),
|
|
3854
|
-
reactions: perKind({
|
|
3855
|
-
issue: true,
|
|
3856
|
-
pull_request: true,
|
|
3857
|
-
discussion: true
|
|
3858
|
-
}, {
|
|
3859
|
-
react,
|
|
3860
|
-
unreact
|
|
3861
|
-
}),
|
|
3862
|
-
locking: perKind({
|
|
3863
|
-
issue: true,
|
|
3864
|
-
pull_request: true,
|
|
3865
|
-
discussion: true
|
|
3866
|
-
}, {
|
|
3867
|
-
lock: async (thread, options = {}) => {
|
|
3868
|
-
const ref = requireThread(thread, context);
|
|
3869
|
-
if (ref.kind === "discussion") {
|
|
3870
|
-
await graphql("LOCK_LOCKABLE", { id: await nodeId(ref, options) }, options);
|
|
3871
|
-
return;
|
|
3872
|
-
}
|
|
3873
|
-
await fetcher.raw(`${repoPath(ref.repo)}/issues/${encodeURIComponent(ref.number)}/lock`, {
|
|
3874
|
-
method: "PUT",
|
|
3875
|
-
json: options.reason ? { lock_reason: LOCK_REASONS[options.reason] } : {},
|
|
3876
|
-
signal: options.signal
|
|
3877
|
-
});
|
|
3878
|
-
},
|
|
3879
|
-
unlock: async (thread, options) => {
|
|
3880
|
-
const ref = requireThread(thread, context);
|
|
3881
|
-
if (ref.kind === "discussion") {
|
|
3882
|
-
await graphql("UNLOCK_LOCKABLE", { id: await nodeId(ref, options) }, options);
|
|
3883
|
-
return;
|
|
3884
|
-
}
|
|
3885
|
-
await fetcher.raw(`${repoPath(ref.repo)}/issues/${encodeURIComponent(ref.number)}/lock`, {
|
|
3886
|
-
method: "DELETE",
|
|
3887
|
-
signal: options?.signal
|
|
3888
|
-
});
|
|
3889
|
-
}
|
|
3890
|
-
}),
|
|
3891
|
-
hiding: perKind({
|
|
3892
|
-
issue: true,
|
|
3893
|
-
pull_request: true,
|
|
3894
|
-
discussion: true
|
|
3895
|
-
}, {
|
|
3896
|
-
hideComment: async (ref, reason, options) => {
|
|
3897
|
-
await graphql("MINIMIZE_COMMENT", {
|
|
3898
|
-
id: await commentNodeId(ref, options),
|
|
3899
|
-
classifier: reason.toUpperCase()
|
|
3900
|
-
}, options);
|
|
3901
|
-
},
|
|
3902
|
-
unhideComment: async (ref, options) => {
|
|
3903
|
-
await graphql("UNMINIMIZE_COMMENT", { id: await commentNodeId(ref, options) }, options);
|
|
3904
|
-
}
|
|
3905
|
-
}),
|
|
3906
|
-
reactionsPage: perKind({
|
|
3907
|
-
issue: true,
|
|
3908
|
-
pull_request: true,
|
|
3909
|
-
discussion: !anonymous
|
|
3910
|
-
}, reactionsPage),
|
|
3911
|
-
transfer: verb(true, async (thread, repo, options) => {
|
|
3912
|
-
const ref = requireThread(thread, context);
|
|
3913
|
-
if (ref.kind !== "issue") throw new UnsupportedOperationError("GitHub transfers issues only", context);
|
|
3914
|
-
const target = await graphql("REPOSITORY_ID", {
|
|
3915
|
-
owner: repo.owner,
|
|
3916
|
-
name: repo.name
|
|
3917
|
-
}, options);
|
|
3918
|
-
if (!target.repository) throw new NotFoundError(`Repository ${repo.owner}/${repo.name} not found`, 404, "", context);
|
|
3919
|
-
const data = await graphql("TRANSFER_ISSUE", {
|
|
3920
|
-
issue: await nodeId(ref, options),
|
|
3921
|
-
repo: target.repository.id
|
|
3922
|
-
}, options);
|
|
3923
|
-
return {
|
|
3924
|
-
forge: FORGE,
|
|
3925
|
-
instance,
|
|
3926
|
-
repo,
|
|
3927
|
-
kind: "issue",
|
|
3928
|
-
number: String(data.transferIssue.issue.number),
|
|
3929
|
-
externalId: data.transferIssue.issue.id
|
|
3930
|
-
};
|
|
3931
|
-
}),
|
|
3932
|
-
markDuplicate: verb(true, async (thread, canonical, options) => {
|
|
3933
|
-
await graphql("MARK_DUPLICATE", {
|
|
3934
|
-
canonical: await nodeId(canonical, options),
|
|
3935
|
-
duplicate: await nodeId(thread, options)
|
|
3936
|
-
}, options);
|
|
3937
|
-
}),
|
|
3938
|
-
setLabels: perKind({
|
|
3939
|
-
issue: true,
|
|
3940
|
-
pull_request: true
|
|
3941
|
-
}, async (thread, labels, options) => {
|
|
3942
|
-
const ref = requireIssueOrPull(thread, context, "label");
|
|
3943
|
-
return toLabels((await fetcher.json(`${repoPath(ref.repo)}/issues/${encodeURIComponent(ref.number)}/labels`, {
|
|
3944
|
-
method: "PUT",
|
|
3945
|
-
json: { labels },
|
|
3946
|
-
signal: options?.signal
|
|
3947
|
-
})).data);
|
|
3948
|
-
}),
|
|
3949
|
-
setAssignees: perKind({
|
|
3950
|
-
issue: true,
|
|
3951
|
-
pull_request: true
|
|
3952
|
-
}, async (thread, assignees, options) => {
|
|
3953
|
-
return ((await issuePatch(thread, { assignees: assignees.map(actorLogin) }, "assign", options?.signal)).assignees ?? []).flatMap((user) => toActor(instance, user) ?? []);
|
|
3954
|
-
}),
|
|
3955
|
-
requestReview: perKind({ pull_request: true }, async (thread, reviewers, options) => {
|
|
3956
|
-
const ref = requireThread(thread, context);
|
|
3957
|
-
if (ref.kind !== "pull_request") throw new UnsupportedOperationError("Only pull requests have reviewers", context);
|
|
3958
|
-
const teams = reviewers.filter((reviewer) => typeof reviewer !== "string" && reviewer.typeRaw === "Team").map(actorLogin);
|
|
3959
|
-
const users = reviewers.filter((reviewer) => typeof reviewer === "string" || reviewer.typeRaw !== "Team").map(actorLogin);
|
|
3960
|
-
await fetcher.raw(`${threadPath(ref)}/requested_reviewers`, {
|
|
3961
|
-
method: "POST",
|
|
3962
|
-
json: {
|
|
3963
|
-
reviewers: users,
|
|
3964
|
-
...teams.length ? { team_reviewers: teams } : {}
|
|
3965
|
-
},
|
|
3966
|
-
signal: options?.signal
|
|
3967
|
-
});
|
|
3968
|
-
}),
|
|
3969
|
-
close: perKind(ISSUE_LIKE, (ref, options_) => setState(ref, "closed", options_)),
|
|
3970
|
-
reopen: perKind({
|
|
3971
|
-
issue: true,
|
|
3972
|
-
pull_request: true,
|
|
3973
|
-
discussion: true
|
|
3974
|
-
}, (ref, options) => setState(ref, "open", options)),
|
|
3975
|
-
merge: verb(true, merge),
|
|
3976
|
-
updateBranch: verb(true, updateBranch),
|
|
3977
|
-
closingIssuesPage: verb(!anonymous, async (thread, listOptions = {}) => closingPage(requirePull(thread, "read for the issues they close"), "CLOSING_ISSUES", listOptions)),
|
|
3978
|
-
closingPullRequestsPage: verb(!anonymous, async (thread, listOptions = {}) => {
|
|
3979
|
-
const ref = requireThread(thread, context);
|
|
3980
|
-
if (ref.kind !== "issue") throw new UnsupportedOperationError("Only issues are closed by pull requests", context);
|
|
3981
|
-
return closingPage(ref, "CLOSING_PULL_REQUESTS", listOptions);
|
|
3982
|
-
}),
|
|
3983
|
-
subscriptions: perKind(ISSUE_LIKE, {
|
|
3984
|
-
subscription: async (thread, options) => {
|
|
3985
|
-
const { state } = await subscriptionNode(thread, options);
|
|
3986
|
-
return state === "SUBSCRIBED" ? "subscribed" : state === "IGNORED" ? "ignored" : "none";
|
|
3987
|
-
},
|
|
3988
|
-
subscribe: (thread, options) => setSubscription(thread, "SUBSCRIBED", options),
|
|
3989
|
-
unsubscribe: (thread, options) => setSubscription(thread, "UNSUBSCRIBED", options)
|
|
3990
|
-
})
|
|
3991
|
-
}
|
|
3992
|
-
};
|
|
3993
|
-
return appItself ? supportOnly(spec, ["installations"]) : spec;
|
|
3994
|
-
}
|
|
3995
|
-
/** Creates a GitHub provider for github.com or a GitHub Enterprise Server instance. */
|
|
3996
|
-
const github = /* @__PURE__ */ defineForgeProvider({
|
|
3997
|
-
forge: FORGE,
|
|
3998
|
-
hasWeb: true,
|
|
3999
|
-
baseUrl: "https://api.github.com",
|
|
4000
|
-
anonymous: true,
|
|
4001
|
-
instance: webHost,
|
|
4002
|
-
headers: {
|
|
4003
|
-
"accept": "application/vnd.github+json",
|
|
4004
|
-
"x-github-api-version": "2022-11-28"
|
|
4005
|
-
},
|
|
4006
|
-
prepare: ({ options, baseUrl, headers, state }) => options.auth?.type === "app" ? state ?? createAppCredentials(options.auth, {
|
|
4007
|
-
baseUrl,
|
|
4008
|
-
fetch: options.fetch,
|
|
4009
|
-
timeout: options.timeout,
|
|
4010
|
-
onRetry: options.onRetry,
|
|
4011
|
-
onRateLimit: options.onRateLimit,
|
|
4012
|
-
headers
|
|
4013
|
-
}) : void 0,
|
|
4014
|
-
authHeaders: ({ options, state }) => createAuthHeaders(options.auth, state),
|
|
4015
|
-
webhooks: githubWebhooks,
|
|
4016
|
-
setup: setupGitHub
|
|
4017
|
-
});
|
|
4018
|
-
const PULL_CHECK_READS = /* @__PURE__ */ new Set([
|
|
4019
|
-
"threads.get",
|
|
4020
|
-
"threads.getMany",
|
|
4021
|
-
"threads.list",
|
|
4022
|
-
"threads.closingPullRequests"
|
|
4023
|
-
]);
|
|
4024
|
-
/**
|
|
4025
|
-
* Token scopes and fine-grained permissions GitHub documents per endpoint
|
|
4026
|
-
* group. Classic scopes are the ones an OAuth consent screen asks for; the
|
|
4027
|
-
* permissions are the fine-grained token and app equivalents.
|
|
4028
|
-
*/
|
|
4029
|
-
function githubScopesFor(verb) {
|
|
4030
|
-
const [group = "", name = ""] = verb.split(".");
|
|
4031
|
-
if (group === "webhooks") return name === "verify" || name === "ingest" ? {} : {
|
|
4032
|
-
token: ["admin:repo_hook", "admin:org_hook"],
|
|
4033
|
-
permissions: { webhooks: "admin" }
|
|
4034
|
-
};
|
|
4035
|
-
if (group === "notifications") return {
|
|
4036
|
-
token: ["notifications"],
|
|
4037
|
-
note: "Notifications need a classic personal access token or an OAuth app token; fine-grained tokens and GitHub Apps have no access to them"
|
|
4038
|
-
};
|
|
4039
|
-
if (group === "securityAlerts") return {
|
|
4040
|
-
token: ["security_events", "repo"],
|
|
4041
|
-
permissions: {
|
|
4042
|
-
vulnerability_alerts: "read",
|
|
4043
|
-
secret_scanning_alerts: "read",
|
|
4044
|
-
code_scanning_alerts: "read",
|
|
4045
|
-
repository_advisories: "read"
|
|
4046
|
-
},
|
|
4047
|
-
note: "Drafts and private vulnerability reports need a security manager, an administrator, or a collaborator on the advisory"
|
|
4048
|
-
};
|
|
4049
|
-
if (group === "installations") return { note: "App credentials: an app JWT signed with the app private key" };
|
|
4050
|
-
if (verb === "users.block" || verb === "users.unblock") return {
|
|
4051
|
-
token: ["user"],
|
|
4052
|
-
permissions: { blocking: "write" },
|
|
4053
|
-
note: "Needs a user token: a GitHub App installation cannot block for an account"
|
|
4054
|
-
};
|
|
4055
|
-
if (verb === "orgs.block" || verb === "orgs.unblock") return {
|
|
4056
|
-
token: ["admin:org"],
|
|
4057
|
-
permissions: { organization_user_blocking: "write" }
|
|
4058
|
-
};
|
|
4059
|
-
if (group === "users" || group === "search") return {
|
|
4060
|
-
token: ["read:user"],
|
|
4061
|
-
permissions: {}
|
|
4062
|
-
};
|
|
4063
|
-
if (group === "orgs") return {
|
|
4064
|
-
token: ["read:org"],
|
|
4065
|
-
permissions: { members: "read" }
|
|
4066
|
-
};
|
|
4067
|
-
if (verb === "threads.checks") return {
|
|
4068
|
-
token: ["repo"],
|
|
4069
|
-
permissions: {
|
|
4070
|
-
pull_requests: "read",
|
|
4071
|
-
checks: "read",
|
|
4072
|
-
statuses: "read"
|
|
4073
|
-
}
|
|
4074
|
-
};
|
|
4075
|
-
if (verb === "checks.list") return {
|
|
4076
|
-
token: ["repo"],
|
|
4077
|
-
permissions: {
|
|
4078
|
-
checks: "read",
|
|
4079
|
-
statuses: "read"
|
|
4080
|
-
}
|
|
4081
|
-
};
|
|
4082
|
-
if (verb === "checks.get") return {
|
|
4083
|
-
token: ["repo"],
|
|
4084
|
-
permissions: { checks: "read" }
|
|
4085
|
-
};
|
|
4086
|
-
if (verb === "checks.rerun") return {
|
|
4087
|
-
token: ["repo"],
|
|
4088
|
-
permissions: {
|
|
4089
|
-
checks: "write",
|
|
4090
|
-
actions: "write"
|
|
4091
|
-
},
|
|
4092
|
-
note: "A check run created by GitHub Actions is re-run as its job, which needs `actions: write`"
|
|
4093
|
-
};
|
|
4094
|
-
if (group === "ci") return {
|
|
4095
|
-
token: ["repo"],
|
|
4096
|
-
permissions: { actions: WRITE_VERBS.has(verb) ? "write" : "read" }
|
|
4097
|
-
};
|
|
4098
|
-
if (verb === "checks.report") return {
|
|
4099
|
-
token: ["repo:status"],
|
|
4100
|
-
permissions: {
|
|
4101
|
-
checks: "write",
|
|
4102
|
-
statuses: "write"
|
|
4103
|
-
}
|
|
4104
|
-
};
|
|
4105
|
-
if (verb === "threads.updateBranch") return {
|
|
4106
|
-
token: ["repo", "public_repo"],
|
|
4107
|
-
permissions: {
|
|
4108
|
-
pull_requests: "write",
|
|
4109
|
-
contents: "write"
|
|
4110
|
-
},
|
|
4111
|
-
note: "A GitHub App needs `contents: write` on the head repository"
|
|
4112
|
-
};
|
|
4113
|
-
if (verb === "repos.issueTypes") return {
|
|
4114
|
-
token: ["repo"],
|
|
4115
|
-
permissions: { metadata: "read" }
|
|
4116
|
-
};
|
|
4117
|
-
if (verb === "repos.branchRules") return {
|
|
4118
|
-
token: ["repo", "public_repo"],
|
|
4119
|
-
permissions: {
|
|
4120
|
-
contents: "read",
|
|
4121
|
-
metadata: "read",
|
|
4122
|
-
administration: "read"
|
|
4123
|
-
},
|
|
4124
|
-
note: "Classic branch protection shows its approvals only to an admin of the repository, or with `administration: read`"
|
|
4125
|
-
};
|
|
4126
|
-
if (verb === "threads.setIssueType") return {
|
|
4127
|
-
token: ["repo", "public_repo"],
|
|
4128
|
-
permissions: { issues: "write" },
|
|
4129
|
-
note: "Needs push access: without it, GitHub leaves the type unchanged"
|
|
4130
|
-
};
|
|
4131
|
-
const write = WRITE_VERBS.has(verb);
|
|
4132
|
-
if (PULL_CHECK_READS.has(verb)) return {
|
|
4133
|
-
token: ["repo", "public_repo"],
|
|
4134
|
-
permissions: {
|
|
4135
|
-
issues: "read",
|
|
4136
|
-
pull_requests: "read",
|
|
4137
|
-
checks: "read",
|
|
4138
|
-
statuses: "read"
|
|
4139
|
-
},
|
|
4140
|
-
note: "The `checks` of a pull request are read from its check runs and commit statuses"
|
|
4141
|
-
};
|
|
4142
|
-
if (group === "threads") return {
|
|
4143
|
-
token: ["repo", "public_repo"],
|
|
4144
|
-
permissions: {
|
|
4145
|
-
issues: write ? "write" : "read",
|
|
4146
|
-
pull_requests: write ? "write" : "read"
|
|
4147
|
-
}
|
|
4148
|
-
};
|
|
4149
|
-
if (group === "repos" || group === "contents" || group === "releases") return {
|
|
4150
|
-
token: ["repo", "public_repo"],
|
|
4151
|
-
permissions: {
|
|
4152
|
-
contents: write ? "write" : "read",
|
|
4153
|
-
metadata: "read"
|
|
4154
|
-
}
|
|
4155
|
-
};
|
|
4156
|
-
return {};
|
|
4157
|
-
}
|
|
4158
|
-
//#endregion
|
|
4159
|
-
export { toRepoRef as a, github, toLabels as i, toActor as n, toThreadState as o, toIssueType as r, FORGE as t };
|