@theholocron/holocron-plugin-github 5.0.0-alpha.515 → 5.0.0-alpha.517
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 +10 -1
- package/dist/index.mjs +163 -4
- package/package.json +11 -11
package/dist/index.d.mts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* receives plugin-level options from `holocron.config.json` and
|
|
8
8
|
* returns the bound implementation.
|
|
9
9
|
*/
|
|
10
|
-
import { AddedItem, Auth, AuthError, BoardItem, BoardItemInput, BoardState, BoardSummary, BoardTemplate, Ci, CiRun, CiRunFilter, EnsureReport, Environment, Environments, ExportInfo, ImportOptions, ImportResult, Issue, IssueCreateInput, IssuePatch, IssueRecord, IssueSearchFilter, IssueSelector, IssueUpdateResult, Issues, LabelDef, LifecycleResult, LifecycleSlot, MoveReport, PagesConfig, PluginToken, Projects, PullRequest, PullRequestChecks, PullRequestInput, PullRequestPatch, PullRequestResult, RepoRef, RepoSettings, ResolveTokenInput, Ruleset, SecretAccess, SecretScope, Secrets, Source, SourceBranch, SourceFile, SourceRepoInfo, SourceRulesetDetail, SourceSecurity, SourceTeamMember, SyncResult, TeamEntry, TeamEntry as TeamEntry$1, TeamPermission, TeamPermission as TeamPermission$1, TrackerDoctorReport, TrackerUser, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess, createFeatureResolver } from "@theholocron/cli";
|
|
10
|
+
import { AddedItem, Auth, AuthError, BoardItem, BoardItemInput, BoardState, BoardSummary, BoardTemplate, Ci, CiRun, CiRunFilter, EnsureRelaySourceInput, EnsureRelaySourceResult, EnsureReport, Environment, Environments, ExportInfo, ImportOptions, ImportResult, InspectRelaySourceInput, Issue, IssueCreateInput, IssuePatch, IssueRecord, IssueSearchFilter, IssueSelector, IssueUpdateResult, Issues, LabelDef, LifecycleResult, LifecycleSlot, MoveReport, PagesConfig, PluginToken, Projects, PullRequest, PullRequestChecks, PullRequestInput, PullRequestPatch, PullRequestResult, RelaySourceState, RepoRef, RepoSettings, ResolveTokenInput, Ruleset, SecretAccess, SecretScope, Secrets, Source, SourceBranch, SourceFile, SourceRepoInfo, SourceRulesetDetail, SourceSecurity, SourceTeamMember, SyncResult, TeamEntry, TeamEntry as TeamEntry$1, TeamPermission, TeamPermission as TeamPermission$1, TrackerDoctorReport, TrackerUser, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess, createFeatureResolver } from "@theholocron/cli";
|
|
11
11
|
import { GitHubClient, GitHubClientOptions, GraphQLClient, createGitHubClient } from "@theholocron/github-client";
|
|
12
12
|
/** Resolves the token for read-only GitHub access (`HOLOCRON_READ_TOKEN`, keyring key `github.read`). */
|
|
13
13
|
export declare const resolveReadToken: import("@theholocron/cli").FeatureResolver;
|
|
@@ -309,6 +309,15 @@ export declare class GitHubSource implements Source {
|
|
|
309
309
|
private readonly baseUrl?;
|
|
310
310
|
private readonly fetchImpl?;
|
|
311
311
|
constructor(client: GitHubClient, opts: SourceOptions);
|
|
312
|
+
/**
|
|
313
|
+
* Makes the GitHub webhook for a relay source: on one repository with the admin token, or on the organization
|
|
314
|
+
* (`options.org`) with the organization token. Found by URL, events and `active` brought in line, nothing deleted.
|
|
315
|
+
*/
|
|
316
|
+
ensureRelaySource(input: EnsureRelaySourceInput): Promise<EnsureRelaySourceResult>;
|
|
317
|
+
/** Reads the relay source's webhook back, changing nothing. GitHub never returns the secret, so `hasSecret` is left out. */
|
|
318
|
+
inspectRelaySource(input: InspectRelaySourceInput): Promise<RelaySourceState>;
|
|
319
|
+
/** The organization token for an organization's webhook, the repository one otherwise. */
|
|
320
|
+
private relayClient;
|
|
312
321
|
whoami(): Promise<{
|
|
313
322
|
login: string;
|
|
314
323
|
}>;
|
package/dist/index.mjs
CHANGED
|
@@ -2448,6 +2448,122 @@ async function readSecurity(client, repo) {
|
|
|
2448
2448
|
};
|
|
2449
2449
|
return Object.fromEntries(Object.entries(found).filter(([, v]) => v !== void 0));
|
|
2450
2450
|
}
|
|
2451
|
+
// src/capabilities/relay-source.ts
|
|
2452
|
+
/** The events a webhook subscribes to when the layout names none: the one the Dependabot relay source carries. */
|
|
2453
|
+
const DEFAULT_RELAY_EVENTS = ["dependabot_alert"];
|
|
2454
|
+
/** A repository name, `owner/name`, made of the characters GitHub allows. */
|
|
2455
|
+
const REPOSITORY$1 = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
2456
|
+
/** An organization login. */
|
|
2457
|
+
const ORGANIZATION = /^[A-Za-z0-9][A-Za-z0-9-]*$/;
|
|
2458
|
+
/**
|
|
2459
|
+
* Where a relay source's one webhook lives. A webhook has one URL, so a source covers one place, not a list: a single
|
|
2460
|
+
* repository (`scope: ["owner/name"]`, or the plugin's own repository when `scope` is absent) or an organization
|
|
2461
|
+
* (`options: { org: "name" }` with no `scope`). Both together, more than one repository and anything that is not
|
|
2462
|
+
* `owner/name` are a problem the caller reports, never a guess.
|
|
2463
|
+
*/
|
|
2464
|
+
function relayTarget(input, defaultRepo) {
|
|
2465
|
+
const org = input.options?.org;
|
|
2466
|
+
if (org !== void 0) {
|
|
2467
|
+
if (typeof org !== "string" || !ORGANIZATION.test(org)) return { problem: `relay source ${input.source}: \`options.org\` must be an organization login` };
|
|
2468
|
+
if (input.scope !== void 0 && input.scope.length > 0) return { problem: `relay source ${input.source}: name a repository in \`scope\` or an organization in \`options.org\`, not both` };
|
|
2469
|
+
return {
|
|
2470
|
+
scope: {
|
|
2471
|
+
kind: "organization",
|
|
2472
|
+
org
|
|
2473
|
+
},
|
|
2474
|
+
label: `organization ${org}`
|
|
2475
|
+
};
|
|
2476
|
+
}
|
|
2477
|
+
const scope = input.scope ?? [];
|
|
2478
|
+
if (scope.length > 1) return { problem: `relay source ${input.source}: a webhook has one URL, so \`scope\` names one repository, not ${scope.length}; use \`options.org\` for an organization` };
|
|
2479
|
+
const repo = scope[0] ?? defaultRepo;
|
|
2480
|
+
if (!REPOSITORY$1.test(repo)) return { problem: `relay source ${input.source}: \`scope\` must be one repository as \`owner/name\`${scope.length === 0 ? " (the plugin has no repository to default to)" : ""}` };
|
|
2481
|
+
return {
|
|
2482
|
+
scope: {
|
|
2483
|
+
kind: "repo",
|
|
2484
|
+
repo
|
|
2485
|
+
},
|
|
2486
|
+
label: `repository ${repo}`
|
|
2487
|
+
};
|
|
2488
|
+
}
|
|
2489
|
+
/** Whether two event lists subscribe to the same events. */
|
|
2490
|
+
function sameEvents(a, b) {
|
|
2491
|
+
return a.length === b.length && [...a].sort().every((event, i) => event === [...b].sort()[i]);
|
|
2492
|
+
}
|
|
2493
|
+
/** The sentence for a token GitHub refuses, which GitHub answers as a 403 or, for a hidden resource, a 404. */
|
|
2494
|
+
function accessTodo(label, scope) {
|
|
2495
|
+
return `GitHub refused the webhook call for ${label}: the token needs ${scope.kind === "organization" ? "Organization permission Webhooks: read and write (classic: admin:org_hook)" : "Repository permission Webhooks: read and write (classic: admin:repo_hook)"}, or add the webhook in the settings yourself and set the secret on the Worker`;
|
|
2496
|
+
}
|
|
2497
|
+
/**
|
|
2498
|
+
* Makes the GitHub webhook for a relay source (spec `tech-relay-sources`, issue #2531). The webhook is found by its
|
|
2499
|
+
* `config.url`; when absent it is made with the secret the caller offers (GitHub never returns it, so it is returned
|
|
2500
|
+
* only now), and an existing one has only its events and `active` flag brought in line. Nothing is deleted and an
|
|
2501
|
+
* adopted webhook keeps the secret the Worker has.
|
|
2502
|
+
*/
|
|
2503
|
+
async function ensureRelaySource(client, defaultRepo, input) {
|
|
2504
|
+
const target = relayTarget(input, defaultRepo);
|
|
2505
|
+
if ("problem" in target) return {
|
|
2506
|
+
created: false,
|
|
2507
|
+
updated: [],
|
|
2508
|
+
todo: [target.problem]
|
|
2509
|
+
};
|
|
2510
|
+
const events = input.events && input.events.length > 0 ? input.events : DEFAULT_RELAY_EVENTS;
|
|
2511
|
+
try {
|
|
2512
|
+
const found = (await client.hooks.listHooks(target.scope)).find((hook) => hook.config.url === input.url);
|
|
2513
|
+
if (!found) {
|
|
2514
|
+
if (!input.secret) return {
|
|
2515
|
+
created: false,
|
|
2516
|
+
updated: [],
|
|
2517
|
+
todo: [`no signing secret was offered for the ${target.label} webhook, so none was made`]
|
|
2518
|
+
};
|
|
2519
|
+
await client.hooks.createHook(target.scope, {
|
|
2520
|
+
url: input.url,
|
|
2521
|
+
secret: input.secret,
|
|
2522
|
+
events
|
|
2523
|
+
});
|
|
2524
|
+
return {
|
|
2525
|
+
created: true,
|
|
2526
|
+
updated: [],
|
|
2527
|
+
secret: input.secret
|
|
2528
|
+
};
|
|
2529
|
+
}
|
|
2530
|
+
const updated = [];
|
|
2531
|
+
const patch = {};
|
|
2532
|
+
if (!sameEvents(found.events, events)) {
|
|
2533
|
+
patch.events = events;
|
|
2534
|
+
updated.push("events");
|
|
2535
|
+
}
|
|
2536
|
+
if (!found.active) {
|
|
2537
|
+
patch.active = true;
|
|
2538
|
+
updated.push("active");
|
|
2539
|
+
}
|
|
2540
|
+
if (updated.length > 0) await client.hooks.updateHook(target.scope, found.id, patch);
|
|
2541
|
+
return {
|
|
2542
|
+
created: false,
|
|
2543
|
+
updated
|
|
2544
|
+
};
|
|
2545
|
+
} catch (err) {
|
|
2546
|
+
if (err instanceof ProviderApiError && (err.status === 403 || err.status === 404)) return {
|
|
2547
|
+
created: false,
|
|
2548
|
+
updated: [],
|
|
2549
|
+
todo: [accessTodo(target.label, target.scope)]
|
|
2550
|
+
};
|
|
2551
|
+
throw err;
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
/** Reads the webhook back without changing anything: whether it exists, is active and what it subscribes to. The secret is never readable. */
|
|
2555
|
+
async function inspectRelaySource(client, defaultRepo, input) {
|
|
2556
|
+
const target = relayTarget(input, defaultRepo);
|
|
2557
|
+
if ("problem" in target) throw new Error(target.problem);
|
|
2558
|
+
const found = (await client.hooks.listHooks(target.scope)).find((hook) => hook.config.url === input.url);
|
|
2559
|
+
if (!found) return { exists: false };
|
|
2560
|
+
return {
|
|
2561
|
+
exists: true,
|
|
2562
|
+
enabled: found.active,
|
|
2563
|
+
events: found.events,
|
|
2564
|
+
...target.scope.kind === "repo" ? { scope: [target.scope.repo] } : {}
|
|
2565
|
+
};
|
|
2566
|
+
}
|
|
2451
2567
|
// src/capabilities/teams.ts
|
|
2452
2568
|
/** Turns a team entry into slug and permission form; a bare slug gets `push`. */
|
|
2453
2569
|
function normalizeTeamEntry(entry) {
|
|
@@ -2611,6 +2727,21 @@ var GitHubSource = class {
|
|
|
2611
2727
|
this.baseUrl = opts.baseUrl;
|
|
2612
2728
|
this.fetchImpl = opts.fetch;
|
|
2613
2729
|
}
|
|
2730
|
+
/**
|
|
2731
|
+
* Makes the GitHub webhook for a relay source: on one repository with the admin token, or on the organization
|
|
2732
|
+
* (`options.org`) with the organization token. Found by URL, events and `active` brought in line, nothing deleted.
|
|
2733
|
+
*/
|
|
2734
|
+
async ensureRelaySource(input) {
|
|
2735
|
+
return ensureRelaySource(this.relayClient(input), this.repo, input);
|
|
2736
|
+
}
|
|
2737
|
+
/** Reads the relay source's webhook back, changing nothing. GitHub never returns the secret, so `hasSecret` is left out. */
|
|
2738
|
+
async inspectRelaySource(input) {
|
|
2739
|
+
return inspectRelaySource(this.relayClient(input), this.repo, input);
|
|
2740
|
+
}
|
|
2741
|
+
/** The organization token for an organization's webhook, the repository one otherwise. */
|
|
2742
|
+
relayClient(input) {
|
|
2743
|
+
return input.options?.org !== void 0 ? this.orgClient ?? this.client : this.client;
|
|
2744
|
+
}
|
|
2614
2745
|
async whoami() {
|
|
2615
2746
|
return { login: (await this.client.user.getCurrentUser()).login };
|
|
2616
2747
|
}
|
|
@@ -3624,6 +3755,26 @@ function everywhere(rules) {
|
|
|
3624
3755
|
} };
|
|
3625
3756
|
}
|
|
3626
3757
|
/**
|
|
3758
|
+
* `rules` everywhere, plus a permission only a person at a terminal needs: `local` and `dev` must have `held`, and `ci`
|
|
3759
|
+
* must not have `ci` (a workflow's token needs no more than it uses).
|
|
3760
|
+
*/
|
|
3761
|
+
function withoutInCi(rules, held, ci) {
|
|
3762
|
+
return { permissions: {
|
|
3763
|
+
local: {
|
|
3764
|
+
...rules,
|
|
3765
|
+
...held
|
|
3766
|
+
},
|
|
3767
|
+
dev: {
|
|
3768
|
+
...rules,
|
|
3769
|
+
...held
|
|
3770
|
+
},
|
|
3771
|
+
ci: {
|
|
3772
|
+
...rules,
|
|
3773
|
+
...ci
|
|
3774
|
+
}
|
|
3775
|
+
} };
|
|
3776
|
+
}
|
|
3777
|
+
/**
|
|
3627
3778
|
* What each GitHub token is meant to carry, by its `envName`, the same as the GitHub tokens table in
|
|
3628
3779
|
* `docs/src/content/docs/tokens.mdx`. This is the plugin's `tokens` declaration, read through `tokenExpectations()`;
|
|
3629
3780
|
* change it and that table together.
|
|
@@ -3662,7 +3813,7 @@ const EXPECTED = {
|
|
|
3662
3813
|
administration: "absent",
|
|
3663
3814
|
secrets: "absent"
|
|
3664
3815
|
} } },
|
|
3665
|
-
HOLOCRON_ADMIN_TOKEN:
|
|
3816
|
+
HOLOCRON_ADMIN_TOKEN: withoutInCi({
|
|
3666
3817
|
administration: "required",
|
|
3667
3818
|
secrets: "required",
|
|
3668
3819
|
environments: "required",
|
|
@@ -3670,7 +3821,7 @@ const EXPECTED = {
|
|
|
3670
3821
|
"custom-properties": "required",
|
|
3671
3822
|
"actions-variables": "required",
|
|
3672
3823
|
"org-secrets": "absent"
|
|
3673
|
-
}),
|
|
3824
|
+
}, { webhooks: "required" }, { webhooks: "absent" }),
|
|
3674
3825
|
HOLOCRON_SECRETS_TOKEN: everywhere({
|
|
3675
3826
|
"org-secrets": "required",
|
|
3676
3827
|
administration: "absent"
|
|
@@ -3686,12 +3837,12 @@ const EXPECTED = {
|
|
|
3686
3837
|
administration: "absent",
|
|
3687
3838
|
secrets: "absent"
|
|
3688
3839
|
}),
|
|
3689
|
-
HOLOCRON_ORG_TOKEN:
|
|
3840
|
+
HOLOCRON_ORG_TOKEN: withoutInCi({
|
|
3690
3841
|
administration: "required",
|
|
3691
3842
|
"org-members": "required",
|
|
3692
3843
|
"org-variables": "required",
|
|
3693
3844
|
"org-secrets": "absent"
|
|
3694
|
-
})
|
|
3845
|
+
}, { "org-webhooks": "required" }, { "org-webhooks": "absent" })
|
|
3695
3846
|
};
|
|
3696
3847
|
// src/tokens.ts
|
|
3697
3848
|
/** Adds what a layer's token must and must not be able to do (`EXPECTED`, by `envName`) to a token. */
|
|
@@ -3793,6 +3944,14 @@ const PERMISSIONS = {
|
|
|
3793
3944
|
label: "Pages",
|
|
3794
3945
|
path: "/repos/{r}/pages"
|
|
3795
3946
|
},
|
|
3947
|
+
webhooks: {
|
|
3948
|
+
label: "Webhooks",
|
|
3949
|
+
path: "/repos/{r}/hooks?per_page=1"
|
|
3950
|
+
},
|
|
3951
|
+
"org-webhooks": {
|
|
3952
|
+
label: "Organization: Webhooks",
|
|
3953
|
+
path: "/orgs/{o}/hooks?per_page=1"
|
|
3954
|
+
},
|
|
3796
3955
|
"org-members": {
|
|
3797
3956
|
label: "Organization: Members",
|
|
3798
3957
|
path: "/orgs/{o}/members?per_page=1"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/holocron-plugin-github",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.517",
|
|
4
4
|
"description": "Holocron plugin for GitHub. Implements source, ci, secrets, environments, and issues capabilities against the GitHub REST API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ci",
|
|
@@ -42,23 +42,23 @@
|
|
|
42
42
|
"globals": "^17.14.0",
|
|
43
43
|
"tsdown": "^0.23.7",
|
|
44
44
|
"tsx": "4.23.15",
|
|
45
|
-
"typescript": "^
|
|
45
|
+
"typescript": "^6.0.3",
|
|
46
46
|
"vitest": "^5.1.0",
|
|
47
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
48
|
-
"@theholocron/eslint-config": "^8.9.0-alpha.
|
|
49
|
-
"@theholocron/github-client": "^1.58.0-alpha.49",
|
|
50
|
-
"@theholocron/http-client": "^1.58.0-alpha.49",
|
|
51
|
-
"@theholocron/misc-utils": "^1.17.0-alpha.5",
|
|
47
|
+
"@theholocron/cli": "5.0.0-alpha.517",
|
|
48
|
+
"@theholocron/eslint-config": "^8.9.0-alpha.22",
|
|
52
49
|
"@theholocron/fs-utils": "^1.17.0-alpha.5",
|
|
53
|
-
"@theholocron/
|
|
54
|
-
"@theholocron/
|
|
55
|
-
"@theholocron/
|
|
50
|
+
"@theholocron/github-client": "^1.58.0-alpha.51",
|
|
51
|
+
"@theholocron/http-client": "^1.58.0-alpha.51",
|
|
52
|
+
"@theholocron/tsconfig": "^8.9.0-alpha.22",
|
|
53
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.22",
|
|
54
|
+
"@theholocron/vitest-config": "^8.9.0-alpha.22",
|
|
55
|
+
"@theholocron/misc-utils": "^1.17.0-alpha.5"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@theholocron/fs-utils": "^1.16.0",
|
|
59
59
|
"@theholocron/github-client": "^1.58.0",
|
|
60
60
|
"@theholocron/misc-utils": "^1.16.0",
|
|
61
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
61
|
+
"@theholocron/cli": "5.0.0-alpha.517"
|
|
62
62
|
},
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": ">=22"
|