@theholocron/holocron-plugin-github 5.0.0-alpha.274 → 5.0.0-alpha.275

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 CHANGED
@@ -1,4 +1,4 @@
1
- import { Auth, AuthError, Ci, CiRun, CiRunFilter, Environment, Environments, Issue, IssueSearchFilter, Issues, LabelDef, LifecycleResult, LifecycleSlot, PagesConfig, PluginToken, PullRequest, RepoRef, RepoSettings, ResolveTokenInput, Ruleset, SecretScope, Secrets, Source, SourceBranch, SourceFile, SourceTeamMember, TeamEntry, TeamEntry as TeamEntry$1, TeamPermission, TrackerDoctorReport, TrackerUser, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess, createFeatureResolver } from "@theholocron/cli";
1
+ import { Auth, AuthError, Ci, CiRun, CiRunFilter, Environment, Environments, Issue, IssueSearchFilter, Issues, LabelDef, LifecycleResult, LifecycleSlot, PagesConfig, PluginToken, PullRequest, RepoRef, RepoSettings, ResolveTokenInput, Ruleset, SecretScope, Secrets, Source, SourceBranch, SourceFile, SourceRepoInfo, SourceRulesetDetail, SourceSecurity, SourceTeamMember, TeamEntry, TeamEntry as TeamEntry$1, TeamPermission, TeamPermission as TeamPermission$1, TrackerDoctorReport, TrackerUser, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess, createFeatureResolver } from "@theholocron/cli";
2
2
  import { GitHubClient, GitHubClientOptions, createGitHubClient } from "@theholocron/github-client";
3
3
  export declare const resolveReadToken: import("@theholocron/cli").FeatureResolver;
4
4
  export declare const resolveIssuesToken: import("@theholocron/cli").FeatureResolver;
@@ -184,6 +184,15 @@ export declare class GitHubSource implements Source {
184
184
  value: string;
185
185
  visibility: "all" | "private" | "selected";
186
186
  }>>;
187
+ getRepoInfo(): Promise<SourceRepoInfo>;
188
+ getProperties(): Promise<Record<string, string | string[]>>;
189
+ listLabels(): Promise<LabelDef[]>;
190
+ listTeamAccess(): Promise<Array<{
191
+ slug: string;
192
+ permission: TeamPermission$1;
193
+ }>>;
194
+ getRulesetDetail(id: number): Promise<SourceRulesetDetail>;
195
+ getSecurity(): Promise<SourceSecurity>;
187
196
  syncDescription(description: string): Promise<string>;
188
197
  syncHomepage(homepage: string): Promise<string>;
189
198
  getPullRequest(number: number, repo?: string): Promise<PullRequest>;
package/dist/index.mjs CHANGED
@@ -565,6 +565,80 @@ async function syncProperties(client, repo, values) {
565
565
  }
566
566
  return `${Object.keys(values).length} properties set`;
567
567
  }
568
+ // src/capabilities/read-repo.ts
569
+ /** The settings `repo setup` writes, which `GET /repos/{repo}` reports under the same names. */
570
+ const SETTING_KEYS = [
571
+ "allow_squash_merge",
572
+ "allow_merge_commit",
573
+ "allow_rebase_merge",
574
+ "allow_auto_merge",
575
+ "allow_update_branch",
576
+ "delete_branch_on_merge",
577
+ "has_issues",
578
+ "has_discussions",
579
+ "has_projects",
580
+ "has_wiki"
581
+ ];
582
+ /** The repository's description, homepage, default branch, topics and settings, from one read. */
583
+ async function readRepoInfo(client, repo) {
584
+ const data = await client.repos.getRepo(repo);
585
+ const settings = { default_branch: data.default_branch };
586
+ for (const key of SETTING_KEYS) {
587
+ const value = data[key];
588
+ if (value !== void 0) settings[key] = value;
589
+ }
590
+ return {
591
+ description: data.description ?? null,
592
+ homepage: data.homepage ?? null,
593
+ defaultBranch: data.default_branch,
594
+ topics: data.topics ?? [],
595
+ settings
596
+ };
597
+ }
598
+ /** A ruleset reduced to what `repo setup` writes: its enforcement, rule types and required status checks. */
599
+ function toRulesetDetail(data) {
600
+ const rules = data.rules ?? [];
601
+ const checks = rules.find((r) => r.type === "required_status_checks")?.parameters?.required_status_checks;
602
+ return {
603
+ name: data.name,
604
+ enforcement: data.enforcement,
605
+ ruleTypes: rules.map((r) => r.type),
606
+ requiredChecks: Array.isArray(checks) ? checks.map((c) => String(c.context)) : []
607
+ };
608
+ }
609
+ /** The value, or `undefined` when GitHub refuses the read (permission, plan, feature absent). Other errors still throw. */
610
+ async function readable(read) {
611
+ try {
612
+ return await read();
613
+ } catch (err) {
614
+ if (err instanceof ProviderApiError$1) return void 0;
615
+ throw err;
616
+ }
617
+ }
618
+ /** Which security features are on. One GitHub refuses to report is left out, not reported as off. */
619
+ async function readSecurity(client, repo) {
620
+ const [data, alerts, fixes, reporting, codeScanning] = await Promise.all([
621
+ readable(() => client.repos.getRepo(repo)),
622
+ readable(() => client.security.vulnerabilityAlertsEnabled(repo)),
623
+ readable(() => client.security.automatedSecurityFixesEnabled(repo)),
624
+ readable(() => client.security.privateVulnerabilityReportingEnabled(repo)),
625
+ readable(() => client.security.codeScanningDefaultSetupState(repo))
626
+ ]);
627
+ const analysis = data?.security_and_analysis;
628
+ const on = (feature) => {
629
+ const status = analysis?.[feature]?.status;
630
+ return status === void 0 ? void 0 : status === "enabled";
631
+ };
632
+ const found = {
633
+ vulnerabilityAlerts: alerts,
634
+ automatedSecurityFixes: fixes,
635
+ secretScanning: on("secret_scanning"),
636
+ secretScanningPushProtection: on("secret_scanning_push_protection"),
637
+ privateVulnerabilityReporting: reporting,
638
+ codeScanningDefaultSetup: codeScanning === void 0 ? void 0 : codeScanning === "configured"
639
+ };
640
+ return Object.fromEntries(Object.entries(found).filter(([, v]) => v !== void 0));
641
+ }
568
642
  // src/capabilities/teams.ts
