@theholocron/holocron-plugin-github 5.0.0-alpha.593 → 5.0.0-alpha.594

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
@@ -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, EnsureRelaySourceInput, EnsureRelaySourceResult, EnsureReport, Environment, Environments, ExportInfo, ImportOptions, ImportResult, InspectRelaySourceInput, Issue, IssueCreateInput, IssuePatch, IssueRecord, IssueSearchFilter, IssueSelector, IssueTypeDeclaration, IssueTypeInfo, IssueUpdateResult, Issues, LabelDef, LifecycleResult, LifecycleSlot, MoveReport, PagesConfig, PluginToken, Projects, PullRequest, PullRequestChecks, PullRequestInput, PullRequestPatch, PullRequestResult, RelaySourceState, RepoRef, RepoSettings, ResolveTokenInput, Ruleset, SecretAccess, SecretScope, Secrets, Source, SourceBranch, SourceCheckRun, SourceCheckRunWrite, SourceCommitStatus, SourceFile, SourceRepoInfo, SourceRequiredChecks, 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, IssueTypeDeclaration, IssueTypeInfo, IssueUpdateResult, Issues, LabelDef, LifecycleResult, LifecycleSlot, MoveReport, PagesConfig, PluginToken, Projects, PullRequest, PullRequestChecks, PullRequestInput, PullRequestPatch, PullRequestResult, PullRequestState, RelaySourceState, RepoRef, RepoSettings, ResolveTokenInput, Ruleset, SecretAccess, SecretScope, Secrets, Source, SourceBranch, SourceCheckRun, SourceCheckRunWrite, SourceCommitStatus, SourceFile, SourceRepoInfo, SourceRequiredChecks, 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;
@@ -441,6 +441,7 @@ export declare class GitHubSource implements Source {
441
441
  private get pullClient();
442
442
  getPullRequest(number: number, repo?: string): Promise<PullRequest>;
443
443
  listPullRequests(state: "open" | "closed", repo?: string): Promise<PullRequest[]>;
444
+ readPullRequestState(number: number, repo?: string, required?: SourceRequiredChecks): Promise<PullRequestState | undefined>;
444
445
  listBranches(repo?: string): Promise<SourceBranch[]>;
445
446
  deleteBranch(name: string, repo?: string): Promise<void>;
446
447
  listPullRequestCommits(number: number, repo?: string): Promise<string[]>;
package/dist/index.mjs CHANGED
@@ -2469,12 +2469,10 @@ function aggregateState(runs) {
2469
2469
  return "none";
2470
2470
  }
2471
2471
  /**
2472
- * The aggregate check of a pull request's newest commit and the checks that failed on it, read now (never cached, so a
2473
- * caller that polls sees each change). The newest run of each name counts, so a job that failed and was re-run to green
2474
- * is not listed.
2472
+ * The aggregate check of a commit and the checks that failed on it, read now (never cached, so a caller that polls sees
2473
+ * each change). The newest run of each name counts, so a job that failed and was re-run to green is not listed.
2475
2474
  */
2476
- async function readPullRequestChecks(client, repo, number) {
2477
- const sha = (await client.pulls.getPullRequest(repo, number)).head.sha;
2475
+ async function aggregateChecksFor(client, repo, sha) {
2478
2476
  const runs = await client.checks.listCheckRunsForRef(repo, sha);
2479
2477
  const newest = /* @__PURE__ */ new Map();
2480
2478
  for (const run of [...runs].sort(newestFirst)) if (!newest.has(run.name)) newest.set(run.name, run);
@@ -2488,13 +2486,12 @@ async function readPullRequestChecks(client, repo, number) {
2488
2486
  };
2489
2487
  }
2490
2488
  /**
2491
- * Whether the required checks of a pull request's newest commit are green, for a repo with no `ci / Required checks`
2492
- * aggregate (`ci.aggregate: "none"`). Reads the commit's check runs and, only when a status context is required, its
2493
- * commit statuses, then lets the CLI's `requiredChecksVerdict()` decide: the rule lives there and nowhere else. Read
2494
- * now, never cached. Optional checks that failed are listed with `required: false` and never change the state.
2489
+ * Whether the required checks of a commit are green, for a repo with no `ci / Required checks` aggregate
2490
+ * (`ci.aggregate: "none"`). Reads the commit's check runs and, only when a status context is required, its commit
2491
+ * statuses, then lets the CLI's `requiredChecksVerdict()` decide: the rule lives there and nowhere else. Read now, never
2492
+ * cached. Optional checks that failed are listed with `required: false` and never change the state.
2495
2493
  */
2496
- async function readRequiredPullRequestChecks(client, repo, number, required) {
2497
- const sha = (await client.pulls.getPullRequest(repo, number)).head.sha;
2494
+ async function requiredChecksFor(client, repo, sha, required) {
2498
2495
  const checkRuns = await readCheckRuns(client, repo, sha);
2499
2496
  const commitStatuses = required.statuses.length > 0 ? await readCommitStatuses(client, repo, sha) : [];
2500
2497
  const verdict = requiredChecksVerdict({
@@ -2515,6 +2512,70 @@ async function readRequiredPullRequestChecks(client, repo, number, required) {
2515
2512
  ...verdict.pending ? { pending: verdict.pending } : {}
2516
2513
  };
2517
2514
  }
2515
+ /** The checks of a commit: the aggregate's verdict, or with `required` the required checks'. */
2516
+ function checksForSha(client, repo, sha, required) {
2517
+ return required ? requiredChecksFor(client, repo, sha, required) : aggregateChecksFor(client, repo, sha);
2518
+ }
2519
+ /** The aggregate check of a pull request's newest commit and the checks that failed on it, read now. */
2520
+ async function readPullRequestChecks(client, repo, number) {
2521
+ return aggregateChecksFor(client, repo, (await client.pulls.getPullRequest(repo, number)).head.sha);
2522
+ }
2523
+ /** Whether the required checks of a pull request's newest commit are green, for a repo with no aggregate. */
2524
+ async function readRequiredPullRequestChecks(client, repo, number, required) {
2525
+ return requiredChecksFor(client, repo, (await client.pulls.getPullRequest(repo, number)).head.sha, required);
2526
+ }
2527
+ // src/capabilities/pull-request-state.ts
2528
+ /** The reviews that count: each reviewer's last approval, change request or dismissal (a comment changes nothing). */
2529
+ function reviewState(reviews, requested) {
2530
+ const latest = /* @__PURE__ */ new Map();
2531
+ for (const r of reviews) if (r.user && (r.state === "APPROVED" || r.state === "CHANGES_REQUESTED" || r.state === "DISMISSED")) latest.set(r.user.login, r.state);
2532
+ const states = [...latest.values()];
2533
+ if (states.includes("CHANGES_REQUESTED")) return "changes_requested";
2534
+ if (states.includes("APPROVED")) return "approved";
2535
+ return requested.length > 0 ? "review_required" : "none";
2536
+ }
2537
+ const CI = {
2538
+ success: "passing",
2539
+ failure: "failing",
2540
+ pending: "pending",
2541
+ none: "none"
2542
+ };
2543
+ /**
2544
+ * One pull request as the PR forum's post is rendered from it: the pull request, and for an open one its reviews and the
2545
+ * checks of its head commit (a finished pull request's tag needs neither, so they are not read). `undefined` for a pull
2546
+ * request that does not exist. Three reads for an open pull request, one for a closed one.
2547
+ */
2548
+ async function readPullRequestState(client, repo, number, required) {
2549
+ let pull;
2550
+ try {
2551
+ pull = await client.pulls.getPullRequest(repo, number);
2552
+ } catch (err) {
2553
+ if (err instanceof ProviderApiError && err.status === 404) return void 0;
2554
+ throw err;
2555
+ }
2556
+ const closed = pull.state === "closed";
2557
+ const requestedReviewers = (pull.requested_reviewers ?? []).map((r) => r.login);
2558
+ const [reviews, checks] = closed ? [[], void 0] : await Promise.all([client.pulls.listReviews(repo, number), checksForSha(client, repo, pull.head.sha, required)]);
2559
+ return {
2560
+ repo,
2561
+ number,
2562
+ title: pull.title,
2563
+ body: pull.body ?? "",
2564
+ url: pull.html_url,
2565
+ author: pull.user?.login ?? "unknown",
2566
+ authorIsBot: pull.user?.type === "Bot",
2567
+ draft: pull.draft ?? false,
2568
+ merged: pull.merged_at !== null,
2569
+ closed,
2570
+ createdAt: pull.created_at ?? (/* @__PURE__ */ new Date(0)).toISOString(),
2571
+ ...pull.closed_at ? { closedAt: pull.closed_at } : {},
2572
+ base: pull.base?.ref ?? "",
2573
+ requestedReviewers,
2574
+ review: reviewState(reviews, requestedReviewers),
2575
+ ci: checks ? CI[checks.state] : "none",
2576
+ mergeable: pull.mergeable_state === "dirty" ? "conflicting" : pull.mergeable_state === void 0 || pull.mergeable_state === "unknown" ? "unknown" : "clean"
2577
+ };
2578
+ }
2518
2579
  // src/capabilities/pull-requests.ts
2519
2580
  /** The GitHub pull request as the neutral {@link PullRequest}. */
2520
2581
  function toPullRequest(raw) {
@@ -3226,6 +3287,9 @@ var GitHubSource = class {
3226
3287
  async listPullRequests(state, repo) {
3227
3288
  return (await this.pullClient.pulls.listPullRequests(repo ?? this.repo, state)).map(toPullRequest);
3228
3289
  }
3290
+ async readPullRequestState(number, repo, required) {
3291
+ return readPullRequestState(this.pullClient, repo ?? this.repo, number, required);
3292
+ }
3229
3293
  async listBranches(repo) {
3230
3294
  return (await this.client.branches.listBranches(repo ?? this.repo)).map((b) => ({
3231
3295
  name: b.name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-github",
3
- "version": "5.0.0-alpha.593",
3
+ "version": "5.0.0-alpha.594",
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,11 +44,11 @@
44
44
  "tsx": "4.23.15",
45
45
  "typescript": "^6.0.3",
46
46
  "vitest": "^5.1.2",
47
- "@theholocron/cli": "5.0.0-alpha.593",
47
+ "@theholocron/cli": "5.0.0-alpha.594",
48
48
  "@theholocron/eslint-config": "^8.9.0-alpha.24",
49
49
  "@theholocron/fs-utils": "^1.17.0-alpha.9",
50
- "@theholocron/github-client": "^1.58.0-alpha.75",
51
- "@theholocron/http-client": "^1.58.0-alpha.75",
50
+ "@theholocron/github-client": "^1.58.0-alpha.76",
51
+ "@theholocron/http-client": "^1.58.0-alpha.76",
52
52
  "@theholocron/misc-utils": "^1.17.0-alpha.9",
53
53
  "@theholocron/tsconfig": "^8.9.0-alpha.24",
54
54
  "@theholocron/tsdown-config": "^8.9.0-alpha.24",
@@ -58,7 +58,7 @@
58
58
  "@theholocron/fs-utils": "^1.16.0",
59
59
  "@theholocron/github-client": "^1.58.0-alpha.0",
60
60
  "@theholocron/misc-utils": "^1.16.0",
61
- "@theholocron/cli": "5.0.0-alpha.593"
61
+ "@theholocron/cli": "5.0.0-alpha.594"
62
62
  },
63
63
  "engines": {
64
64
  "node": ">=22"