@theholocron/holocron-plugin-github 2.0.0-alpha.41 → 2.0.0-alpha.42
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/dist/index.d.mts +19 -2
- package/dist/index.mjs +51 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Auth, AuthError, Ci, CiRun, CiRunFilter, Environment, Environments, Issue, IssueSearchFilter, Issues, LifecycleResult, LifecycleSlot, RepoRef, RepoSettings, ResolveTokenInput, RestClient, RestClient as RestClient$1, Ruleset, SecretScope, Secrets, Source, TrackerDoctorReport, TrackerUser } from "@theholocron/cli";
|
|
1
|
+
import { Auth, AuthError, Ci, CiRun, CiRunFilter, Environment, Environments, Issue, IssueSearchFilter, Issues, LabelDef, LifecycleResult, LifecycleSlot, RepoRef, RepoSettings, ResolveTokenInput, RestClient, RestClient as RestClient$1, Ruleset, SecretScope, Secrets, Source, TrackerDoctorReport, TrackerUser } from "@theholocron/cli";
|
|
2
2
|
|
|
3
3
|
//#region src/auth.d.ts
|
|
4
4
|
declare const resolveToken: (input?: import("@theholocron/http-client").ResolveTokenInput) => string;
|
|
@@ -54,6 +54,7 @@ declare class GitHubSource implements Source {
|
|
|
54
54
|
writeWorkflowFile(name: string, contents: string): Promise<void>;
|
|
55
55
|
removeWorkflowFile(name: string): Promise<void>;
|
|
56
56
|
writeRepoFile(path: string, contents: string): Promise<void>;
|
|
57
|
+
syncLabels(canonical: ReadonlyArray<LabelDef>, stale: ReadonlyArray<string>): Promise<string>;
|
|
57
58
|
}
|
|
58
59
|
//#endregion
|
|
59
60
|
//#region src/capabilities/secrets.d.ts
|
|
@@ -155,6 +156,22 @@ declare class GitHubIssues implements Issues {
|
|
|
155
156
|
private mapIssue;
|
|
156
157
|
}
|
|
157
158
|
//#endregion
|
|
159
|
+
//#region src/capabilities/labels.d.ts
|
|
160
|
+
interface CanonicalLabel {
|
|
161
|
+
readonly name: string;
|
|
162
|
+
readonly color: string;
|
|
163
|
+
readonly description: string;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Idempotently synchronise a repo's labels to the canonical set.
|
|
167
|
+
*
|
|
168
|
+
* - Creates labels that are missing.
|
|
169
|
+
* - PATCHes labels whose color or description has drifted.
|
|
170
|
+
* - DELETEs labels listed in `stale`.
|
|
171
|
+
* - Leaves unrecognised labels that aren't in `stale` untouched.
|
|
172
|
+
*/
|
|
173
|
+
declare function syncLabels(rest: RestClient, repo: string, canonical: ReadonlyArray<CanonicalLabel>, stale: ReadonlyArray<string>): Promise<string>;
|
|
174
|
+
//#endregion
|
|
158
175
|
//#region src/verify-token.d.ts
|
|
159
176
|
/**
|
|
160
177
|
* `verifyToken` — plugin-level export used by `holocron auth set` +
|
|
@@ -228,4 +245,4 @@ declare function createPlugin(options: GitHubPluginOptions): {
|
|
|
228
245
|
*/
|
|
229
246
|
declare const AUTH_HINT: string;
|
|
230
247
|
//#endregion
|
|
231
|
-
export { AUTH_HINT, type Auth, AuthError, GitHubCi, GitHubEnvironments, GitHubIssues, GitHubPluginOptions, GitHubSecrets, GitHubSource, PluginContext, type ResolveTokenInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, ci, createContext, createGitHubRestClient, createPlugin, encryptSecret, environments, issues, resolveToken, secrets, source, verifyToken };
|
|
248
|
+
export { AUTH_HINT, type Auth, AuthError, type CanonicalLabel, GitHubCi, GitHubEnvironments, GitHubIssues, GitHubPluginOptions, GitHubSecrets, GitHubSource, PluginContext, type ResolveTokenInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, ci, createContext, createGitHubRestClient, createPlugin, encryptSecret, environments, issues, resolveToken, secrets, source, syncLabels, verifyToken };
|
package/dist/index.mjs
CHANGED
|
@@ -436,6 +436,53 @@ var GitHubSecrets = class {
|
|
|
436
436
|
}
|
|
437
437
|
};
|
|
438
438
|
//#endregion
|
|
439
|
+
//#region src/capabilities/labels.ts
|
|
440
|
+
/**
|
|
441
|
+
* Idempotently synchronise a repo's labels to the canonical set.
|
|
442
|
+
*
|
|
443
|
+
* - Creates labels that are missing.
|
|
444
|
+
* - PATCHes labels whose color or description has drifted.
|
|
445
|
+
* - DELETEs labels listed in `stale`.
|
|
446
|
+
* - Leaves unrecognised labels that aren't in `stale` untouched.
|
|
447
|
+
*/
|
|
448
|
+
async function syncLabels(rest, repo, canonical, stale) {
|
|
449
|
+
const { owner, name } = parseRepo(repo);
|
|
450
|
+
const base = `/repos/${owner}/${name}`;
|
|
451
|
+
const existing = await rest.request(`${base}/labels?per_page=100`);
|
|
452
|
+
const existingMap = new Map(existing.map((l) => [l.name.toLowerCase(), l]));
|
|
453
|
+
let created = 0;
|
|
454
|
+
let updated = 0;
|
|
455
|
+
let deleted = 0;
|
|
456
|
+
for (const label of canonical) {
|
|
457
|
+
const current = existingMap.get(label.name);
|
|
458
|
+
if (!current) {
|
|
459
|
+
await rest.request(`${base}/labels`, {
|
|
460
|
+
method: "POST",
|
|
461
|
+
body: {
|
|
462
|
+
name: label.name,
|
|
463
|
+
color: label.color,
|
|
464
|
+
description: label.description
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
created++;
|
|
468
|
+
} else if (current.color !== label.color || (current.description ?? "") !== label.description) {
|
|
469
|
+
await rest.request(`${base}/labels/${encodeURIComponent(label.name)}`, {
|
|
470
|
+
method: "PATCH",
|
|
471
|
+
body: {
|
|
472
|
+
color: label.color,
|
|
473
|
+
description: label.description
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
updated++;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
for (const staleName of stale) if (existingMap.has(staleName)) {
|
|
480
|
+
await rest.request(`${base}/labels/${encodeURIComponent(staleName)}`, { method: "DELETE" });
|
|
481
|
+
deleted++;
|
|
482
|
+
}
|
|
483
|
+
return `${created} created, ${updated} updated, ${deleted} deleted`;
|
|
484
|
+
}
|
|
485
|
+
//#endregion
|
|
439
486
|
//#region src/capabilities/source.ts
|
|
440
487
|
/**
|
|
441
488
|
* `source` capability for GitHub.
|
|
@@ -590,6 +637,9 @@ var GitHubSource = class {
|
|
|
590
637
|
await ensureDir(dirname(full));
|
|
591
638
|
await writeFile(full, contents, "utf8");
|
|
592
639
|
}
|
|
640
|
+
async syncLabels(canonical, stale) {
|
|
641
|
+
return syncLabels(this.rest, `${this.owner}/${this.name}`, canonical, stale);
|
|
642
|
+
}
|
|
593
643
|
};
|
|
594
644
|
function isENOENT(err) {
|
|
595
645
|
return typeof err === "object" && err !== null && "code" in err && err.code === "ENOENT";
|
|
@@ -705,4 +755,4 @@ function createPlugin(options) {
|
|
|
705
755
|
*/
|
|
706
756
|
const AUTH_HINT = "generate a Personal Access Token at https://github.com/settings/tokens (scopes: repo, admin:repo_hook — plus admin:org for org-level ops), then run: holocron auth set github <PAT>";
|
|
707
757
|
//#endregion
|
|
708
|
-
export { AUTH_HINT, AuthError, GitHubCi, GitHubEnvironments, GitHubIssues, GitHubSecrets, GitHubSource, ci, createContext, createGitHubRestClient, createPlugin, encryptSecret, environments, issues, resolveToken, secrets, source, verifyToken };
|
|
758
|
+
export { AUTH_HINT, AuthError, GitHubCi, GitHubEnvironments, GitHubIssues, GitHubSecrets, GitHubSource, ci, createContext, createGitHubRestClient, createPlugin, encryptSecret, environments, issues, resolveToken, secrets, source, syncLabels, verifyToken };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/holocron-plugin-github",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.42",
|
|
4
4
|
"description": "Holocron plugin for GitHub. Implements source, ci, secrets, environments, and issues capabilities against the GitHub REST API.",
|
|
5
5
|
"homepage": "https://github.com/theholocron/holocron/tree/main/packages/holocron-plugin-github#readme",
|
|
6
6
|
"bugs": "https://github.com/theholocron/holocron/issues",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@theholocron/cli": "2.0.0-alpha.
|
|
24
|
+
"@theholocron/cli": "2.0.0-alpha.42"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"libsodium-wrappers": "^0.7.15"
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"tsx": "^4.22.4",
|
|
42
42
|
"typescript": "^5.9.3",
|
|
43
43
|
"vitest": "^4.1.10",
|
|
44
|
-
"@theholocron/cli": "2.0.0-alpha.
|
|
44
|
+
"@theholocron/cli": "2.0.0-alpha.42"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|