@theholocron/holocron-plugin-github 5.0.0-alpha.38 → 5.0.0-alpha.381
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 +28 -3
- package/dist/index.d.mts +248 -71
- package/dist/index.mjs +1542 -68
- package/package.json +29 -25
package/dist/index.mjs
CHANGED
|
@@ -1,48 +1,74 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
+
import { AuthError, MissingTokenError, ProviderApiError, connectionProbe, createFeatureResolver, pickByCreation, readKeysLimited } from "@theholocron/cli";
|
|
2
3
|
import { createGitHubClient, createGitHubClient as createGitHubClient$1 } from "@theholocron/github-client";
|
|
3
|
-
import { AuthError, createFeatureResolver } from "@theholocron/cli";
|
|
4
4
|
import { mkdir, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
|
-
|
|
6
|
+
import { findRootSync } from "@theholocron/fs-utils";
|
|
7
|
+
import { ProviderApiError as ProviderApiError$1 } from "@theholocron/http-client";
|
|
8
|
+
import { errorMessage } from "@theholocron/misc-utils";
|
|
9
|
+
// src/auth.ts
|
|
10
|
+
/** Resolves the token for read-only GitHub access (`HOLOCRON_READ_TOKEN`, keyring key `github.read`). */
|
|
7
11
|
const resolveReadToken = createFeatureResolver({
|
|
8
12
|
envName: "HOLOCRON_READ_TOKEN",
|
|
9
13
|
keyringKey: "github.read"
|
|
10
14
|
});
|
|
15
|
+
/** Resolves the token for issue operations (`HOLOCRON_ISSUES_TOKEN`, keyring key `github.issues`). */
|
|
11
16
|
const resolveIssuesToken = createFeatureResolver({
|
|
12
17
|
envName: "HOLOCRON_ISSUES_TOKEN",
|
|
13
18
|
keyringKey: "github.issues"
|
|
14
19
|
});
|
|
20
|
+
/** Resolves the token for syncing repo files and settings (`HOLOCRON_SYNC_TOKEN`, keyring key `github.sync`). */
|
|
15
21
|
const resolveSyncToken = createFeatureResolver({
|
|
16
22
|
envName: "HOLOCRON_SYNC_TOKEN",
|
|
17
23
|
keyringKey: "github.sync"
|
|
18
24
|
});
|
|
25
|
+
/** Resolves the token for release operations (`HOLOCRON_RELEASE_TOKEN`, keyring key `github.release`). */
|
|
19
26
|
const resolveReleaseToken = createFeatureResolver({
|
|
20
27
|
envName: "HOLOCRON_RELEASE_TOKEN",
|
|
21
28
|
keyringKey: "github.release"
|
|
22
29
|
});
|
|
30
|
+
/** Resolves the repo-scoped admin token (`HOLOCRON_ADMIN_TOKEN`, keyring key `github.admin`). */
|
|
23
31
|
const resolveAdminToken = createFeatureResolver({
|
|
24
32
|
envName: "HOLOCRON_ADMIN_TOKEN",
|
|
25
33
|
keyringKey: "github.admin"
|
|
26
34
|
});
|
|
35
|
+
/** Resolves the org-level secrets token (`HOLOCRON_SECRETS_TOKEN`, keyring key `github.secrets`). */
|
|
36
|
+
const resolveSecretsToken = createFeatureResolver({
|
|
37
|
+
envName: "HOLOCRON_SECRETS_TOKEN",
|
|
38
|
+
keyringKey: "github.secrets"
|
|
39
|
+
});
|
|
40
|
+
/** Resolves the token for deployment operations (`HOLOCRON_DEPLOY_TOKEN`, keyring key `github.deploy`). */
|
|
27
41
|
const resolveDeployToken = createFeatureResolver({
|
|
28
42
|
envName: "HOLOCRON_DEPLOY_TOKEN",
|
|
29
43
|
keyringKey: "github.deploy"
|
|
30
44
|
});
|
|
45
|
+
/**
|
|
46
|
+
* Resolves the token for the user-sync files in the org's private config repo (`HOLOCRON_USER_SYNC_TOKEN`, keyring
|
|
47
|
+
* key `github.user-sync`).
|
|
48
|
+
*/
|
|
49
|
+
const resolveUserSyncToken = createFeatureResolver({
|
|
50
|
+
envName: "HOLOCRON_USER_SYNC_TOKEN",
|
|
51
|
+
keyringKey: "github.user-sync"
|
|
52
|
+
});
|
|
53
|
+
/** Resolves the org-level token (`HOLOCRON_ORG_TOKEN`, keyring key `github.org`). */
|
|
31
54
|
const resolveOrgToken = createFeatureResolver({
|
|
32
55
|
envName: "HOLOCRON_ORG_TOKEN",
|
|
33
56
|
keyringKey: "github.org"
|
|
34
57
|
});
|
|
35
|
-
|
|
36
|
-
|
|
58
|
+
// src/capabilities/ci.ts
|
|
59
|
+
/** The GitHub implementation of the `ci` capability, backed by GitHub Actions workflow runs. */
|
|
37
60
|
var GitHubCi = class {
|
|
38
61
|
client;
|
|
39
62
|
opts;
|
|
63
|
+
/** Capability key, always `"ci"`. */
|
|
40
64
|
key = "ci";
|
|
65
|
+
/** Provider name, always `"github"`. */
|
|
41
66
|
providerName = "github";
|
|
42
67
|
constructor(client, opts) {
|
|
43
68
|
this.client = client;
|
|
44
69
|
this.opts = opts;
|
|
45
70
|
}
|
|
71
|
+
/** Lists workflow runs for the repo, optionally filtered by branch, status and limit. */
|
|
46
72
|
async listRuns(filter) {
|
|
47
73
|
return (await this.client.workflows.listRuns(this.opts.repo, {
|
|
48
74
|
branch: filter?.branch,
|
|
@@ -50,6 +76,7 @@ var GitHubCi = class {
|
|
|
50
76
|
status: filter?.status
|
|
51
77
|
})).map((r) => this.mapRun(r));
|
|
52
78
|
}
|
|
79
|
+
/** Fetches one workflow run by id. */
|
|
53
80
|
async getRun(id) {
|
|
54
81
|
const raw = await this.client.workflows.getRun(this.opts.repo, id);
|
|
55
82
|
return this.mapRun(raw);
|
|
@@ -77,17 +104,20 @@ var GitHubCi = class {
|
|
|
77
104
|
}
|
|
78
105
|
}
|
|
79
106
|
};
|
|
80
|
-
|
|
81
|
-
|
|
107
|
+
// src/capabilities/environments.ts
|
|
108
|
+
/** The GitHub implementation of the `environments` capability, managing a repo's deployment environments. */
|
|
82
109
|
var GitHubEnvironments = class {
|
|
83
110
|
client;
|
|
84
111
|
opts;
|
|
112
|
+
/** Capability key, always `"environments"`. */
|
|
85
113
|
key = "environments";
|
|
114
|
+
/** Provider name, always `"github"`. */
|
|
86
115
|
providerName = "github";
|
|
87
116
|
constructor(client, opts) {
|
|
88
117
|
this.client = client;
|
|
89
118
|
this.opts = opts;
|
|
90
119
|
}
|
|
120
|
+
/** Lists the repo's environments with their wait timer, self-review rule and required reviewers. */
|
|
91
121
|
async listEnvironments() {
|
|
92
122
|
return (await this.client.environments.listEnvironments(this.opts.repo)).map((e) => ({
|
|
93
123
|
name: e.name,
|
|
@@ -96,6 +126,7 @@ var GitHubEnvironments = class {
|
|
|
96
126
|
reviewers: this.flattenReviewers(e.protection_rules)
|
|
97
127
|
}));
|
|
98
128
|
}
|
|
129
|
+
/** Creates or updates an environment, sending only the settings the given environment defines. */
|
|
99
130
|
async upsertEnvironment(env) {
|
|
100
131
|
const body = {};
|
|
101
132
|
if (env.waitTimer !== void 0) body.wait_timer = env.waitTimer;
|
|
@@ -106,6 +137,7 @@ var GitHubEnvironments = class {
|
|
|
106
137
|
}));
|
|
107
138
|
await this.client.environments.upsertEnvironment(this.opts.repo, env.name, body);
|
|
108
139
|
}
|
|
140
|
+
/** Deletes the named environment. */
|
|
109
141
|
async deleteEnvironment(name) {
|
|
110
142
|
await this.client.environments.deleteEnvironment(this.opts.repo, name);
|
|
111
143
|
}
|
|
@@ -119,11 +151,337 @@ var GitHubEnvironments = class {
|
|
|
119
151
|
}));
|
|
120
152
|
}
|
|
121
153
|
};
|
|
122
|
-
|
|
123
|
-
|
|
154
|
+
// src/capabilities/issues-migration.ts
|
|
155
|
+
/**
|
|
156
|
+
* Export and import of GitHub issues for `holocron migrate`.
|
|
157
|
+
*
|
|
158
|
+
* GitHub holds less than a planning tool, so what does not fit is named in each result's `dropped` list rather than
|
|
159
|
+
* lost quietly:
|
|
160
|
+
* - priority is a label (`priority: high`), because on GitHub it lives in a project field, not on the issue;
|
|
161
|
+
* - an import cannot backdate an issue or a comment, and cannot post as someone else, so the original date and
|
|
162
|
+
* author go in the text;
|
|
163
|
+
* - an import does not set parent or blocked-by links (they need GraphQL node ids of issues made in the same run);
|
|
164
|
+
* - an assignee is not mapped (a Linear user is not a GitHub login).
|
|
165
|
+
* A migrated issue ends with `<!-- holocron:migrated-from <url> -->`, which is how a second run finds it.
|
|
166
|
+
*/
|
|
167
|
+
const MARKER = /<!-- holocron:migrated-from (\S+) -->/;
|
|
168
|
+
const PRIORITY_LABEL = /^priority\s*[:/-]\s*(urgent|high|medium|low)$/i;
|
|
169
|
+
const LINK_QUERY = `query($owner: String!, $name: String!, $number: Int!) { repository(owner: $owner, name: $name) {
|
|
170
|
+
issue(number: $number) { parent { number } blockedBy(first: 50) { nodes { number } } } } }`;
|
|
171
|
+
/** Splits `priority: high` labels from the rest. */
|
|
172
|
+
function splitLabels(names) {
|
|
173
|
+
let priority;
|
|
174
|
+
const labels = [];
|
|
175
|
+
for (const name of names) {
|
|
176
|
+
const match = PRIORITY_LABEL.exec(name);
|
|
177
|
+
if (match) priority = match[1].toLowerCase();
|
|
178
|
+
else labels.push(name);
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
labels,
|
|
182
|
+
...priority ? { priority } : {}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function categoryOf(issue) {
|
|
186
|
+
if (issue.state === "closed") return "done";
|
|
187
|
+
const names = issue.labels.map((l) => l.name.toLowerCase());
|
|
188
|
+
if (names.some((n) => n === "status:in-review" || n === "status: in review")) return "in-review";
|
|
189
|
+
if (names.some((n) => n === "status:in-progress" || n === "status: in progress")) return "in-progress";
|
|
190
|
+
return "open";
|
|
191
|
+
}
|
|
192
|
+
/** How many issues an export fetches at once. GitHub's secondary rate limit punishes bursts of requests, not volume. */
|
|
193
|
+
const EXPORT_CONCURRENCY = 4;
|
|
194
|
+
/** Runs `fn` over `items`, at most `limit` at a time, and returns the results in the order of `items`. */
|
|
195
|
+
async function mapLimit(items, limit, fn) {
|
|
196
|
+
const results = new Array(items.length);
|
|
197
|
+
let next = 0;
|
|
198
|
+
const worker = async () => {
|
|
199
|
+
while (next < items.length) {
|
|
200
|
+
const at = next++;
|
|
201
|
+
results[at] = await fn(items[at]);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
205
|
+
return results;
|
|
206
|
+
}
|
|
207
|
+
/** GitHub's own answer to a burst of requests (403 or 429 naming the secondary limit) becomes a message that says what to do. */
|
|
208
|
+
function explainSecondaryLimit(err) {
|
|
209
|
+
if (err instanceof ProviderApiError && (err.status === 403 || err.status === 429) && String(err.details).includes("secondary rate limit")) return /* @__PURE__ */ new Error("GitHub's secondary rate limit stopped the export. It limits bursts of requests, not the hourly quota, and nothing has been written. Wait a couple of minutes and run the command again.");
|
|
210
|
+
return err;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Reads the issues `selector` names, with their comments, priority label, parent and blockers.
|
|
214
|
+
*
|
|
215
|
+
* With `limit`, only that many survivors of the other filters are read, from the `order` end of the creation order. A
|
|
216
|
+
* list of keys is sorted by issue number (which rises with creation in one repository) before anything is fetched, then
|
|
217
|
+
* fetched a few at a time until enough are kept; a listing already carries `created_at`, so it is cut before the
|
|
218
|
+
* per-issue comment and link requests. `info.matched` receives how many the selection matched before the cut.
|
|
219
|
+
*/
|
|
220
|
+
async function exportIssues(client, repo, selector, info = {}) {
|
|
221
|
+
return readIssues(client, repo, selector, info).catch((err) => {
|
|
222
|
+
throw explainSecondaryLimit(err);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
async function readIssues(client, repo, selector, info) {
|
|
226
|
+
const [owner = "", name = ""] = repo.split("/", 2);
|
|
227
|
+
const since = selector.since ? Date.parse(selector.since) : void 0;
|
|
228
|
+
const survives = (i) => !i.pull_request && !(selector.openOnly && i.state === "closed") && (since === void 0 || Date.parse(i.updated_at) >= since);
|
|
229
|
+
const { limit, order = "oldest" } = selector;
|
|
230
|
+
let issues;
|
|
231
|
+
if (selector.keys) {
|
|
232
|
+
const fetch = (k) => client.issues.getIssue(repo, parseNumber(k));
|
|
233
|
+
info.matched = selector.keys.length;
|
|
234
|
+
issues = limit === void 0 ? (await mapLimit(selector.keys, EXPORT_CONCURRENCY, fetch)).filter(survives) : await readKeysLimited({
|
|
235
|
+
keys: selector.keys,
|
|
236
|
+
order,
|
|
237
|
+
limit,
|
|
238
|
+
concurrency: EXPORT_CONCURRENCY,
|
|
239
|
+
fetch,
|
|
240
|
+
keep: survives
|
|
241
|
+
});
|
|
242
|
+
} else {
|
|
243
|
+
let raw;
|
|
244
|
+
if (selector.milestone) {
|
|
245
|
+
const milestone = await findMilestone(client, repo, selector.milestone);
|
|
246
|
+
if (!milestone) throw new Error(`Milestone "${selector.milestone}" not found in ${repo}.`);
|
|
247
|
+
raw = await listAll(client, repo, { milestone: String(milestone.number) });
|
|
248
|
+
} else if (selector.all) raw = await listAll(client, repo, {});
|
|
249
|
+
else throw new Error("export needs keys, a milestone or all");
|
|
250
|
+
issues = raw.filter(survives);
|
|
251
|
+
info.matched = issues.length;
|
|
252
|
+
if (limit !== void 0) issues = pickByCreation(issues, (i) => i.created_at ?? i.updated_at, order, limit);
|
|
253
|
+
}
|
|
254
|
+
const records = [];
|
|
255
|
+
for (const issue of issues) {
|
|
256
|
+
const comments = await client.issues.listComments(repo, issue.number);
|
|
257
|
+
const links = (await client.graphql.query(LINK_QUERY, {
|
|
258
|
+
owner,
|
|
259
|
+
name,
|
|
260
|
+
number: issue.number
|
|
261
|
+
}).catch(() => void 0))?.repository.issue;
|
|
262
|
+
const { labels, priority } = splitLabels(issue.labels.map((l) => l.name));
|
|
263
|
+
const body = issue.body?.replace(MARKER, "").trimEnd();
|
|
264
|
+
const migratedFrom = issue.body ? MARKER.exec(issue.body)?.[1] : void 0;
|
|
265
|
+
records.push({
|
|
266
|
+
key: `#${issue.number}`,
|
|
267
|
+
url: issue.html_url,
|
|
268
|
+
title: issue.title,
|
|
269
|
+
...body ? { body } : {},
|
|
270
|
+
statusCategory: categoryOf(issue),
|
|
271
|
+
closed: issue.state === "closed",
|
|
272
|
+
...priority ? { priority } : {},
|
|
273
|
+
labels: labels.filter((l) => !l.toLowerCase().startsWith("status:")),
|
|
274
|
+
...issue.assignee ? { assignee: {
|
|
275
|
+
id: issue.assignee.login,
|
|
276
|
+
displayName: issue.assignee.name ?? issue.assignee.login,
|
|
277
|
+
...issue.assignee.email ? { emailAddress: issue.assignee.email } : {}
|
|
278
|
+
} } : {},
|
|
279
|
+
...issue.milestone ? { milestone: issue.milestone.title } : {},
|
|
280
|
+
...links?.parent ? { parent: `#${links.parent.number}` } : {},
|
|
281
|
+
blockedBy: (links?.blockedBy.nodes ?? []).map((n) => `#${n.number}`),
|
|
282
|
+
comments: comments.map((c) => ({
|
|
283
|
+
...c.user ? { author: c.user.login } : {},
|
|
284
|
+
body: c.body,
|
|
285
|
+
createdAt: c.created_at
|
|
286
|
+
})),
|
|
287
|
+
createdAt: issue.created_at ?? issue.updated_at,
|
|
288
|
+
updatedAt: issue.updated_at,
|
|
289
|
+
...migratedFrom ? { migratedFrom } : {}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
return records;
|
|
293
|
+
}
|
|
294
|
+
/** Makes the records as issues, skipping any whose source address an earlier run already recorded. */
|
|
295
|
+
async function importIssues(client, repo, records, options = {}) {
|
|
296
|
+
const existing = /* @__PURE__ */ new Map();
|
|
297
|
+
for (const issue of await listAll(client, repo, {})) {
|
|
298
|
+
const url = issue.body ? MARKER.exec(issue.body)?.[1] : void 0;
|
|
299
|
+
if (url) existing.set(url, issue.number);
|
|
300
|
+
}
|
|
301
|
+
const results = [];
|
|
302
|
+
for (const record of records) {
|
|
303
|
+
const found = existing.get(record.url);
|
|
304
|
+
if (found !== void 0) {
|
|
305
|
+
results.push({
|
|
306
|
+
source: record.key,
|
|
307
|
+
key: `#${found}`,
|
|
308
|
+
created: false,
|
|
309
|
+
dropped: []
|
|
310
|
+
});
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
const dropped = droppedFor(record);
|
|
314
|
+
if (options.dryRun) {
|
|
315
|
+
results.push({
|
|
316
|
+
source: record.key,
|
|
317
|
+
created: true,
|
|
318
|
+
dropped
|
|
319
|
+
});
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
const number = await createFromRecord(client, repo, record, options);
|
|
323
|
+
results.push({
|
|
324
|
+
source: record.key,
|
|
325
|
+
key: `#${number}`,
|
|
326
|
+
created: true,
|
|
327
|
+
dropped
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
return results;
|
|
331
|
+
}
|
|
332
|
+
/** What GitHub cannot hold of this record, for the report. */
|
|
333
|
+
function droppedFor(record) {
|
|
334
|
+
const dropped = ["createdAt (GitHub sets it; the original date is in the text)"];
|
|
335
|
+
if (record.assignee) dropped.push("assignee (not mapped)");
|
|
336
|
+
if (record.parent) dropped.push("parent (not set on GitHub)");
|
|
337
|
+
if (record.blockedBy.length > 0) dropped.push("blockedBy (not set on GitHub)");
|
|
338
|
+
return dropped;
|
|
339
|
+
}
|
|
340
|
+
/** The labels a record becomes on GitHub: its own, plus `priority: <level>` (GitHub's priority is a label). */
|
|
341
|
+
function labelsFor(record) {
|
|
342
|
+
return [...record.labels, ...record.priority && record.priority !== "none" ? [`priority: ${record.priority}`] : []];
|
|
343
|
+
}
|
|
344
|
+
/** The text a comment gets when it is copied: GitHub cannot post as another author or backdate. */
|
|
345
|
+
function renderComment(comment) {
|
|
346
|
+
return `${comment.author ? `**${comment.author}**` : "Someone"} commented on ${comment.createdAt}:\n\n${comment.body}`;
|
|
347
|
+
}
|
|
348
|
+
/** Makes one issue from a record, with its comments, and closes it when the record is closed; returns its number. */
|
|
349
|
+
async function createFromRecord(client, repo, record, options) {
|
|
350
|
+
const milestoneName = options.milestone ?? record.milestone;
|
|
351
|
+
const milestone = milestoneName ? await ensureMilestone(client, repo, milestoneName) : void 0;
|
|
352
|
+
const labels = labelsFor(record);
|
|
353
|
+
const created = await client.issues.createIssue(repo, {
|
|
354
|
+
title: record.title,
|
|
355
|
+
body: withProvenance(record),
|
|
356
|
+
...labels.length > 0 ? { labels } : {},
|
|
357
|
+
...milestone !== void 0 ? { milestone } : {}
|
|
358
|
+
});
|
|
359
|
+
for (const comment of record.comments) await client.issues.createComment(repo, created.number, renderComment(comment));
|
|
360
|
+
if (record.closed) await client.issues.updateIssue(repo, created.number, {
|
|
361
|
+
state: "closed",
|
|
362
|
+
state_reason: "completed"
|
|
363
|
+
});
|
|
364
|
+
return created.number;
|
|
365
|
+
}
|
|
366
|
+
/** The text of a migrated issue: the record's body, then where it came from and the marker a second run looks for. */
|
|
367
|
+
function withProvenance(record) {
|
|
368
|
+
return `${record.body ? `${record.body}\n\n` : ""}---\n_Migrated from [${record.key}](${record.url}); created ${record.createdAt}._\n<!-- holocron:migrated-from ${record.url} -->`;
|
|
369
|
+
}
|
|
370
|
+
function parseNumber(key) {
|
|
371
|
+
const n = key.trim().replace(/^.*#/, "");
|
|
372
|
+
if (!/^\d+$/.test(n)) throw new Error(`Invalid GitHub issue key "${key}" — expected #N or N.`);
|
|
373
|
+
return parseInt(n, 10);
|
|
374
|
+
}
|
|
375
|
+
async function listAll(client, repo, extra) {
|
|
376
|
+
const all = [];
|
|
377
|
+
for (let page = 1;; page++) {
|
|
378
|
+
const batch = await client.issues.listIssues(repo, {
|
|
379
|
+
state: "all",
|
|
380
|
+
per_page: 100,
|
|
381
|
+
page,
|
|
382
|
+
...extra
|
|
383
|
+
});
|
|
384
|
+
all.push(...batch);
|
|
385
|
+
if (batch.length < 100) return all;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
async function findMilestone(client, repo, ref) {
|
|
389
|
+
return (await client.issues.listMilestones(repo, { state: "all" })).find((m) => String(m.number) === ref || m.title.toLowerCase() === ref.toLowerCase());
|
|
390
|
+
}
|
|
391
|
+
async function ensureMilestone(client, repo, title) {
|
|
392
|
+
return (await findMilestone(client, repo, title))?.number ?? (await client.issues.createMilestone(repo, title)).number;
|
|
393
|
+
}
|
|
394
|
+
// src/capabilities/issues-sync.ts
|
|
395
|
+
const COMMENT_HEADER = /^(?:\*\*.*?\*\*|Someone) commented on (\S+?):\n/;
|
|
396
|
+
/** Whether GitHub is asking to be left alone: a 429, or a 403 that says it is a rate limit. */
|
|
397
|
+
function isRateLimited(err) {
|
|
398
|
+
return err instanceof ProviderApiError && (err.status === 429 || err.status === 403 && /rate limit/i.test(`${err.message} ${String(err.details)}`));
|
|
399
|
+
}
|
|
400
|
+
const normalize = (text) => text.replace(/\r\n/g, "\n").trim();
|
|
401
|
+
const sorted = (names) => names.map((n) => n.toLowerCase()).sort().join("\n");
|
|
402
|
+
/** Makes the records missing from the repo and updates the ones an earlier run made. See the file comment. */
|
|
403
|
+
async function syncIssues(client, repo, records, options = {}) {
|
|
404
|
+
const existing = /* @__PURE__ */ new Map();
|
|
405
|
+
for (const issue of await listAll(client, repo, {})) {
|
|
406
|
+
const url = issue.body ? MARKER.exec(issue.body)?.[1] : void 0;
|
|
407
|
+
if (url) existing.set(url, issue);
|
|
408
|
+
}
|
|
409
|
+
const results = [];
|
|
410
|
+
for (const record of records) try {
|
|
411
|
+
const found = existing.get(record.url);
|
|
412
|
+
results.push(found ? await update(client, repo, found, record, options) : await create(client, repo, record, options));
|
|
413
|
+
} catch (err) {
|
|
414
|
+
if (isRateLimited(err)) return results;
|
|
415
|
+
throw err;
|
|
416
|
+
}
|
|
417
|
+
return results;
|
|
418
|
+
}
|
|
419
|
+
async function create(client, repo, record, options) {
|
|
420
|
+
const dropped = droppedFor(record);
|
|
421
|
+
if (options.dryRun) return {
|
|
422
|
+
source: record.key,
|
|
423
|
+
created: true,
|
|
424
|
+
updated: false,
|
|
425
|
+
changes: [],
|
|
426
|
+
dropped
|
|
427
|
+
};
|
|
428
|
+
const number = await createFromRecord(client, repo, record, options);
|
|
429
|
+
return {
|
|
430
|
+
source: record.key,
|
|
431
|
+
key: `#${number}`,
|
|
432
|
+
created: true,
|
|
433
|
+
updated: false,
|
|
434
|
+
changes: [],
|
|
435
|
+
dropped
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
async function update(client, repo, issue, record, options) {
|
|
439
|
+
const patch = {};
|
|
440
|
+
const changes = [];
|
|
441
|
+
if (issue.title !== record.title) {
|
|
442
|
+
patch.title = record.title;
|
|
443
|
+
changes.push("title");
|
|
444
|
+
}
|
|
445
|
+
const body = withProvenance(record);
|
|
446
|
+
if (normalize(issue.body) !== normalize(body)) {
|
|
447
|
+
patch.body = body;
|
|
448
|
+
changes.push("description");
|
|
449
|
+
}
|
|
450
|
+
if (issue.state === "closed" !== record.closed) {
|
|
451
|
+
patch.state = record.closed ? "closed" : "open";
|
|
452
|
+
if (record.closed) patch.state_reason = "completed";
|
|
453
|
+
changes.push("state");
|
|
454
|
+
}
|
|
455
|
+
const current = issue.labels.map((l) => l.name);
|
|
456
|
+
const finalLabels = [...labelsFor(record), ...current.filter((n) => n.toLowerCase().startsWith("status:"))];
|
|
457
|
+
if (sorted(finalLabels) !== sorted(current)) {
|
|
458
|
+
patch.labels = finalLabels;
|
|
459
|
+
changes.push("labels");
|
|
460
|
+
}
|
|
461
|
+
const comments = await client.issues.listComments(repo, issue.number);
|
|
462
|
+
const seen = new Set(comments.map((c) => COMMENT_HEADER.exec(c.body)?.[1]));
|
|
463
|
+
const missing = record.comments.filter((c) => !seen.has(c.createdAt));
|
|
464
|
+
if (missing.length > 0) changes.push("comments");
|
|
465
|
+
if (!options.dryRun) {
|
|
466
|
+
if (Object.keys(patch).length > 0) await client.issues.updateIssue(repo, issue.number, patch);
|
|
467
|
+
for (const comment of missing) await client.issues.createComment(repo, issue.number, renderComment(comment));
|
|
468
|
+
}
|
|
469
|
+
return {
|
|
470
|
+
source: record.key,
|
|
471
|
+
key: `#${issue.number}`,
|
|
472
|
+
created: false,
|
|
473
|
+
updated: changes.length > 0,
|
|
474
|
+
changes,
|
|
475
|
+
dropped: droppedFor(record)
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
// src/capabilities/issues.ts
|
|
479
|
+
/** The GitHub implementation of the `issues` capability, backed by GitHub Issues and status labels. */
|
|
124
480
|
var GitHubIssues = class {
|
|
125
481
|
client;
|
|
482
|
+
/** Capability key, always `"issues"`. */
|
|
126
483
|
key = "issues";
|
|
484
|
+
/** Provider name, always `"github"`. */
|
|
127
485
|
providerName = "github";
|
|
128
486
|
owner;
|
|
129
487
|
repoName;
|
|
@@ -145,6 +503,7 @@ var GitHubIssues = class {
|
|
|
145
503
|
...raw.email ? { emailAddress: raw.email } : {}
|
|
146
504
|
};
|
|
147
505
|
}
|
|
506
|
+
/** Searches the repo's issues, newest update first, leaving out pull requests. */
|
|
148
507
|
async search(filter) {
|
|
149
508
|
const params = {
|
|
150
509
|
state: filter.openOnly ? "open" : "all",
|
|
@@ -164,11 +523,13 @@ var GitHubIssues = class {
|
|
|
164
523
|
assignee: params.assignee
|
|
165
524
|
})).filter((i) => !i.pull_request).map((i) => this.mapIssue(i));
|
|
166
525
|
}
|
|
526
|
+
/** Fetches one issue by its key. */
|
|
167
527
|
async get(key) {
|
|
168
528
|
const number = parseIssueNumber(key, this.owner, this.repoName);
|
|
169
529
|
const raw = await this.client.issues.getIssue(this.repo, number);
|
|
170
530
|
return this.mapIssue(raw);
|
|
171
531
|
}
|
|
532
|
+
/** Creates an issue and returns its key as `#<number>`; the milestone is resolved from its title. */
|
|
172
533
|
async create(input) {
|
|
173
534
|
const body = { title: input.summary };
|
|
174
535
|
if (input.body) body.body = input.body;
|
|
@@ -216,10 +577,12 @@ var GitHubIssues = class {
|
|
|
216
577
|
via: `label set to ${targetLabel}`
|
|
217
578
|
};
|
|
218
579
|
}
|
|
580
|
+
/** Adds a comment to the issue with the given key. */
|
|
219
581
|
async comment(key, body) {
|
|
220
582
|
const number = parseIssueNumber(key, this.owner, this.repoName);
|
|
221
583
|
await this.client.issues.createComment(this.repo, number, body);
|
|
222
584
|
}
|
|
585
|
+
/** Checks the authenticated user, the repo and the label-backed lifecycle slots, and reports what resolves. */
|
|
223
586
|
async doctor() {
|
|
224
587
|
const me = await this.getMyself();
|
|
225
588
|
const repo = await this.client.repos.getRepo(this.repo);
|
|
@@ -288,6 +651,18 @@ var GitHubIssues = class {
|
|
|
288
651
|
lifecycle
|
|
289
652
|
};
|
|
290
653
|
}
|
|
654
|
+
/** Reads issues with their comments, priority label, parent and blockers, for `holocron migrate`. */
|
|
655
|
+
export(selector, info) {
|
|
656
|
+
return exportIssues(this.client, this.repo, selector, info);
|
|
657
|
+
}
|
|
658
|
+
/** Makes the records as issues; one already made by an earlier run is skipped. */
|
|
659
|
+
import(records, options) {
|
|
660
|
+
return importIssues(this.client, this.repo, records, options);
|
|
661
|
+
}
|
|
662
|
+
/** Like `import`, and it also updates what an earlier import or sync made, for `holocron sync issues`. */
|
|
663
|
+
sync(records, options) {
|
|
664
|
+
return syncIssues(this.client, this.repo, records, options);
|
|
665
|
+
}
|
|
291
666
|
async resolveMilestone(ref) {
|
|
292
667
|
if (/^\d+$/.test(ref)) return parseInt(ref, 10);
|
|
293
668
|
const match = (await this.client.issues.listMilestones(this.repo, { state: "all" })).find((m) => m.title.toLowerCase() === ref.toLowerCase());
|
|
@@ -337,8 +712,584 @@ function parseIssueNumber(key, owner, repoName) {
|
|
|
337
712
|
if (!/^\d+$/.test(num)) throw new Error(`Invalid GitHub issue key "${key}" — expected #N or N.`);
|
|
338
713
|
return parseInt(num, 10);
|
|
339
714
|
}
|
|
340
|
-
|
|
341
|
-
|
|
715
|
+
// src/capabilities/projects.ts
|
|
716
|
+
/** The name of the single select field that holds an item's status. */
|
|
717
|
+
const STATUS_FIELD = "Status";
|
|
718
|
+
/** The name of the field `move` carries over besides the status. */
|
|
719
|
+
const PRIORITY_FIELD = "Priority";
|
|
720
|
+
const P_LEVELS = {
|
|
721
|
+
p0: "urgent",
|
|
722
|
+
p1: "high",
|
|
723
|
+
p2: "medium",
|
|
724
|
+
p3: "low"
|
|
725
|
+
};
|
|
726
|
+
/** The neutral priority a `Priority` option stands for, by its name; undefined for a name that is not one of them. */
|
|
727
|
+
function priorityOf(value) {
|
|
728
|
+
const name = value?.trim().toLowerCase();
|
|
729
|
+
if (name === "urgent" || name === "high" || name === "medium" || name === "low") return name;
|
|
730
|
+
return name ? P_LEVELS[name] : void 0;
|
|
731
|
+
}
|
|
732
|
+
const PROJECT_FIELDS = "id number title closed url";
|
|
733
|
+
const BOARD_QUERY = `query($id: ID!) { node(id: $id) { ... on ProjectV2 {
|
|
734
|
+
${PROJECT_FIELDS}
|
|
735
|
+
fields(first: 100) { nodes {
|
|
736
|
+
... on ProjectV2FieldCommon { id name dataType }
|
|
737
|
+
... on ProjectV2SingleSelectField { options { id name color description } }
|
|
738
|
+
} }
|
|
739
|
+
views(first: 50) { nodes { id name layout filter groupByFields(first: 5) { nodes { ... on ProjectV2FieldCommon { name } } } } }
|
|
740
|
+
workflows(first: 50) { nodes { id name enabled } }
|
|
741
|
+
} } }`;
|
|
742
|
+
const ITEMS_QUERY = `query($id: ID!, $after: String) { node(id: $id) { ... on ProjectV2 {
|
|
743
|
+
items(first: 100, after: $after) {
|
|
744
|
+
pageInfo { hasNextPage endCursor }
|
|
745
|
+
nodes {
|
|
746
|
+
id
|
|
747
|
+
fieldValues(first: 30) { nodes { ... on ProjectV2ItemFieldSingleSelectValue { name field { ... on ProjectV2FieldCommon { name } } } } }
|
|
748
|
+
content {
|
|
749
|
+
__typename
|
|
750
|
+
... on Issue { id number title state repository { nameWithOwner } blockedBy(first: 50) { nodes { number state repository { nameWithOwner } } } }
|
|
751
|
+
... on PullRequest { id number title state repository { nameWithOwner } }
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
} } }`;
|
|
756
|
+
const LIST_QUERY = `query($owner: String!, $after: String) { organization(login: $owner) { id projectsV2(first: 100, after: $after) {
|
|
757
|
+
pageInfo { hasNextPage endCursor }
|
|
758
|
+
nodes { ${PROJECT_FIELDS} }
|
|
759
|
+
} } }`;
|
|
760
|
+
const OWNER_QUERY = "query($owner: String!) { organization(login: $owner) { id } }";
|
|
761
|
+
const SET_VALUE = `mutation($project: ID!, $item: ID!, $field: ID!, $option: String!) {
|
|
762
|
+
updateProjectV2ItemFieldValue(input: { projectId: $project, itemId: $item, fieldId: $field, value: { singleSelectOptionId: $option } }) { projectV2Item { id } }
|
|
763
|
+
}`;
|
|
764
|
+
const UPDATE_OPTIONS = `mutation($field: ID!, $options: [ProjectV2SingleSelectFieldOptionInput!]!) {
|
|
765
|
+
updateProjectV2Field(input: { fieldId: $field, singleSelectOptions: $options }) { projectV2Field { ... on ProjectV2SingleSelectField { id } } }
|
|
766
|
+
}`;
|
|
767
|
+
const DATA_TYPES = {
|
|
768
|
+
single_select: "SINGLE_SELECT",
|
|
769
|
+
text: "TEXT",
|
|
770
|
+
number: "NUMBER",
|
|
771
|
+
date: "DATE",
|
|
772
|
+
iteration: "ITERATION"
|
|
773
|
+
};
|
|
774
|
+
function fieldTypeOf(dataType) {
|
|
775
|
+
return Object.keys(DATA_TYPES).find((t) => DATA_TYPES[t] === dataType);
|
|
776
|
+
}
|
|
777
|
+
function toSummary(n) {
|
|
778
|
+
return {
|
|
779
|
+
id: n.id,
|
|
780
|
+
number: n.number,
|
|
781
|
+
name: n.title,
|
|
782
|
+
url: n.url,
|
|
783
|
+
closed: n.closed
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
function toOptionInput(o) {
|
|
787
|
+
return {
|
|
788
|
+
...o.id ? { id: o.id } : {},
|
|
789
|
+
name: o.name,
|
|
790
|
+
color: (o.color ?? "GRAY").toUpperCase(),
|
|
791
|
+
description: o.description ?? ""
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
/** The GitHub implementation of the `projects` capability, backed by Projects v2. */
|
|
795
|
+
var GitHubProjects = class {
|
|
796
|
+
graphql;
|
|
797
|
+
/** Capability key, always `"projects"`. */
|
|
798
|
+
key = "projects";
|
|
799
|
+
/** Provider name, always `"github"`. */
|
|
800
|
+
providerName = "github";
|
|
801
|
+
repo;
|
|
802
|
+
constructor(graphql, opts) {
|
|
803
|
+
this.graphql = graphql;
|
|
804
|
+
this.repo = opts.repo;
|
|
805
|
+
}
|
|
806
|
+
/** Every board of the organization, open and closed. */
|
|
807
|
+
async list(owner) {
|
|
808
|
+
const boards = [];
|
|
809
|
+
let after = null;
|
|
810
|
+
for (;;) {
|
|
811
|
+
const page = (await this.graphql.query(LIST_QUERY, {
|
|
812
|
+
owner,
|
|
813
|
+
after
|
|
814
|
+
})).organization.projectsV2;
|
|
815
|
+
boards.push(...page.nodes.map(toSummary));
|
|
816
|
+
if (!page.pageInfo.hasNextPage) return boards;
|
|
817
|
+
after = page.pageInfo.endCursor;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
/** The open board with exactly this name. */
|
|
821
|
+
async find(owner, name) {
|
|
822
|
+
return (await this.list(owner)).find((b) => !b.closed && b.name === name);
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Makes a board. With `template.source` naming an open board it is copied (fields, options, views and automation
|
|
826
|
+
* rules, no items); otherwise the board is created and brought in line with the template.
|
|
827
|
+
*/
|
|
828
|
+
async create(owner, name, template) {
|
|
829
|
+
const ownerId = await this.ownerId(owner);
|
|
830
|
+
const source = template.source ? await this.find(owner, template.source) : void 0;
|
|
831
|
+
if (source) return toSummary((await this.graphql.query(`mutation($project: ID!, $owner: ID!, $title: String!) {
|
|
832
|
+
copyProjectV2(input: { projectId: $project, ownerId: $owner, title: $title, includeDraftIssues: false }) { projectV2 { ${PROJECT_FIELDS} } }
|
|
833
|
+
}`, {
|
|
834
|
+
project: source.id,
|
|
835
|
+
owner: ownerId,
|
|
836
|
+
title: name
|
|
837
|
+
})).copyProjectV2.projectV2);
|
|
838
|
+
const board = toSummary((await this.graphql.query(`mutation($owner: ID!, $title: String!) {
|
|
839
|
+
createProjectV2(input: { ownerId: $owner, title: $title }) { projectV2 { ${PROJECT_FIELDS} } }
|
|
840
|
+
}`, {
|
|
841
|
+
owner: ownerId,
|
|
842
|
+
title: name
|
|
843
|
+
})).createProjectV2.projectV2);
|
|
844
|
+
await this.ensure(owner, board, template);
|
|
845
|
+
return board;
|
|
846
|
+
}
|
|
847
|
+
/** Closes the board; `updateProjectV2` with `closed: true` is the only way, and reversible. */
|
|
848
|
+
async close(_owner, board) {
|
|
849
|
+
await this.graphql.query(`mutation($project: ID!) { updateProjectV2(input: { projectId: $project, closed: true }) { projectV2 { id } } }`, { project: board.id });
|
|
850
|
+
}
|
|
851
|
+
/** The live board: statuses, other fields, views and automation rules. */
|
|
852
|
+
async read(_owner, board) {
|
|
853
|
+
const raw = await this.readRaw(board.id);
|
|
854
|
+
const status = raw.fields.find((f) => f.name === STATUS_FIELD);
|
|
855
|
+
const fields = [];
|
|
856
|
+
for (const f of raw.fields) {
|
|
857
|
+
const type = fieldTypeOf(f.dataType);
|
|
858
|
+
if (!type || f.name === STATUS_FIELD) continue;
|
|
859
|
+
fields.push({
|
|
860
|
+
name: f.name,
|
|
861
|
+
type,
|
|
862
|
+
...f.options ? { options: f.options.map((o) => o.name) } : {}
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
const views = [];
|
|
866
|
+
for (const v of raw.views) {
|
|
867
|
+
const layout = v.layout === "BOARD_LAYOUT" ? "board" : v.layout === "TABLE_LAYOUT" ? "table" : void 0;
|
|
868
|
+
if (!layout) continue;
|
|
869
|
+
views.push({
|
|
870
|
+
name: v.name,
|
|
871
|
+
layout,
|
|
872
|
+
...v.filter ? { filter: v.filter } : {},
|
|
873
|
+
...v.groupBy[0] ? { groupBy: v.groupBy[0] } : {}
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
return {
|
|
877
|
+
board: raw.summary,
|
|
878
|
+
statuses: (status?.options ?? []).map((o) => o.name),
|
|
879
|
+
fields,
|
|
880
|
+
views,
|
|
881
|
+
rules: raw.rules.map(({ name, enabled }) => ({
|
|
882
|
+
name,
|
|
883
|
+
enabled
|
|
884
|
+
}))
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Brings the board in line with the template. Never deletes a field, option or view, and never sends an option
|
|
889
|
+
* list without ids. Stops (throws) when the status field cannot be read.
|
|
890
|
+
*/
|
|
891
|
+
async ensure(_owner, board, template) {
|
|
892
|
+
const raw = await this.readRaw(board.id);
|
|
893
|
+
const status = raw.fields.find((f) => f.name === STATUS_FIELD && f.options);
|
|
894
|
+
if (!status) throw new Error(`cannot read the "${STATUS_FIELD}" field of board "${board.name}"; stopped before any write so no item loses its status`);
|
|
895
|
+
const changes = [];
|
|
896
|
+
const todos = [];
|
|
897
|
+
const statusChanges = await this.ensureOptions(board, status, template.statuses.map((s) => ({
|
|
898
|
+
name: s.name,
|
|
899
|
+
color: s.color,
|
|
900
|
+
description: s.description
|
|
901
|
+
})));
|
|
902
|
+
changes.push(...statusChanges.map((c) => `status ${c}`));
|
|
903
|
+
for (const want of template.fields) {
|
|
904
|
+
const have = raw.fields.find((f) => f.name === want.name);
|
|
905
|
+
if (!have) {
|
|
906
|
+
await this.createField(board.id, want);
|
|
907
|
+
changes.push(`field ${want.name} created`);
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
if (fieldTypeOf(have.dataType) !== want.type) {
|
|
911
|
+
todos.push(`field "${want.name}" is ${have.dataType} but the template says ${want.type}; change it by hand`);
|
|
912
|
+
continue;
|
|
913
|
+
}
|
|
914
|
+
if (want.type === "single_select" && have.options && want.options) {
|
|
915
|
+
const diff = await this.ensureOptions(board, have, want.options.map((name) => ({ name })));
|
|
916
|
+
changes.push(...diff.map((c) => `field ${want.name} option ${c}`));
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
for (const want of template.views) {
|
|
920
|
+
const have = raw.views.find((v) => v.name === want.name);
|
|
921
|
+
const layout = want.layout === "board" ? "BOARD_LAYOUT" : "TABLE_LAYOUT";
|
|
922
|
+
let viewId = have?.id;
|
|
923
|
+
if (!viewId) {
|
|
924
|
+
viewId = await this.createView(board.id, want.name, layout);
|
|
925
|
+
changes.push(`view ${want.name} created`);
|
|
926
|
+
} else if (have && have.layout !== layout) {
|
|
927
|
+
await this.updateView(viewId, { layout });
|
|
928
|
+
changes.push(`view ${want.name} layout set to ${want.layout}`);
|
|
929
|
+
}
|
|
930
|
+
if (want.filter !== void 0 && want.filter !== (have?.filter ?? "")) {
|
|
931
|
+
await this.updateView(viewId, { filter: want.filter });
|
|
932
|
+
changes.push(`view ${want.name} filter set`);
|
|
933
|
+
}
|
|
934
|
+
if (want.groupBy && have?.groupBy[0] !== want.groupBy) todos.push(`group view "${want.name}" by ${want.groupBy}; the API cannot set a view's grouping`);
|
|
935
|
+
}
|
|
936
|
+
for (const rule of template.rules ?? []) {
|
|
937
|
+
const have = raw.rules.find((r) => r.name === rule);
|
|
938
|
+
if (!have) todos.push(`create the automation rule "${rule}"; the API cannot create one`);
|
|
939
|
+
else if (!have.enabled) todos.push(`turn on the automation rule "${rule}"; the API cannot switch one`);
|
|
940
|
+
}
|
|
941
|
+
return {
|
|
942
|
+
created: false,
|
|
943
|
+
changes,
|
|
944
|
+
todos
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Makes a single select field hold the wanted options in order, every existing one sent with its id. Options the
|
|
949
|
+
* template does not mention stay, after the wanted ones. Returns what changed (`Blocked added`, `order set`).
|
|
950
|
+
*/
|
|
951
|
+
async ensureOptions(board, field, wanted) {
|
|
952
|
+
/* v8 ignore next -- every caller passes a field it found with options; the fallback only satisfies the type */
|
|
953
|
+
const existing = field.options ?? [];
|
|
954
|
+
const next = [];
|
|
955
|
+
const changes = [];
|
|
956
|
+
for (const w of wanted) {
|
|
957
|
+
const have = existing.find((o) => o.name === w.name);
|
|
958
|
+
if (have) {
|
|
959
|
+
next.push({
|
|
960
|
+
id: have.id,
|
|
961
|
+
name: have.name,
|
|
962
|
+
color: (w.color ?? have.color).toUpperCase(),
|
|
963
|
+
description: w.description ?? have.description
|
|
964
|
+
});
|
|
965
|
+
if (next[next.length - 1].color !== have.color || next[next.length - 1].description !== have.description) changes.push(`${have.name} updated`);
|
|
966
|
+
} else {
|
|
967
|
+
next.push({
|
|
968
|
+
name: w.name,
|
|
969
|
+
color: (w.color ?? "GRAY").toUpperCase(),
|
|
970
|
+
description: w.description ?? ""
|
|
971
|
+
});
|
|
972
|
+
changes.push(`${w.name} added`);
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
for (const have of existing) if (!next.some((n) => n.id === have.id)) next.push({ ...have });
|
|
976
|
+
const sameOrder = next.length === existing.length && next.every((n, i) => n.id === existing[i]?.id);
|
|
977
|
+
if (changes.length === 0 && sameOrder) return [];
|
|
978
|
+
if (sameOrder === false && !changes.some((c) => c.endsWith("added"))) changes.push("order set");
|
|
979
|
+
const before = await this.fetchItems(board.id);
|
|
980
|
+
const snapshot = /* @__PURE__ */ new Map();
|
|
981
|
+
for (const item of before) {
|
|
982
|
+
const value = item.values[field.name];
|
|
983
|
+
if (value) snapshot.set(item.id, value);
|
|
984
|
+
}
|
|
985
|
+
await this.graphql.query(UPDATE_OPTIONS, {
|
|
986
|
+
field: field.id,
|
|
987
|
+
options: next.map(toOptionInput)
|
|
988
|
+
});
|
|
989
|
+
const afterField = (await this.readRaw(board.id)).fields.find((f) => f.id === field.id);
|
|
990
|
+
const afterItems = await this.fetchItems(board.id);
|
|
991
|
+
const afterValues = new Map(afterItems.map((i) => [i.id, i.values[field.name]]));
|
|
992
|
+
const lost = [...snapshot].filter(([itemId]) => !afterValues.get(itemId));
|
|
993
|
+
if (lost.length > 0) {
|
|
994
|
+
let restored = 0;
|
|
995
|
+
for (const [itemId, name] of lost) {
|
|
996
|
+
const option = afterField?.options?.find((o) => o.name === name);
|
|
997
|
+
if (!option) continue;
|
|
998
|
+
await this.graphql.query(SET_VALUE, {
|
|
999
|
+
project: board.id,
|
|
1000
|
+
item: itemId,
|
|
1001
|
+
field: field.id,
|
|
1002
|
+
option: option.id
|
|
1003
|
+
});
|
|
1004
|
+
restored++;
|
|
1005
|
+
}
|
|
1006
|
+
throw new Error(`updating "${field.name}" on board "${board.name}" blanked ${lost.length} item value(s); wrote ${restored} back by option name`);
|
|
1007
|
+
}
|
|
1008
|
+
return changes;
|
|
1009
|
+
}
|
|
1010
|
+
async createField(projectId, want) {
|
|
1011
|
+
await this.graphql.query(`mutation($project: ID!, $name: String!, $type: ProjectV2CustomFieldType!, $options: [ProjectV2SingleSelectFieldOptionInput!]) {
|
|
1012
|
+
createProjectV2Field(input: { projectId: $project, name: $name, dataType: $type, singleSelectOptions: $options }) { projectV2Field { ... on ProjectV2SingleSelectField { id } } }
|
|
1013
|
+
}`, {
|
|
1014
|
+
project: projectId,
|
|
1015
|
+
name: want.name,
|
|
1016
|
+
type: DATA_TYPES[want.type],
|
|
1017
|
+
options: want.type === "single_select" ? (want.options ?? []).map((name) => toOptionInput({ name })) : void 0
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
async createView(projectId, name, layout) {
|
|
1021
|
+
return (await this.graphql.query(`mutation($project: ID!, $name: String!, $layout: ProjectV2ViewLayout!) {
|
|
1022
|
+
createProjectV2View(input: { projectId: $project, name: $name, layout: $layout }) { projectV2View { id } }
|
|
1023
|
+
}`, {
|
|
1024
|
+
project: projectId,
|
|
1025
|
+
name,
|
|
1026
|
+
layout
|
|
1027
|
+
})).createProjectV2View.projectV2View.id;
|
|
1028
|
+
}
|
|
1029
|
+
async updateView(viewId, change) {
|
|
1030
|
+
await this.graphql.query(`mutation($view: ID!, $layout: ProjectV2ViewLayout, $filter: String) {
|
|
1031
|
+
updateProjectV2View(input: { viewId: $view, layout: $layout, filter: $filter }) { projectV2View { id } }
|
|
1032
|
+
}`, {
|
|
1033
|
+
view: viewId,
|
|
1034
|
+
layout: change.layout,
|
|
1035
|
+
filter: change.filter
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
/** The board's issues and pull requests with their status, whether they are open and their open blockers. */
|
|
1039
|
+
async items(_owner, board, template) {
|
|
1040
|
+
const categories = new Map(template.statuses.map((s) => [s.name, s.category]));
|
|
1041
|
+
return (await this.fetchItems(board.id)).map((i) => {
|
|
1042
|
+
const status = i.values[STATUS_FIELD];
|
|
1043
|
+
const category = status ? categories.get(status) : void 0;
|
|
1044
|
+
const priority = priorityOf(i.values[PRIORITY_FIELD]);
|
|
1045
|
+
return {
|
|
1046
|
+
key: this.keyOf(i.repo, i.number),
|
|
1047
|
+
title: i.title,
|
|
1048
|
+
open: i.open,
|
|
1049
|
+
...status ? { status } : {},
|
|
1050
|
+
...category ? { category } : {},
|
|
1051
|
+
blockedBy: i.blockers.map((b) => this.keyOf(b.repo, b.number)),
|
|
1052
|
+
...priority ? { priority } : {}
|
|
1053
|
+
};
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
/** Puts an item in a status; `transitioned` is false when it already is there. */
|
|
1057
|
+
async setStatus(_owner, board, key, status) {
|
|
1058
|
+
const ref = this.parseKey(key);
|
|
1059
|
+
const field = (await this.readRaw(board.id)).fields.find((f) => f.name === STATUS_FIELD && f.options);
|
|
1060
|
+
const option = field?.options?.find((o) => o.name === status);
|
|
1061
|
+
if (!field || !option) throw new Error(`board "${board.name}" has no status "${status}"`);
|
|
1062
|
+
const item = (await this.fetchItems(board.id)).find((i) => i.repo === ref.repo && i.number === ref.number);
|
|
1063
|
+
if (!item) throw new Error(`${key} is not on board "${board.name}"`);
|
|
1064
|
+
if (item.values[STATUS_FIELD] === status) return {
|
|
1065
|
+
transitioned: false,
|
|
1066
|
+
status
|
|
1067
|
+
};
|
|
1068
|
+
await this.graphql.query(SET_VALUE, {
|
|
1069
|
+
project: board.id,
|
|
1070
|
+
item: item.id,
|
|
1071
|
+
field: field.id,
|
|
1072
|
+
option: option.id
|
|
1073
|
+
});
|
|
1074
|
+
return {
|
|
1075
|
+
transitioned: true,
|
|
1076
|
+
status,
|
|
1077
|
+
via: "project field set"
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Puts the open items of `from` on `to` with their status and priority, only where the target has no value;
|
|
1082
|
+
* closed and merged ones stay, and are set to the template's done status when theirs is not a done one.
|
|
1083
|
+
*/
|
|
1084
|
+
async move(_owner, from, to, template) {
|
|
1085
|
+
const report = {
|
|
1086
|
+
moved: [],
|
|
1087
|
+
kept: [],
|
|
1088
|
+
left: []
|
|
1089
|
+
};
|
|
1090
|
+
const [source, target, fromRaw, toRaw] = await Promise.all([
|
|
1091
|
+
this.fetchItems(from.id),
|
|
1092
|
+
this.fetchItems(to.id),
|
|
1093
|
+
this.readRaw(from.id),
|
|
1094
|
+
this.readRaw(to.id)
|
|
1095
|
+
]);
|
|
1096
|
+
const done = template.statuses.find((s) => s.category === "done")?.name;
|
|
1097
|
+
const doneNames = new Set(template.statuses.filter((s) => s.category === "done").map((s) => s.name));
|
|
1098
|
+
const carried = [STATUS_FIELD, PRIORITY_FIELD];
|
|
1099
|
+
for (const item of source) {
|
|
1100
|
+
const key = this.keyOf(item.repo, item.number);
|
|
1101
|
+
if (!item.open) {
|
|
1102
|
+
const current = item.values[STATUS_FIELD];
|
|
1103
|
+
if (done && (!current || !doneNames.has(current))) await this.setOption(from.id, fromRaw, item.id, STATUS_FIELD, done);
|
|
1104
|
+
report.left.push(key);
|
|
1105
|
+
continue;
|
|
1106
|
+
}
|
|
1107
|
+
let targetItem = target.find((t) => t.contentId === item.contentId);
|
|
1108
|
+
if (targetItem) report.kept.push(key);
|
|
1109
|
+
else {
|
|
1110
|
+
const data = await this.graphql.query(`mutation($project: ID!, $content: ID!) { addProjectV2ItemById(input: { projectId: $project, contentId: $content }) { item { id } } }`, {
|
|
1111
|
+
project: to.id,
|
|
1112
|
+
content: item.contentId
|
|
1113
|
+
});
|
|
1114
|
+
targetItem = {
|
|
1115
|
+
...item,
|
|
1116
|
+
id: data.addProjectV2ItemById.item.id,
|
|
1117
|
+
values: {}
|
|
1118
|
+
};
|
|
1119
|
+
report.moved.push(key);
|
|
1120
|
+
}
|
|
1121
|
+
for (const name of carried) {
|
|
1122
|
+
const value = item.values[name];
|
|
1123
|
+
if (value && !targetItem.values[name]) await this.setOption(to.id, toRaw, targetItem.id, name, value);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
return report;
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* Puts issues on the board (`addProjectV2ItemById`, the content id the issue's node id) and sets Status and Priority
|
|
1130
|
+
* through the single select update, only where the item has no value yet. A status or priority with no option on
|
|
1131
|
+
* the board is reported in `dropped`; no option is ever created, so no value is cleared.
|
|
1132
|
+
*/
|
|
1133
|
+
async addItems(_owner, board, items, template) {
|
|
1134
|
+
const raw = await this.readRaw(board.id);
|
|
1135
|
+
const onBoard = await this.fetchItems(board.id);
|
|
1136
|
+
const statusField = raw.fields.find((f) => f.name === STATUS_FIELD && f.options);
|
|
1137
|
+
const priorityField = raw.fields.find((f) => f.name === PRIORITY_FIELD && f.options);
|
|
1138
|
+
const results = [];
|
|
1139
|
+
for (const input of items) {
|
|
1140
|
+
const ref = this.parseKey(input.key);
|
|
1141
|
+
let current = onBoard.find((i) => i.repo === ref.repo && i.number === ref.number);
|
|
1142
|
+
const added = !current;
|
|
1143
|
+
if (!current) current = {
|
|
1144
|
+
id: (await this.graphql.query(`mutation($project: ID!, $content: ID!) { addProjectV2ItemById(input: { projectId: $project, contentId: $content }) { item { id } } }`, {
|
|
1145
|
+
project: board.id,
|
|
1146
|
+
content: await this.nodeId(ref)
|
|
1147
|
+
})).addProjectV2ItemById.item.id,
|
|
1148
|
+
contentId: "",
|
|
1149
|
+
repo: ref.repo,
|
|
1150
|
+
number: ref.number,
|
|
1151
|
+
title: "",
|
|
1152
|
+
open: true,
|
|
1153
|
+
values: {},
|
|
1154
|
+
blockers: []
|
|
1155
|
+
};
|
|
1156
|
+
const dropped = [];
|
|
1157
|
+
if (input.status !== void 0 || input.category !== void 0) {
|
|
1158
|
+
const name = this.statusFor(input, template, statusField?.options);
|
|
1159
|
+
if (!name) dropped.push(`status ${input.status ?? input.category} (no matching option on the board)`);
|
|
1160
|
+
else if (!current.values[STATUS_FIELD]) await this.setOption(board.id, raw, current.id, STATUS_FIELD, name);
|
|
1161
|
+
}
|
|
1162
|
+
if (input.priority !== void 0 && input.priority !== "none") {
|
|
1163
|
+
const option = priorityField?.options?.find((o) => priorityOf(o.name) === input.priority);
|
|
1164
|
+
if (!option) dropped.push(`priority ${input.priority} (no matching option on the board)`);
|
|
1165
|
+
else if (!current.values[PRIORITY_FIELD]) await this.setOption(board.id, raw, current.id, PRIORITY_FIELD, option.name);
|
|
1166
|
+
}
|
|
1167
|
+
results.push({
|
|
1168
|
+
key: input.key,
|
|
1169
|
+
added,
|
|
1170
|
+
dropped
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
return results;
|
|
1174
|
+
}
|
|
1175
|
+
/** The board's own status for an input: the option named like its status, else the template's status of its category. */
|
|
1176
|
+
statusFor(input, template, options) {
|
|
1177
|
+
const has = (name) => options?.find((o) => o.name.toLowerCase() === name.toLowerCase())?.name;
|
|
1178
|
+
const named = input.status === void 0 ? void 0 : has(input.status);
|
|
1179
|
+
if (named) return named;
|
|
1180
|
+
const byCategory = template.statuses.find((s) => s.category === input.category);
|
|
1181
|
+
return byCategory ? has(byCategory.name) : void 0;
|
|
1182
|
+
}
|
|
1183
|
+
/** The node id of an issue, which `addProjectV2ItemById` takes as the content id. */
|
|
1184
|
+
async nodeId(ref) {
|
|
1185
|
+
const [owner, name] = ref.repo.split("/");
|
|
1186
|
+
const id = (await this.graphql.query(`query($owner: String!, $name: String!, $number: Int!) { repository(owner: $owner, name: $name) { issue(number: $number) { id } } }`, {
|
|
1187
|
+
owner,
|
|
1188
|
+
name,
|
|
1189
|
+
number: ref.number
|
|
1190
|
+
})).repository?.issue?.id;
|
|
1191
|
+
if (!id) throw new Error(`issue ${ref.repo}#${ref.number} not found`);
|
|
1192
|
+
return id;
|
|
1193
|
+
}
|
|
1194
|
+
/** A `holocron doctor` smoke check: how many boards the token sees in the configured repository's organization. */
|
|
1195
|
+
async whoami() {
|
|
1196
|
+
try {
|
|
1197
|
+
return {
|
|
1198
|
+
ok: true,
|
|
1199
|
+
boards: (await this.list(this.repo.split("/")[0] ?? "")).length
|
|
1200
|
+
};
|
|
1201
|
+
} catch {
|
|
1202
|
+
return {
|
|
1203
|
+
ok: false,
|
|
1204
|
+
boards: 0
|
|
1205
|
+
};
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
/** Sets a single select value by option name; a field or option the board lacks is skipped. */
|
|
1209
|
+
async setOption(projectId, raw, itemId, fieldName, optionName) {
|
|
1210
|
+
const field = raw.fields.find((f) => f.name === fieldName && f.options);
|
|
1211
|
+
const option = field?.options?.find((o) => o.name === optionName);
|
|
1212
|
+
if (!field || !option) return;
|
|
1213
|
+
await this.graphql.query(SET_VALUE, {
|
|
1214
|
+
project: projectId,
|
|
1215
|
+
item: itemId,
|
|
1216
|
+
field: field.id,
|
|
1217
|
+
option: option.id
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
async ownerId(owner) {
|
|
1221
|
+
return (await this.graphql.query(OWNER_QUERY, { owner })).organization.id;
|
|
1222
|
+
}
|
|
1223
|
+
async readRaw(id) {
|
|
1224
|
+
const n = (await this.graphql.query(BOARD_QUERY, { id })).node;
|
|
1225
|
+
if (!n) throw new Error(`board ${id} not found`);
|
|
1226
|
+
return {
|
|
1227
|
+
summary: toSummary(n),
|
|
1228
|
+
fields: n.fields.nodes.filter((f) => f.id).map((f) => ({
|
|
1229
|
+
id: f.id,
|
|
1230
|
+
name: f.name,
|
|
1231
|
+
dataType: f.dataType,
|
|
1232
|
+
...f.options ? { options: f.options } : {}
|
|
1233
|
+
})),
|
|
1234
|
+
views: n.views.nodes.map((v) => ({
|
|
1235
|
+
id: v.id,
|
|
1236
|
+
name: v.name,
|
|
1237
|
+
layout: v.layout,
|
|
1238
|
+
filter: v.filter,
|
|
1239
|
+
groupBy: (v.groupByFields?.nodes ?? []).map((g) => g.name)
|
|
1240
|
+
})),
|
|
1241
|
+
rules: n.workflows.nodes.map((w) => ({
|
|
1242
|
+
id: w.id,
|
|
1243
|
+
name: w.name,
|
|
1244
|
+
enabled: w.enabled
|
|
1245
|
+
}))
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
async fetchItems(id) {
|
|
1249
|
+
const items = [];
|
|
1250
|
+
let after = null;
|
|
1251
|
+
for (;;) {
|
|
1252
|
+
const page = (await this.graphql.query(ITEMS_QUERY, {
|
|
1253
|
+
id,
|
|
1254
|
+
after
|
|
1255
|
+
})).node.items;
|
|
1256
|
+
for (const n of page.nodes) {
|
|
1257
|
+
const c = n.content;
|
|
1258
|
+
if (!c || !c.repository) continue;
|
|
1259
|
+
const values = {};
|
|
1260
|
+
for (const v of n.fieldValues.nodes) if (v.name && v.field?.name) values[v.field.name] = v.name;
|
|
1261
|
+
items.push({
|
|
1262
|
+
id: n.id,
|
|
1263
|
+
contentId: c.id,
|
|
1264
|
+
repo: c.repository.nameWithOwner,
|
|
1265
|
+
number: c.number,
|
|
1266
|
+
title: c.title,
|
|
1267
|
+
open: c.state === "OPEN",
|
|
1268
|
+
values,
|
|
1269
|
+
blockers: (c.blockedBy?.nodes ?? []).filter((b) => b.state === "OPEN").map((b) => ({
|
|
1270
|
+
repo: b.repository.nameWithOwner,
|
|
1271
|
+
number: b.number
|
|
1272
|
+
}))
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
if (!page.pageInfo.hasNextPage) return items;
|
|
1276
|
+
after = page.pageInfo.endCursor;
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
keyOf(repo, number) {
|
|
1280
|
+
return repo === this.repo ? `#${number}` : `${repo}#${number}`;
|
|
1281
|
+
}
|
|
1282
|
+
parseKey(key) {
|
|
1283
|
+
const m = /^(?:([^#\s]+))?#?(\d+)$/.exec(key.trim());
|
|
1284
|
+
const hasRepo = key.includes("#") && m?.[1];
|
|
1285
|
+
if (!m) throw new Error(`not an issue key: ${key}`);
|
|
1286
|
+
return {
|
|
1287
|
+
repo: hasRepo ? m[1] : this.repo,
|
|
1288
|
+
number: Number(m[2])
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
};
|
|
1292
|
+
// src/sodium.ts
|
|
342
1293
|
/**
|
|
343
1294
|
* libsodium sealed-box encryption for GitHub Actions secrets.
|
|
344
1295
|
*
|
|
@@ -369,32 +1320,46 @@ async function encryptSecret(publicKeyBase64, value) {
|
|
|
369
1320
|
const ciphertext = sodium.crypto_box_seal(plaintext, publicKey);
|
|
370
1321
|
return sodium.to_base64(ciphertext, sodium.base64_variants.ORIGINAL);
|
|
371
1322
|
}
|
|
372
|
-
|
|
373
|
-
|
|
1323
|
+
// src/capabilities/secrets.ts
|
|
1324
|
+
/** The GitHub implementation of the `secrets` capability, covering repository, environment and organization secrets. */
|
|
374
1325
|
var GitHubSecrets = class {
|
|
375
1326
|
client;
|
|
376
1327
|
opts;
|
|
1328
|
+
orgClient;
|
|
1329
|
+
/** Capability key, always `"secrets"`. */
|
|
377
1330
|
key = "secrets";
|
|
1331
|
+
/** Provider name, always `"github"`. */
|
|
378
1332
|
providerName = "github";
|
|
379
|
-
|
|
1333
|
+
/**
|
|
1334
|
+
* `client` handles repo and environment scopes; `orgClient`, when given, handles
|
|
1335
|
+
* the organization scope. They differ when a dedicated org-only token exists:
|
|
1336
|
+
* it can write org secrets but not repo ones, and `github.admin` is the reverse.
|
|
1337
|
+
*/
|
|
1338
|
+
constructor(client, opts, orgClient) {
|
|
380
1339
|
this.client = client;
|
|
381
1340
|
this.opts = opts;
|
|
1341
|
+
this.orgClient = orgClient;
|
|
1342
|
+
}
|
|
1343
|
+
clientFor(scope) {
|
|
1344
|
+
return scope.kind === "organization" ? this.orgClient ?? this.client : this.client;
|
|
382
1345
|
}
|
|
383
1346
|
async listSecrets(scope) {
|
|
384
|
-
return this.
|
|
1347
|
+
return this.clientFor(scope).secrets.listSecrets(this.opts.repo, toGHScope(scope));
|
|
385
1348
|
}
|
|
386
1349
|
async setSecret(scope, name, value) {
|
|
387
1350
|
const ghScope = toGHScope(scope);
|
|
388
|
-
const
|
|
1351
|
+
const client = this.clientFor(scope);
|
|
1352
|
+
const pk = await client.secrets.getPublicKey(this.opts.repo, ghScope);
|
|
389
1353
|
const body = {
|
|
390
1354
|
encrypted_value: await encryptSecret(pk.key, value),
|
|
391
1355
|
key_id: pk.key_id
|
|
392
1356
|
};
|
|
393
1357
|
if (scope.kind === "organization") body.visibility = "all";
|
|
394
|
-
await
|
|
1358
|
+
await client.secrets.putSecret(this.opts.repo, ghScope, name, body);
|
|
395
1359
|
}
|
|
1360
|
+
/** Deletes the named secret in the given scope. */
|
|
396
1361
|
async deleteSecret(scope, name) {
|
|
397
|
-
await this.
|
|
1362
|
+
await this.clientFor(scope).secrets.deleteSecret(this.opts.repo, toGHScope(scope), name);
|
|
398
1363
|
}
|
|
399
1364
|
};
|
|
400
1365
|
function toGHScope(scope) {
|
|
@@ -404,8 +1369,46 @@ function toGHScope(scope) {
|
|
|
404
1369
|
};
|
|
405
1370
|
return scope;
|
|
406
1371
|
}
|
|
407
|
-
|
|
408
|
-
|
|
1372
|
+
// src/capabilities/files.ts
|
|
1373
|
+
/** Reads one file; `null` when it does not exist. `version` is the blob sha `writeFile` needs to replace exactly this one. */
|
|
1374
|
+
/** A fine-grained token only reaches the repositories and permissions it was given; say which one is missing. */
|
|
1375
|
+
function noAccess(repo, action, cause) {
|
|
1376
|
+
return new Error(`the token cannot ${action} files in ${repo} (403): give the user-sync token (HOLOCRON_USER_SYNC_TOKEN, or holocron auth set github.user-sync) access to that repository with Contents: ${action === "read" ? "read" : "read and write"}`, { cause });
|
|
1377
|
+
}
|
|
1378
|
+
async function readRepoFile(client, repo, path) {
|
|
1379
|
+
try {
|
|
1380
|
+
const file = await client.git.getContents(repo, path);
|
|
1381
|
+
if (file.encoding !== "base64") throw new Error(`${repo}/${path}: unexpected encoding \`${file.encoding}\``);
|
|
1382
|
+
return {
|
|
1383
|
+
content: Buffer.from(file.content, "base64").toString("utf-8"),
|
|
1384
|
+
version: file.sha
|
|
1385
|
+
};
|
|
1386
|
+
} catch (err) {
|
|
1387
|
+
if (err instanceof ProviderApiError && err.status === 403) throw noAccess(repo, "read", err);
|
|
1388
|
+
if (!(err instanceof ProviderApiError && err.status === 404)) throw err;
|
|
1389
|
+
}
|
|
1390
|
+
try {
|
|
1391
|
+
await client.repos.getRepo(repo);
|
|
1392
|
+
} catch (err) {
|
|
1393
|
+
if (err instanceof ProviderApiError && err.status === 404) throw new Error(`${repo} was not found: it does not exist, or the token cannot see it`, { cause: err });
|
|
1394
|
+
throw err;
|
|
1395
|
+
}
|
|
1396
|
+
return null;
|
|
1397
|
+
}
|
|
1398
|
+
/** Creates or replaces one file in a commit; GitHub refuses (409) a `version` that has since changed. */
|
|
1399
|
+
async function writeRepoFile(client, repo, path, content, opts) {
|
|
1400
|
+
try {
|
|
1401
|
+
await client.git.putContents(repo, path, {
|
|
1402
|
+
message: opts.message,
|
|
1403
|
+
content,
|
|
1404
|
+
...opts.version ? { sha: opts.version } : {}
|
|
1405
|
+
});
|
|
1406
|
+
} catch (err) {
|
|
1407
|
+
if (err instanceof ProviderApiError && err.status === 403) throw noAccess(repo, "write", err);
|
|
1408
|
+
throw err;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
// src/capabilities/labels.ts
|
|
409
1412
|
/**
|
|
410
1413
|
* Idempotently synchronise a repo's labels to the canonical set.
|
|
411
1414
|
*
|
|
@@ -443,14 +1446,202 @@ async function syncLabels(client, repo, canonical, stale) {
|
|
|
443
1446
|
}
|
|
444
1447
|
return `${created} created, ${updated} updated, ${deleted} deleted`;
|
|
445
1448
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
1449
|
+
// src/capabilities/property-fix-hints.ts
|
|
1450
|
+
/** GitHub's wording when a custom property value is not one the organization's definition allows. */
|
|
1451
|
+
const NOT_ALLOWED = /Value '([^']+)' is not allowed for property '([^']+)'/g;
|
|
1452
|
+
/**
|
|
1453
|
+
* What to do about each value GitHub says an organization custom property does not allow, one sentence per property,
|
|
1454
|
+
* read from GitHub's own message so it works even when the organization's definitions cannot be read. The values
|
|
1455
|
+
* belong to the organization's definition, not to the repository, so the fix is to add them there: a repository cannot
|
|
1456
|
+
* make its own value allowed. Empty when GitHub's message names no such value.
|
|
1457
|
+
*/
|
|
1458
|
+
function propertyFixHints(githubMessage) {
|
|
1459
|
+
const byProperty = /* @__PURE__ */ new Map();
|
|
1460
|
+
for (const [, value, property] of githubMessage.matchAll(NOT_ALLOWED)) {
|
|
1461
|
+
const values = byProperty.get(property) ?? [];
|
|
1462
|
+
if (!values.includes(value)) values.push(value);
|
|
1463
|
+
byProperty.set(property, values);
|
|
1464
|
+
}
|
|
1465
|
+
return [...byProperty].map(([property, values]) => `add ${values.map((v) => `"${v}"`).join(", ")} to the allowed values of the organization custom property ${property} (the organization's Settings, Custom properties), then run repo setup again`);
|
|
1466
|
+
}
|
|
1467
|
+
// src/capabilities/rejected-properties.ts
|
|
1468
|
+
/** The values `repo setup` sends for `true_false` properties; anything else is rejected. */
|
|
1469
|
+
const BOOLEANS = /* @__PURE__ */ new Set(["true", "false"]);
|
|
1470
|
+
/**
|
|
1471
|
+
* What is wrong with `values` when compared with the organization's property definitions, one sentence per
|
|
1472
|
+
* problem, in the order the properties are given: a property the organization does not define, a value a
|
|
1473
|
+
* `single_select` or `multi_select` property does not allow, or a `true_false` property that is not `true` or
|
|
1474
|
+
* `false`. A `string` or `url` property has nothing to check here. Empty when every value fits its definition.
|
|
1475
|
+
*/
|
|
1476
|
+
function rejectedProperties(values, schema) {
|
|
1477
|
+
const byName = new Map(schema.map((property) => [property.property_name, property]));
|
|
1478
|
+
const problems = [];
|
|
1479
|
+
for (const [name, value] of Object.entries(values)) {
|
|
1480
|
+
const definition = byName.get(name);
|
|
1481
|
+
if (!definition) {
|
|
1482
|
+
problems.push(`${name} is not a custom property of the organization`);
|
|
1483
|
+
continue;
|
|
1484
|
+
}
|
|
1485
|
+
const sent = Array.isArray(value) ? value : [value];
|
|
1486
|
+
if (definition.value_type === "true_false") {
|
|
1487
|
+
for (const item of sent.filter((item) => !BOOLEANS.has(item))) problems.push(`${name} is "${item}", but it takes only true or false`);
|
|
1488
|
+
continue;
|
|
1489
|
+
}
|
|
1490
|
+
const allowed = definition.allowed_values ?? [];
|
|
1491
|
+
if (definition.value_type !== "single_select" && definition.value_type !== "multi_select") continue;
|
|
1492
|
+
for (const item of sent.filter((item) => !allowed.includes(item))) problems.push(`${name} has "${item}", which is not one of its allowed values (${allowed.join(", ")})`);
|
|
1493
|
+
}
|
|
1494
|
+
return problems;
|
|
1495
|
+
}
|
|
1496
|
+
// src/capabilities/properties.ts
|
|
1497
|
+
/** GitHub's own message from a 422 body (`{"message": ..., "errors": [...]}`), or the start of the body when it is not JSON. */
|
|
1498
|
+
function githubMessage(details) {
|
|
1499
|
+
const raw = String(details ?? "").trim();
|
|
1500
|
+
try {
|
|
1501
|
+
const body = JSON.parse(raw);
|
|
1502
|
+
const errors = Array.isArray(body.errors) ? body.errors.map((e) => JSON.stringify(e)).join(", ") : "";
|
|
1503
|
+
const message = typeof body.message === "string" ? body.message : raw;
|
|
1504
|
+
return errors ? `${message}: ${errors}` : message;
|
|
1505
|
+
} catch {
|
|
1506
|
+
return raw.slice(0, 300);
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
/** The organization's property definitions, or `undefined` when they cannot be read (permission, an older client). */
|
|
1510
|
+
async function orgSchema(client, repo) {
|
|
1511
|
+
try {
|
|
1512
|
+
return await client.properties.orgSchema(repo.split("/")[0]);
|
|
1513
|
+
} catch {
|
|
1514
|
+
return;
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
/**
|
|
1518
|
+
* The values `values` holds that the organization's property definitions do not allow, one sentence each, or
|
|
1519
|
+
* `undefined` when the definitions cannot be read (the token lacks the organization's custom properties permission, or
|
|
1520
|
+
* the organization defines none). `client` should be the organization-scoped one when there is one, since reading the
|
|
1521
|
+
* definitions is an organization permission a repository token often lacks. Read-only.
|
|
1522
|
+
*/
|
|
1523
|
+
async function checkPropertyValues(client, repo, values) {
|
|
1524
|
+
const schema = await orgSchema(client, repo);
|
|
1525
|
+
return schema ? rejectedProperties(values, schema) : void 0;
|
|
1526
|
+
}
|
|
1527
|
+
/**
|
|
1528
|
+
* Sets the repo's custom properties. When GitHub answers 422 the error says which value it refused and what to do
|
|
1529
|
+
* about it: the values are compared with the organization's property definitions (read-only, with `schemaClient`, the
|
|
1530
|
+
* organization-scoped client when there is one), GitHub's own message is added, and each value GitHub says a property
|
|
1531
|
+
* does not allow gets the fix, which does not need the definitions to be readable. One refused value fails the whole
|
|
1532
|
+
* request, so none of the properties is set.
|
|
1533
|
+
*/
|
|
1534
|
+
async function syncProperties(client, repo, values, schemaClient = client) {
|
|
1535
|
+
try {
|
|
1536
|
+
await client.properties.setProperties(repo, values);
|
|
1537
|
+
} catch (err) {
|
|
1538
|
+
if (!(err instanceof ProviderApiError$1) || err.status !== 422) throw err;
|
|
1539
|
+
const problems = await checkPropertyValues(schemaClient, repo, values) ?? [];
|
|
1540
|
+
const said = githubMessage(err.details);
|
|
1541
|
+
const fixes = propertyFixHints(said);
|
|
1542
|
+
throw new Error(`GitHub refused the custom properties (422), so none was set: ${problems.length > 0 ? problems.join("; ") : "no value differs from the organization's definitions, or they could not be read"}. GitHub said: ${said}${fixes.length > 0 ? `. To fix it: ${fixes.join("; ")}` : ""}`, { cause: err });
|
|
1543
|
+
}
|
|
450
1544
|
return `${Object.keys(values).length} properties set`;
|
|
451
1545
|
}
|
|
452
|
-
|
|
453
|
-
|
|
1546
|
+
/** The values the organization's property `name` allows; `undefined` when it cannot be read, is not defined or takes any value. */
|
|
1547
|
+
async function getOrgPropertyValues(client, repo, name) {
|
|
1548
|
+
return ((await orgSchema(client, repo))?.find((p) => p.property_name === name))?.allowed_values ?? void 0;
|
|
1549
|
+
}
|
|
1550
|
+
/**
|
|
1551
|
+
* Adds the missing `values` to the organization's property `name` and returns them. GitHub replaces the whole
|
|
1552
|
+
* definition on a write, so the current one is read and sent back with the allowed values extended, in their order,
|
|
1553
|
+
* and nothing removed. A write is made only when something is missing.
|
|
1554
|
+
*/
|
|
1555
|
+
async function addOrgPropertyValues(client, repo, name, values) {
|
|
1556
|
+
const org = repo.split("/")[0];
|
|
1557
|
+
const current = (await client.properties.orgSchema(org)).find((p) => p.property_name === name);
|
|
1558
|
+
if (!current) throw new Error(`the organization ${org} has no custom property "${name}"; create it first`);
|
|
1559
|
+
if (!current.allowed_values) throw new Error(`the custom property "${name}" takes any value; it has nothing to extend`);
|
|
1560
|
+
const have = new Set(current.allowed_values);
|
|
1561
|
+
const added = [...new Set(values)].filter((v) => !have.has(v));
|
|
1562
|
+
if (added.length === 0) return [];
|
|
1563
|
+
await client.properties.setOrgProperty(org, {
|
|
1564
|
+
...current,
|
|
1565
|
+
allowed_values: [...current.allowed_values, ...added]
|
|
1566
|
+
});
|
|
1567
|
+
return added;
|
|
1568
|
+
}
|
|
1569
|
+
// src/capabilities/read-repo.ts
|
|
1570
|
+
/** The settings `repo setup` writes, which `GET /repos/{repo}` reports under the same names. */
|
|
1571
|
+
const SETTING_KEYS = [
|
|
1572
|
+
"allow_squash_merge",
|
|
1573
|
+
"allow_merge_commit",
|
|
1574
|
+
"allow_rebase_merge",
|
|
1575
|
+
"allow_auto_merge",
|
|
1576
|
+
"allow_update_branch",
|
|
1577
|
+
"delete_branch_on_merge",
|
|
1578
|
+
"has_issues",
|
|
1579
|
+
"has_discussions",
|
|
1580
|
+
"has_projects",
|
|
1581
|
+
"has_wiki"
|
|
1582
|
+
];
|
|
1583
|
+
/** The repository's description, homepage, default branch, topics and settings, from one read. */
|
|
1584
|
+
async function readRepoInfo(client, repo) {
|
|
1585
|
+
const data = await client.repos.getRepo(repo);
|
|
1586
|
+
const settings = { default_branch: data.default_branch };
|
|
1587
|
+
for (const key of SETTING_KEYS) {
|
|
1588
|
+
const value = data[key];
|
|
1589
|
+
if (value !== void 0) settings[key] = value;
|
|
1590
|
+
}
|
|
1591
|
+
return {
|
|
1592
|
+
description: data.description ?? null,
|
|
1593
|
+
homepage: data.homepage ?? null,
|
|
1594
|
+
defaultBranch: data.default_branch,
|
|
1595
|
+
topics: data.topics ?? [],
|
|
1596
|
+
settings
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
/** A ruleset reduced to what `repo setup` writes: its enforcement, rule types and required status checks. */
|
|
1600
|
+
function toRulesetDetail(data) {
|
|
1601
|
+
const rules = data.rules ?? [];
|
|
1602
|
+
const checks = rules.find((r) => r.type === "required_status_checks")?.parameters?.required_status_checks;
|
|
1603
|
+
return {
|
|
1604
|
+
name: data.name,
|
|
1605
|
+
enforcement: data.enforcement,
|
|
1606
|
+
ruleTypes: rules.map((r) => r.type),
|
|
1607
|
+
requiredChecks: Array.isArray(checks) ? checks.map((c) => String(c.context)) : []
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
/** The value, or `undefined` when GitHub refuses the read (permission, plan, feature absent). Other errors still throw. */
|
|
1611
|
+
async function readable(read) {
|
|
1612
|
+
try {
|
|
1613
|
+
return await read();
|
|
1614
|
+
} catch (err) {
|
|
1615
|
+
if (err instanceof ProviderApiError$1) return void 0;
|
|
1616
|
+
throw err;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
/** Which security features are on. One GitHub refuses to report is left out, not reported as off. */
|
|
1620
|
+
async function readSecurity(client, repo) {
|
|
1621
|
+
const [data, alerts, fixes, reporting, codeScanning] = await Promise.all([
|
|
1622
|
+
readable(() => client.repos.getRepo(repo)),
|
|
1623
|
+
readable(() => client.security.vulnerabilityAlertsEnabled(repo)),
|
|
1624
|
+
readable(() => client.security.automatedSecurityFixesEnabled(repo)),
|
|
1625
|
+
readable(() => client.security.privateVulnerabilityReportingEnabled(repo)),
|
|
1626
|
+
readable(() => client.security.codeScanningDefaultSetupState(repo))
|
|
1627
|
+
]);
|
|
1628
|
+
const analysis = data?.security_and_analysis;
|
|
1629
|
+
const on = (feature) => {
|
|
1630
|
+
const status = analysis?.[feature]?.status;
|
|
1631
|
+
return status === void 0 ? void 0 : status === "enabled";
|
|
1632
|
+
};
|
|
1633
|
+
const found = {
|
|
1634
|
+
vulnerabilityAlerts: alerts,
|
|
1635
|
+
automatedSecurityFixes: fixes,
|
|
1636
|
+
secretScanning: on("secret_scanning"),
|
|
1637
|
+
secretScanningPushProtection: on("secret_scanning_push_protection"),
|
|
1638
|
+
privateVulnerabilityReporting: reporting,
|
|
1639
|
+
codeScanningDefaultSetup: codeScanning === void 0 ? void 0 : codeScanning === "configured"
|
|
1640
|
+
};
|
|
1641
|
+
return Object.fromEntries(Object.entries(found).filter(([, v]) => v !== void 0));
|
|
1642
|
+
}
|
|
1643
|
+
// src/capabilities/teams.ts
|
|
1644
|
+
/** Turns a team entry into slug and permission form; a bare slug gets `push`. */
|
|
454
1645
|
function normalizeTeamEntry(entry) {
|
|
455
1646
|
if (typeof entry === "string") return {
|
|
456
1647
|
slug: entry,
|
|
@@ -458,6 +1649,7 @@ function normalizeTeamEntry(entry) {
|
|
|
458
1649
|
};
|
|
459
1650
|
return entry;
|
|
460
1651
|
}
|
|
1652
|
+
/** Grants each team access to the repo and reports the outcome; throws when every team fails. */
|
|
461
1653
|
async function syncTeams(client, repo, teams) {
|
|
462
1654
|
const [org = "", name = ""] = repo.split("/", 2);
|
|
463
1655
|
const normalized = teams.map(normalizeTeamEntry);
|
|
@@ -470,17 +1662,132 @@ async function syncTeams(client, repo, teams) {
|
|
|
470
1662
|
}
|
|
471
1663
|
return `${succeeded} team${succeeded === 1 ? "" : "s"} synced`;
|
|
472
1664
|
}
|
|
473
|
-
|
|
474
|
-
//#region src/capabilities/topics.ts
|
|
1665
|
+
// src/capabilities/topics.ts
|
|
475
1666
|
async function syncTopics(client, repo, topics) {
|
|
476
1667
|
await client.topics.setTopics(repo, topics);
|
|
477
1668
|
return `${topics.length} topics set`;
|
|
478
1669
|
}
|
|
479
|
-
|
|
480
|
-
|
|
1670
|
+
// src/capabilities/variables.ts
|
|
1671
|
+
/** GitHub's rule for a variable name: letters, digits and underscores, not starting with a digit or `GITHUB_`. */
|
|
1672
|
+
const NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
1673
|
+
/** Longest name GitHub accepts. */
|
|
1674
|
+
const MAX_NAME = 256;
|
|
1675
|
+
function assertNames(names) {
|
|
1676
|
+
for (const name of names) if (!NAME.test(name) || name.length > MAX_NAME || name.toUpperCase().startsWith("GITHUB_")) throw new Error(`invalid variable name ${JSON.stringify(name)}: use letters, digits and underscores (at most ${MAX_NAME}), not starting with a digit or GITHUB_`);
|
|
1677
|
+
}
|
|
1678
|
+
/** GitHub treats variable names as case-insensitive, so every comparison goes through this. */
|
|
1679
|
+
const key = (name) => name.toUpperCase();
|
|
1680
|
+
/**
|
|
1681
|
+
* Bring one scope's variables in line with the declaration: create what is missing, update what differs, leave what
|
|
1682
|
+
* already matches. Variables that exist but are not declared are left alone, or deleted with `prune`, except an
|
|
1683
|
+
* organization variable limited to selected repositories, which this client cannot manage and so is never deleted.
|
|
1684
|
+
* Returns a one-line summary, naming the ones left so drift is visible. In a dry run it only describes the changes.
|
|
1685
|
+
*/
|
|
1686
|
+
async function reconcile(client, repo, scope, wanted, opts) {
|
|
1687
|
+
assertNames(wanted.map((w) => w.name));
|
|
1688
|
+
const existing = new Map((await client.variables.listVariables(repo, scope)).map((v) => [key(v.name), v]));
|
|
1689
|
+
const counts = {
|
|
1690
|
+
created: 0,
|
|
1691
|
+
updated: 0,
|
|
1692
|
+
unchanged: 0,
|
|
1693
|
+
deleted: 0
|
|
1694
|
+
};
|
|
1695
|
+
for (const want of wanted) {
|
|
1696
|
+
const have = existing.get(key(want.name));
|
|
1697
|
+
const body = {
|
|
1698
|
+
name: want.name,
|
|
1699
|
+
value: want.value
|
|
1700
|
+
};
|
|
1701
|
+
if (want.visibility) body["visibility"] = want.visibility;
|
|
1702
|
+
if (!have) {
|
|
1703
|
+
if (opts.dryRun) {
|
|
1704
|
+
counts.created++;
|
|
1705
|
+
continue;
|
|
1706
|
+
}
|
|
1707
|
+
try {
|
|
1708
|
+
await client.variables.createVariable(repo, scope, body);
|
|
1709
|
+
counts.created++;
|
|
1710
|
+
continue;
|
|
1711
|
+
} catch (err) {
|
|
1712
|
+
if (!(err instanceof ProviderApiError && (err.status === 409 || err.status === 422))) throw err;
|
|
1713
|
+
}
|
|
1714
|
+
} else if (have.value === want.value && (!want.visibility || have.visibility === want.visibility)) {
|
|
1715
|
+
counts.unchanged++;
|
|
1716
|
+
continue;
|
|
1717
|
+
}
|
|
1718
|
+
if (!opts.dryRun) await client.variables.updateVariable(repo, scope, have?.name ?? want.name, body);
|
|
1719
|
+
counts.updated++;
|
|
1720
|
+
}
|
|
1721
|
+
const declared = new Set(wanted.map((w) => key(w.name)));
|
|
1722
|
+
const undeclared = [...existing.entries()].filter(([k]) => !declared.has(k)).map(([, v]) => v);
|
|
1723
|
+
const unmanaged = undeclared.filter((v) => v.visibility === "selected");
|
|
1724
|
+
if (opts.prune) for (const v of undeclared.filter((u) => u.visibility !== "selected")) {
|
|
1725
|
+
if (!opts.dryRun) await client.variables.deleteVariable(repo, scope, v.name);
|
|
1726
|
+
counts.deleted++;
|
|
1727
|
+
}
|
|
1728
|
+
const parts = opts.dryRun ? [
|
|
1729
|
+
`would create ${counts.created}`,
|
|
1730
|
+
`would update ${counts.updated}`,
|
|
1731
|
+
`${counts.unchanged} unchanged`
|
|
1732
|
+
] : [
|
|
1733
|
+
`${counts.created} created`,
|
|
1734
|
+
`${counts.updated} updated`,
|
|
1735
|
+
`${counts.unchanged} unchanged`
|
|
1736
|
+
];
|
|
1737
|
+
if (counts.deleted > 0) parts.push(`${counts.deleted} ${opts.dryRun ? "would be deleted" : "deleted"}`);
|
|
1738
|
+
const left = opts.prune ? unmanaged : undeclared;
|
|
1739
|
+
if (left.length > 0) {
|
|
1740
|
+
const why = opts.prune ? "limited to selected repositories, not managed" : "not declared, left alone";
|
|
1741
|
+
parts.push(`${left.length} ${why}: ${left.map((v) => v.name).join(", ")}`);
|
|
1742
|
+
}
|
|
1743
|
+
return parts.join(", ");
|
|
1744
|
+
}
|
|
1745
|
+
/** Reconcile a repository's Actions variables. */
|
|
1746
|
+
function syncVariables(client, repo, variables, opts = {}) {
|
|
1747
|
+
return reconcile(client, repo, { kind: "repo" }, Object.entries(variables).map(([name, value]) => ({
|
|
1748
|
+
name,
|
|
1749
|
+
value
|
|
1750
|
+
})), {
|
|
1751
|
+
prune: opts.prune === true,
|
|
1752
|
+
dryRun: opts.dryRun === true
|
|
1753
|
+
});
|
|
1754
|
+
}
|
|
1755
|
+
/** Reconcile an organization's Actions variables. `repo` is only the coordinate the client is bound to. */
|
|
1756
|
+
function syncOrgVariables(client, repo, org, variables, opts = {}) {
|
|
1757
|
+
const wanted = Object.entries(variables).map(([name, v]) => ({
|
|
1758
|
+
name,
|
|
1759
|
+
value: v.value,
|
|
1760
|
+
visibility: v.visibility
|
|
1761
|
+
}));
|
|
1762
|
+
return reconcile(client, repo, {
|
|
1763
|
+
kind: "organization",
|
|
1764
|
+
org
|
|
1765
|
+
}, wanted, {
|
|
1766
|
+
prune: opts.prune === true,
|
|
1767
|
+
dryRun: opts.dryRun === true
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
// src/capabilities/source.ts
|
|
1771
|
+
function toPullRequest(raw) {
|
|
1772
|
+
return {
|
|
1773
|
+
number: raw.number,
|
|
1774
|
+
title: raw.title,
|
|
1775
|
+
state: raw.state,
|
|
1776
|
+
merged: raw.merged_at !== null,
|
|
1777
|
+
branch: raw.head.ref,
|
|
1778
|
+
headSha: raw.head.sha,
|
|
1779
|
+
url: raw.html_url
|
|
1780
|
+
};
|
|
1781
|
+
}
|
|
1782
|
+
/**
|
|
1783
|
+
* The GitHub implementation of the `source` capability: repo settings, rulesets, branch protection, security
|
|
1784
|
+
* features and local workflow files.
|
|
1785
|
+
*/
|
|
481
1786
|
var GitHubSource = class {
|
|
482
1787
|
client;
|
|
1788
|
+
/** Capability key, always `"source"`. */
|
|
483
1789
|
key = "source";
|
|
1790
|
+
/** Provider name, always `"github"`. */
|
|
484
1791
|
providerName = "github";
|
|
485
1792
|
owner;
|
|
486
1793
|
name;
|
|
@@ -488,6 +1795,7 @@ var GitHubSource = class {
|
|
|
488
1795
|
repoRoot;
|
|
489
1796
|
workflowDir;
|
|
490
1797
|
orgClient;
|
|
1798
|
+
userSyncClient;
|
|
491
1799
|
baseUrl;
|
|
492
1800
|
fetchImpl;
|
|
493
1801
|
constructor(client, opts) {
|
|
@@ -496,15 +1804,20 @@ var GitHubSource = class {
|
|
|
496
1804
|
this.owner = owner;
|
|
497
1805
|
this.name = name;
|
|
498
1806
|
this.repo = opts.repo;
|
|
499
|
-
this.repoRoot = opts.repoRoot
|
|
500
|
-
|
|
1807
|
+
this.repoRoot = findRootSync(opts.repoRoot, ".git", {
|
|
1808
|
+
fallback: "start",
|
|
1809
|
+
realpath: true
|
|
1810
|
+
});
|
|
1811
|
+
this.workflowDir = join(this.repoRoot, ".github", "workflows");
|
|
501
1812
|
this.orgClient = opts.orgClient;
|
|
1813
|
+
this.userSyncClient = opts.userSyncClient;
|
|
502
1814
|
this.baseUrl = opts.baseUrl;
|
|
503
1815
|
this.fetchImpl = opts.fetch;
|
|
504
1816
|
}
|
|
505
1817
|
async whoami() {
|
|
506
1818
|
return { login: (await this.client.user.getCurrentUser()).login };
|
|
507
1819
|
}
|
|
1820
|
+
/** Returns the repo's owner, name and default branch. */
|
|
508
1821
|
async getRepo() {
|
|
509
1822
|
const data = await this.client.repos.getRepo(this.repo);
|
|
510
1823
|
return {
|
|
@@ -513,27 +1826,34 @@ var GitHubSource = class {
|
|
|
513
1826
|
defaultBranch: data.default_branch
|
|
514
1827
|
};
|
|
515
1828
|
}
|
|
1829
|
+
/** Lists the repo's rulesets. */
|
|
516
1830
|
async listRulesets() {
|
|
517
1831
|
return this.client.rulesets.listRulesets(this.repo);
|
|
518
1832
|
}
|
|
1833
|
+
/** Creates a ruleset from the given payload. */
|
|
519
1834
|
async createRuleset(payload) {
|
|
520
1835
|
return this.client.rulesets.createRuleset(this.repo, payload);
|
|
521
1836
|
}
|
|
1837
|
+
/** Updates the ruleset with the given id from the payload. */
|
|
522
1838
|
async updateRuleset(id, payload) {
|
|
523
1839
|
return this.client.rulesets.updateRuleset(this.repo, id, payload);
|
|
524
1840
|
}
|
|
1841
|
+
/** Updates the repo's settings. */
|
|
525
1842
|
async updateRepoSettings(settings) {
|
|
526
1843
|
await this.client.repos.updateRepo(this.repo, settings);
|
|
527
1844
|
}
|
|
528
1845
|
async protectBranch(branch, payload) {
|
|
529
1846
|
await this.client.branches.protectBranch(this.repo, branch, payload);
|
|
530
1847
|
}
|
|
1848
|
+
/** Enables Dependabot vulnerability alerts. */
|
|
531
1849
|
async enableVulnerabilityAlerts() {
|
|
532
1850
|
await this.client.security.enableVulnerabilityAlerts(this.repo);
|
|
533
1851
|
}
|
|
1852
|
+
/** Enables Dependabot automated security fixes. */
|
|
534
1853
|
async enableAutomatedSecurityFixes() {
|
|
535
1854
|
await this.client.security.enableAutomatedSecurityFixes(this.repo);
|
|
536
1855
|
}
|
|
1856
|
+
/** Enables secret scanning. */
|
|
537
1857
|
async enableSecretScanning() {
|
|
538
1858
|
await this.client.security.enableSecretScanning(this.repo);
|
|
539
1859
|
}
|
|
@@ -546,9 +1866,11 @@ var GitHubSource = class {
|
|
|
546
1866
|
async enableDependencyGraph() {
|
|
547
1867
|
await this.client.security.enableDependencyGraph(this.repo);
|
|
548
1868
|
}
|
|
1869
|
+
/** Enables private vulnerability reporting. */
|
|
549
1870
|
async enablePrivateVulnerabilityReporting() {
|
|
550
1871
|
await this.client.security.enablePrivateVulnerabilityReporting(this.repo);
|
|
551
1872
|
}
|
|
1873
|
+
/** Lists the `.yml` and `.yaml` files in `.github/workflows`, sorted by name; empty when the folder is missing. */
|
|
552
1874
|
async listWorkflowFiles() {
|
|
553
1875
|
try {
|
|
554
1876
|
return (await readdir(this.workflowDir)).filter((e) => e.endsWith(".yml") || e.endsWith(".yaml")).sort();
|
|
@@ -557,6 +1879,7 @@ var GitHubSource = class {
|
|
|
557
1879
|
throw err;
|
|
558
1880
|
}
|
|
559
1881
|
}
|
|
1882
|
+
/** Reads a workflow file's text, or `null` when it does not exist. */
|
|
560
1883
|
async readWorkflowFile(name) {
|
|
561
1884
|
try {
|
|
562
1885
|
return await readFile(join(this.workflowDir, name), "utf8");
|
|
@@ -565,10 +1888,12 @@ var GitHubSource = class {
|
|
|
565
1888
|
throw err;
|
|
566
1889
|
}
|
|
567
1890
|
}
|
|
1891
|
+
/** Writes a workflow file, creating `.github/workflows` first when needed. */
|
|
568
1892
|
async writeWorkflowFile(name, contents) {
|
|
569
1893
|
await ensureDir(this.workflowDir);
|
|
570
1894
|
await writeFile(join(this.workflowDir, name), contents, "utf8");
|
|
571
1895
|
}
|
|
1896
|
+
/** Removes a workflow file; a file that is already gone is not an error. */
|
|
572
1897
|
async removeWorkflowFile(name) {
|
|
573
1898
|
try {
|
|
574
1899
|
await rm(join(this.workflowDir, name));
|
|
@@ -586,14 +1911,83 @@ var GitHubSource = class {
|
|
|
586
1911
|
return syncLabels(this.client, this.repo, canonical, stale);
|
|
587
1912
|
}
|
|
588
1913
|
async syncProperties(values) {
|
|
589
|
-
return syncProperties(this.client, this.repo, values);
|
|
1914
|
+
return syncProperties(this.client, this.repo, values, this.orgClient ?? this.client);
|
|
1915
|
+
}
|
|
1916
|
+
async getOrgPropertyValues(name) {
|
|
1917
|
+
return getOrgPropertyValues(this.orgClient ?? this.client, this.repo, name);
|
|
1918
|
+
}
|
|
1919
|
+
async addOrgPropertyValues(name, values) {
|
|
1920
|
+
return addOrgPropertyValues(this.orgClient ?? this.client, this.repo, name, values);
|
|
1921
|
+
}
|
|
1922
|
+
async checkPropertyValues(values) {
|
|
1923
|
+
return checkPropertyValues(this.orgClient ?? this.client, this.repo, values);
|
|
590
1924
|
}
|
|
591
1925
|
async syncTeams(teams) {
|
|
592
1926
|
return syncTeams(this.orgClient ?? this.client, this.repo, teams);
|
|
593
1927
|
}
|
|
1928
|
+
async teamMembers(teamSlug, org = this.owner) {
|
|
1929
|
+
return (await (this.orgClient ?? this.client).teams.members(org, teamSlug)).map((m) => ({
|
|
1930
|
+
id: String(m.id),
|
|
1931
|
+
login: m.login
|
|
1932
|
+
}));
|
|
1933
|
+
}
|
|
1934
|
+
async readFile(path, repo = this.repo) {
|
|
1935
|
+
return readRepoFile(this.userSyncClient ?? this.orgClient ?? this.client, repo, path);
|
|
1936
|
+
}
|
|
1937
|
+
async writeFile(path, content, opts) {
|
|
1938
|
+
return writeRepoFile(this.userSyncClient ?? this.orgClient ?? this.client, opts.repo ?? this.repo, path, content, opts);
|
|
1939
|
+
}
|
|
594
1940
|
async syncTopics(topics) {
|
|
595
1941
|
return syncTopics(this.client, this.repo, topics);
|
|
596
1942
|
}
|
|
1943
|
+
async syncVariables(variables, opts) {
|
|
1944
|
+
return syncVariables(this.client, this.repo, variables, opts);
|
|
1945
|
+
}
|
|
1946
|
+
async syncOrgVariables(org, variables, opts) {
|
|
1947
|
+
if (!this.orgClient) throw new Error("organization variables need the org token: set HOLOCRON_ORG_TOKEN or run `holocron auth set github.org <token>`");
|
|
1948
|
+
return syncOrgVariables(this.orgClient, this.repo, org, variables, opts);
|
|
1949
|
+
}
|
|
1950
|
+
async listVariables() {
|
|
1951
|
+
const found = await this.client.variables.listVariables(this.repo, { kind: "repo" });
|
|
1952
|
+
return Object.fromEntries(found.map((v) => [v.name, v.value]));
|
|
1953
|
+
}
|
|
1954
|
+
async listOrgVariables(org) {
|
|
1955
|
+
if (!this.orgClient) throw new MissingTokenError("organization variables need the org token: set HOLOCRON_ORG_TOKEN or run `holocron auth set github.org <token>`");
|
|
1956
|
+
const found = await this.orgClient.variables.listVariables(this.repo, {
|
|
1957
|
+
kind: "organization",
|
|
1958
|
+
org
|
|
1959
|
+
});
|
|
1960
|
+
return Object.fromEntries(found.map((v) => [v.name, {
|
|
1961
|
+
value: v.value,
|
|
1962
|
+
visibility: v.visibility ?? "all"
|
|
1963
|
+
}]));
|
|
1964
|
+
}
|
|
1965
|
+
async getRepoInfo() {
|
|
1966
|
+
return readRepoInfo(this.client, this.repo);
|
|
1967
|
+
}
|
|
1968
|
+
async getProperties() {
|
|
1969
|
+
const found = await this.client.properties.getValues(this.repo);
|
|
1970
|
+
return Object.fromEntries(found.flatMap((p) => p.value === null ? [] : [[p.property_name, p.value]]));
|
|
1971
|
+
}
|
|
1972
|
+
async listLabels() {
|
|
1973
|
+
return (await this.client.labels.listLabels(this.repo)).map((l) => ({
|
|
1974
|
+
name: l.name,
|
|
1975
|
+
color: l.color,
|
|
1976
|
+
description: l.description ?? ""
|
|
1977
|
+
}));
|
|
1978
|
+
}
|
|
1979
|
+
async listTeamAccess() {
|
|
1980
|
+
return (await (this.orgClient ?? this.client).teams.listForRepo(this.repo)).map((t) => ({
|
|
1981
|
+
slug: t.slug,
|
|
1982
|
+
permission: t.permission
|
|
1983
|
+
}));
|
|
1984
|
+
}
|
|
1985
|
+
async getRulesetDetail(id) {
|
|
1986
|
+
return toRulesetDetail(await this.client.rulesets.getRuleset(this.repo, id));
|
|
1987
|
+
}
|
|
1988
|
+
async getSecurity() {
|
|
1989
|
+
return readSecurity(this.client, this.repo);
|
|
1990
|
+
}
|
|
597
1991
|
async syncDescription(description) {
|
|
598
1992
|
await this.client.repos.updateRepo(this.repo, { description });
|
|
599
1993
|
return "description updated";
|
|
@@ -603,15 +1997,27 @@ var GitHubSource = class {
|
|
|
603
1997
|
return "homepage updated";
|
|
604
1998
|
}
|
|
605
1999
|
async getPullRequest(number, repo) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
2000
|
+
return toPullRequest(await this.client.pulls.getPullRequest(repo ?? this.repo, number));
|
|
2001
|
+
}
|
|
2002
|
+
async listPullRequests(state, repo) {
|
|
2003
|
+
return (await this.client.pulls.listPullRequests(repo ?? this.repo, state)).map(toPullRequest);
|
|
2004
|
+
}
|
|
2005
|
+
async listBranches(repo) {
|
|
2006
|
+
return (await this.client.branches.listBranches(repo ?? this.repo)).map((b) => ({
|
|
2007
|
+
name: b.name,
|
|
2008
|
+
sha: b.commit.sha
|
|
2009
|
+
}));
|
|
2010
|
+
}
|
|
2011
|
+
async deleteBranch(name, repo) {
|
|
2012
|
+
try {
|
|
2013
|
+
await this.client.branches.removeBranch(repo ?? this.repo, name);
|
|
2014
|
+
} catch (err) {
|
|
2015
|
+
if (err instanceof ProviderApiError && err.status === 422 && String(err.details).includes("does not exist")) return;
|
|
2016
|
+
throw err;
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
async listPullRequestCommits(number, repo) {
|
|
2020
|
+
return (await this.client.pulls.listCommits(repo ?? this.repo, number)).map((commit) => commit.sha);
|
|
615
2021
|
}
|
|
616
2022
|
async configurePages(config, token) {
|
|
617
2023
|
const pagesClient = createGitHubClient$1({
|
|
@@ -650,18 +2056,8 @@ async function ensureDir(path) {
|
|
|
650
2056
|
throw err;
|
|
651
2057
|
}
|
|
652
2058
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
/**
|
|
656
|
-
* `verifyToken` — plugin-level export used by `holocron auth set` +
|
|
657
|
-
* `holocron auth check`. Hits `GET /user` and translates the response
|
|
658
|
-
* into the normalized `VerifyTokenResult` shape.
|
|
659
|
-
*
|
|
660
|
-
* Kept as a standalone function (not a capability method) so the auth
|
|
661
|
-
* command can call it without initializing the full plugin — plugin
|
|
662
|
-
* construction requires an already-resolved token, which is exactly
|
|
663
|
-
* what we don't have yet at bootstrap time.
|
|
664
|
-
*/
|
|
2059
|
+
// src/verify-token.ts
|
|
2060
|
+
/** Checks a token against `GET /user` and returns who it belongs to, or why it failed. */
|
|
665
2061
|
async function verifyToken(token, opts = {}) {
|
|
666
2062
|
const client = createGitHubClient({
|
|
667
2063
|
token,
|
|
@@ -669,49 +2065,61 @@ async function verifyToken(token, opts = {}) {
|
|
|
669
2065
|
fetch: opts.fetch
|
|
670
2066
|
});
|
|
671
2067
|
try {
|
|
672
|
-
const me = await client.user.
|
|
2068
|
+
const { user: me, expiresAt } = await client.user.getCurrentUserWithExpiry();
|
|
673
2069
|
return {
|
|
674
2070
|
ok: true,
|
|
675
|
-
subject: `user @ ${me.login ?? me.email ?? "unknown"}
|
|
2071
|
+
subject: `user @ ${me.login ?? me.email ?? "unknown"}`,
|
|
2072
|
+
...expiresAt ? { expiresAt } : {}
|
|
676
2073
|
};
|
|
677
2074
|
} catch (err) {
|
|
678
2075
|
return {
|
|
679
2076
|
ok: false,
|
|
680
|
-
message:
|
|
2077
|
+
message: errorMessage(err)
|
|
681
2078
|
};
|
|
682
2079
|
}
|
|
683
2080
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
function source(ctx, orgClient) {
|
|
2081
|
+
// src/index.ts
|
|
2082
|
+
/** Builds the `source` capability; the optional clients cover org-level and user-sync access. */
|
|
2083
|
+
function source(ctx, orgClient, userSyncClient) {
|
|
687
2084
|
return new GitHubSource(ctx.client, {
|
|
688
2085
|
repo: ctx.repo,
|
|
689
2086
|
repoRoot: ctx.repoRoot,
|
|
690
2087
|
orgClient,
|
|
2088
|
+
userSyncClient,
|
|
691
2089
|
baseUrl: ctx.options.baseUrl,
|
|
692
2090
|
fetch: ctx.options.fetch
|
|
693
2091
|
});
|
|
694
2092
|
}
|
|
695
|
-
|
|
696
|
-
|
|
2093
|
+
/** Builds the `secrets` capability; the optional client handles organization secrets. */
|
|
2094
|
+
function secrets(ctx, orgClient) {
|
|
2095
|
+
return new GitHubSecrets(ctx.client, { repo: ctx.repo }, orgClient);
|
|
697
2096
|
}
|
|
2097
|
+
/** Builds the `environments` capability. */
|
|
698
2098
|
function environments(ctx) {
|
|
699
2099
|
return new GitHubEnvironments(ctx.client, { repo: ctx.repo });
|
|
700
2100
|
}
|
|
2101
|
+
/** Builds the `ci` capability. */
|
|
701
2102
|
function ci(ctx) {
|
|
702
2103
|
return new GitHubCi(ctx.client, { repo: ctx.repo });
|
|
703
2104
|
}
|
|
2105
|
+
/** Builds the `issues` capability, passing the lifecycle labels when configured. */
|
|
704
2106
|
function issues(ctx) {
|
|
705
2107
|
const opts = { repo: ctx.repo };
|
|
706
2108
|
if (ctx.options.labels !== void 0) opts.labels = ctx.options.labels;
|
|
707
2109
|
return new GitHubIssues(ctx.client, opts);
|
|
708
2110
|
}
|
|
2111
|
+
/** Builds the `projects` capability: GitHub Projects v2 over GraphQL, with items keyed relative to the configured repo. */
|
|
2112
|
+
function projects(ctx) {
|
|
2113
|
+
return new GitHubProjects(ctx.client.graphql, { repo: ctx.repo });
|
|
2114
|
+
}
|
|
2115
|
+
/** Creates the plugin, resolving a token per capability when it is first used. */
|
|
709
2116
|
function createPlugin(options) {
|
|
710
2117
|
function makeCtx(resolver) {
|
|
2118
|
+
const token = resolver(options);
|
|
711
2119
|
return {
|
|
712
2120
|
options,
|
|
713
2121
|
client: createGitHubClient$1({
|
|
714
|
-
token
|
|
2122
|
+
token,
|
|
715
2123
|
baseUrl: options.baseUrl,
|
|
716
2124
|
fetch: options.fetch
|
|
717
2125
|
}),
|
|
@@ -719,10 +2127,45 @@ function createPlugin(options) {
|
|
|
719
2127
|
repoRoot: options.repoRoot ?? process.cwd()
|
|
720
2128
|
};
|
|
721
2129
|
}
|
|
2130
|
+
/** A token, or undefined when that feature token is simply not configured. */
|
|
2131
|
+
function tryResolve(resolver) {
|
|
2132
|
+
try {
|
|
2133
|
+
return resolver(options);
|
|
2134
|
+
} catch (err) {
|
|
2135
|
+
if (err instanceof AuthError) return void 0;
|
|
2136
|
+
throw err;
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
/**
|
|
2140
|
+
* Organization secrets need an org-resource-owner token (`github.secrets`);
|
|
2141
|
+
* repo and environment secrets need `github.admin`. Each scope prefers its own
|
|
2142
|
+
* token and falls back to the other, so a setup with only one of them keeps
|
|
2143
|
+
* working, and an explicit `--token` serves both. With neither configured this
|
|
2144
|
+
* fails exactly as the admin-token capabilities do.
|
|
2145
|
+
*/
|
|
2146
|
+
function makeSecrets() {
|
|
2147
|
+
const secretsToken = tryResolve(resolveSecretsToken);
|
|
2148
|
+
const adminToken = tryResolve(resolveAdminToken);
|
|
2149
|
+
if (!secretsToken && !adminToken) resolveAdminToken(options);
|
|
2150
|
+
const clientFor = (token) => createGitHubClient$1({
|
|
2151
|
+
token,
|
|
2152
|
+
baseUrl: options.baseUrl,
|
|
2153
|
+
fetch: options.fetch
|
|
2154
|
+
});
|
|
2155
|
+
const repoClient = clientFor(adminToken ?? secretsToken);
|
|
2156
|
+
const orgClient = clientFor(secretsToken ?? adminToken);
|
|
2157
|
+
return secrets({
|
|
2158
|
+
options,
|
|
2159
|
+
client: repoClient,
|
|
2160
|
+
repo: options.repo,
|
|
2161
|
+
repoRoot: options.repoRoot ?? process.cwd()
|
|
2162
|
+
}, orgClient);
|
|
2163
|
+
}
|
|
722
2164
|
function makeOrgClient() {
|
|
723
2165
|
try {
|
|
2166
|
+
const token = resolveOrgToken(options);
|
|
724
2167
|
return createGitHubClient$1({
|
|
725
|
-
token
|
|
2168
|
+
token,
|
|
726
2169
|
baseUrl: options.baseUrl,
|
|
727
2170
|
fetch: options.fetch
|
|
728
2171
|
});
|
|
@@ -730,14 +2173,34 @@ function createPlugin(options) {
|
|
|
730
2173
|
return;
|
|
731
2174
|
}
|
|
732
2175
|
}
|
|
2176
|
+
/** The token for the user-sync files; undefined when it is not configured, and the org token is used instead. */
|
|
2177
|
+
function makeUserSyncClient() {
|
|
2178
|
+
const token = tryResolve(resolveUserSyncToken);
|
|
2179
|
+
return token ? createGitHubClient$1({
|
|
2180
|
+
token,
|
|
2181
|
+
baseUrl: options.baseUrl,
|
|
2182
|
+
fetch: options.fetch
|
|
2183
|
+
}) : void 0;
|
|
2184
|
+
}
|
|
733
2185
|
return {
|
|
734
2186
|
name: "@theholocron/holocron-plugin-github",
|
|
2187
|
+
probes: { connection: connectionProbe({
|
|
2188
|
+
provider: "GitHub",
|
|
2189
|
+
url: options.baseUrl ?? "https://api.github.com",
|
|
2190
|
+
fetch: options.fetch,
|
|
2191
|
+
token: () => resolveReadToken(options),
|
|
2192
|
+
verify: (token) => verifyToken(token, {
|
|
2193
|
+
baseUrl: options.baseUrl,
|
|
2194
|
+
fetch: options.fetch
|
|
2195
|
+
})
|
|
2196
|
+
}) },
|
|
735
2197
|
capabilities: {
|
|
736
|
-
source: () => source(makeCtx(resolveAdminToken), makeOrgClient()),
|
|
2198
|
+
source: () => source(makeCtx(resolveAdminToken), makeOrgClient(), makeUserSyncClient()),
|
|
737
2199
|
ci: () => ci(makeCtx(resolveReadToken)),
|
|
738
|
-
secrets: () =>
|
|
2200
|
+
secrets: () => makeSecrets(),
|
|
739
2201
|
environments: () => environments(makeCtx(resolveAdminToken)),
|
|
740
|
-
issues: () => issues(makeCtx(resolveIssuesToken))
|
|
2202
|
+
issues: () => issues(makeCtx(resolveIssuesToken)),
|
|
2203
|
+
projects: () => projects(makeCtx(resolveOrgToken))
|
|
741
2204
|
}
|
|
742
2205
|
};
|
|
743
2206
|
}
|
|
@@ -746,5 +2209,16 @@ function createPlugin(options) {
|
|
|
746
2209
|
* is supplied or the supplied token is rejected.
|
|
747
2210
|
*/
|
|
748
2211
|
const AUTH_HINT = "generate fine-grained Personal Access Tokens at https://github.com/settings/tokens (one per feature — see docs/tokens.md for required scopes per operation), then run: holocron auth set github.<feature> <PAT>";
|
|
749
|
-
|
|
750
|
-
|
|
2212
|
+
/** Every token this plugin takes, for `holocron doctor tokens`. */
|
|
2213
|
+
const tokens = [
|
|
2214
|
+
resolveReadToken,
|
|
2215
|
+
resolveIssuesToken,
|
|
2216
|
+
resolveSyncToken,
|
|
2217
|
+
resolveReleaseToken,
|
|
2218
|
+
resolveAdminToken,
|
|
2219
|
+
resolveSecretsToken,
|
|
2220
|
+
resolveDeployToken,
|
|
2221
|
+
resolveUserSyncToken,
|
|
2222
|
+
resolveOrgToken
|
|
2223
|
+
].map((resolver) => resolver.token);
|
|
2224
|
+
export { AUTH_HINT, AuthError, GitHubCi, GitHubEnvironments, GitHubIssues, GitHubProjects, GitHubSecrets, GitHubSource, ci, createFeatureResolver, createGitHubClient, createPlugin, encryptSecret, environments, issues, normalizeTeamEntry, projects, resolveAdminToken, resolveDeployToken, resolveIssuesToken, resolveOrgToken, resolveReadToken, resolveReleaseToken, resolveSecretsToken, resolveSyncToken, resolveUserSyncToken, secrets, source, syncLabels, syncTeams, tokens, verifyToken };
|