569
643
  function normalizeTeamEntry(entry) {
570
644
  if (typeof entry === "string") return {
@@ -857,6 +931,32 @@ var GitHubSource = class {
857
931
  visibility: v.visibility ?? "all"
858
932
  }]));
859
933
  }
934
+ async getRepoInfo() {
935
+ return readRepoInfo(this.client, this.repo);
936
+ }
937
+ async getProperties() {
938
+ const found = await this.client.properties.getValues(this.repo);
939
+ return Object.fromEntries(found.flatMap((p) => p.value === null ? [] : [[p.property_name, p.value]]));
940
+ }
941
+ async listLabels() {
942
+ return (await this.client.labels.listLabels(this.repo)).map((l) => ({
943
+ name: l.name,
944
+ color: l.color,
945
+ description: l.description ?? ""
946
+ }));
947
+ }
948
+ async listTeamAccess() {
949
+ return (await (this.orgClient ?? this.client).teams.listForRepo(this.repo)).map((t) => ({
950
+ slug: t.slug,
951
+ permission: t.permission
952
+ }));
953
+ }
954
+ async getRulesetDetail(id) {
955
+ return toRulesetDetail(await this.client.rulesets.getRuleset(this.repo, id));
956
+ }
957
+ async getSecurity() {
958
+ return readSecurity(this.client, this.repo);
959
+ }
860
960
  async syncDescription(description) {
861
961
  await this.client.repos.updateRepo(this.repo, { description });
862
962
  return "description updated";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-github",
3
- "version": "5.0.0-alpha.274",
3
+ "version": "5.0.0-alpha.275",
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",
@@ -44,13 +44,13 @@
44
44
  "tsx": "4.23.15",
45
45
  "typescript": "^5.9.3",
46
46
  "vitest": "^5.0.5",
47
+ "@theholocron/cli": "5.0.0-alpha.275",
47
48
  "@theholocron/eslint-config": "^8.9.0-alpha.3",
48
- "@theholocron/fs-utils": "^1.16.1-alpha.1",
49
- "@theholocron/cli": "5.0.0-alpha.274",
50
- "@theholocron/http-client": "^1.58.0-alpha.2",
49
+ "@theholocron/http-client": "^1.58.0-alpha.3",
51
50
  "@theholocron/misc-utils": "^1.16.1-alpha.1",
52
- "@theholocron/github-client": "^1.58.0-alpha.2",
51
+ "@theholocron/github-client": "^1.58.0-alpha.3",
53
52
  "@theholocron/tsconfig": "^8.9.0-alpha.3",
53
+ "@theholocron/fs-utils": "^1.16.1-alpha.1",
54
54
  "@theholocron/tsdown-config": "^8.9.0-alpha.3",
55
55
  "@theholocron/vitest-config": "^8.9.0-alpha.3"
56
56
  },
@@ -58,7 +58,7 @@
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.274"
61
+ "@theholocron/cli": "5.0.0-alpha.275"
62
62
  },
63
63
  "engines": {
64
64
  "node": ">=22"