@theholocron/holocron-plugin-github 5.0.0-alpha.491 → 5.0.0-alpha.492

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
@@ -194,8 +194,10 @@ export declare class GitHubProjects implements Projects {
194
194
  private createView;
195
195
  private updateView;
196
196
  /**
197
- * The board's issues and pull requests with their status, whether they are open and their open blockers; an issue also
198
- * carries the pull requests that close it, each with the aggregate `ci / Required checks` state of its head commit.
197
+ * The board's issues and pull requests with their status, whether they are open and their open blockers. A second step
198
+ * then reads, one small query per issue, the pull requests that close each open issue a rule could still move (it has a
199
+ * status that is not `done` or `blocked` and no open blocker), each with the aggregate `ci / Required checks` state of
200
+ * its head commit. An issue whose read fails keeps no `pullRequests` and carries `pullRequestsProblem` instead.
199
201
  */
200
202
  items(_owner: string, board: BoardSummary, template: BoardTemplate): Promise<BoardItem[]>;
201
203
  /** Puts an item in a status; `transitioned` is false when it already is there. */
package/dist/index.mjs CHANGED
@@ -843,13 +843,18 @@ function parseIssueNumber(key, owner, repoName) {
843
843
  if (!/^\d+$/.test(num)) throw new Error(`Invalid GitHub issue key "${key}" — expected #N or N.`);
844
844
  return parseInt(num, 10);
845
845
  }
846
- /** The GraphQL selection that reads an issue's closing pull requests and the aggregate check on each head commit. */
847
- const CLOSING_PULL_REQUESTS = `closedByPullRequestsReferences(first: 5, includeClosedPrs: true) { nodes {
848
- number state isDraft repository { nameWithOwner }
849
- commits(last: 1) { nodes { commit { checkSuites(first: 50) { nodes {
850
- checkRuns(first: 5, filterBy: { checkName: "ci / Required checks" }) { nodes { databaseId status conclusion startedAt } }
851
- } } } } }
852
- } }`;
846
+ /**
847
+ * One issue's closing pull requests and the aggregate check on each one's newest commit. It is its own small query,
848
+ * never part of the board's items query: nested under `items(first: 100)` it multiplies past GitHub's resource limit.
849
+ */
850
+ const CLOSING_QUERY = `query($id: ID!) { node(id: $id) { ... on Issue {
851
+ closedByPullRequestsReferences(first: 5, includeClosedPrs: true) { nodes {
852
+ number state isDraft repository { nameWithOwner }
853
+ commits(last: 1) { nodes { commit { checkSuites(first: 30) { nodes {
854
+ checkRuns(first: 5, filterBy: { checkName: "ci / Required checks" }) { nodes { databaseId status conclusion startedAt } }
855
+ } } } } }
856
+ } }
857
+ } } }`;
853
858
  const FAILED = /* @__PURE__ */ new Set([
854
859
  "FAILURE",
855
860
  "TIMED_OUT",
@@ -884,6 +889,28 @@ function toBoardPullRequests(nodes, keyOf) {
884
889
  };
885
890
  });
886
891
  }
892
+ /**
893
+ * Reads the closing pull requests of each issue (by node id) with one small query per issue, a few at a time. A query
894
+ * that fails is that issue's `problem` and nothing else: the others are read, and the caller leaves the failed one's
895
+ * pull-request rules unapplied.
896
+ */
897
+ async function readClosingPullRequests(graphql, contentIds, keyOf) {
898
+ const results = /* @__PURE__ */ new Map();
899
+ let next = 0;
900
+ const worker = async () => {
901
+ for (let i = next++; i < contentIds.length; i = next++) {
902
+ const id = contentIds[i];
903
+ try {
904
+ const nodes = (await graphql.query(CLOSING_QUERY, { id })).node?.closedByPullRequestsReferences?.nodes;
905
+ results.set(id, nodes ? { pullRequests: toBoardPullRequests(nodes, keyOf) } : { problem: "GitHub returned no pull request list" });
906
+ } catch (err) {
907
+ results.set(id, { problem: err instanceof Error ? err.message : String(err) });
908
+ }
909
+ }
910
+ };
911
+ await Promise.all(Array.from({ length: Math.min(4, contentIds.length) }, worker));
912
+ return results;
913
+ }
887
914
  // src/capabilities/projects.ts
888
915
  /** The name of the single select field that holds an item's status. */
889
916
  const STATUS_FIELD = "Status";
@@ -919,7 +946,7 @@ const ITEMS_QUERY = `query($id: ID!, $after: String) { node(id: $id) { ... on Pr
919
946
  fieldValues(first: 30) { nodes { ... on ProjectV2ItemFieldSingleSelectValue { name field { ... on ProjectV2FieldCommon { name } } } } }
920
947
  content {
921
948
  __typename
922
- ... on Issue { id number title state repository { nameWithOwner } blockedBy(first: 50) { nodes { number state repository { nameWithOwner } } } ${CLOSING_PULL_REQUESTS} }
949
+ ... on Issue { id number title state repository { nameWithOwner } blockedBy(first: 50) { nodes { number state repository { nameWithOwner } } } }
923
950
  ... on PullRequest { id number title state repository { nameWithOwner } }
924
951
  }
925
952
  }
@@ -1208,12 +1235,22 @@ var GitHubProjects = class {
1208
1235
  });
1209
1236
  }
1210
1237
  /**
1211
- * The board's issues and pull requests with their status, whether they are open and their open blockers; an issue also
1212
- * carries the pull requests that close it, each with the aggregate `ci / Required checks` state of its head commit.
1238
+ * The board's issues and pull requests with their status, whether they are open and their open blockers. A second step
1239
+ * then reads, one small query per issue, the pull requests that close each open issue a rule could still move (it has a
1240
+ * status that is not `done` or `blocked` and no open blocker), each with the aggregate `ci / Required checks` state of
1241
+ * its head commit. An issue whose read fails keeps no `pullRequests` and carries `pullRequestsProblem` instead.
1213
1242
  */
1214
1243
  async items(_owner, board, template) {
1215
1244
  const categories = new Map(template.statuses.map((s) => [s.name, s.category]));
1216
- return (await this.fetchItems(board.id)).map((i) => {
1245
+ const raw = await this.fetchItems(board.id);
1246
+ const wanted = raw.filter((i) => {
1247
+ const status = i.values[STATUS_FIELD];
1248
+ const category = status ? categories.get(status) : void 0;
1249
+ return i.issue && i.open && status !== void 0 && i.blockers.length === 0 && category !== "done" && category !== "blocked";
1250
+ });
1251
+ const closing = await readClosingPullRequests(this.graphql, wanted.map((i) => i.contentId), (r, n) => this.keyOf(r, n));
1252
+ return raw.map((i) => {
1253
+ const read = closing.get(i.contentId);
1217
1254
  const status = i.values[STATUS_FIELD];
1218
1255
  const category = status ? categories.get(status) : void 0;
1219
1256
  const priority = priorityOf(i.values[PRIORITY_FIELD]);
@@ -1225,7 +1262,8 @@ var GitHubProjects = class {
1225
1262
  ...category ? { category } : {},
1226
1263
  blockedBy: i.blockers.map((b) => this.keyOf(b.repo, b.number)),
1227
1264
  ...priority ? { priority } : {},
1228
- ...i.closing ? { pullRequests: toBoardPullRequests(i.closing, (r, n) => this.keyOf(r, n)) } : {}
1265
+ ...read && "pullRequests" in read ? { pullRequests: read.pullRequests } : {},
1266
+ ...read && "problem" in read ? { pullRequestsProblem: read.problem } : {}
1229
1267
  };
1230
1268
  });
1231
1269
  }
@@ -1326,6 +1364,7 @@ var GitHubProjects = class {
1326
1364
  number: ref.number,
1327
1365
  title: "",
1328
1366
  open: true,
1367
+ issue: false,
1329
1368
  values: {},
1330
1369
  blockers: []
1331
1370
  };
@@ -1441,12 +1480,12 @@ var GitHubProjects = class {
1441
1480
  number: c.number,
1442
1481
  title: c.title,
1443
1482
  open: c.state === "OPEN",
1483
+ issue: c.__typename === "Issue",
1444
1484
  values,
1445
1485
  blockers: (c.blockedBy?.nodes ?? []).filter((b) => b.state === "OPEN").map((b) => ({
1446
1486
  repo: b.repository.nameWithOwner,
1447
1487
  number: b.number
1448
- })),
1449
- ...c.closedByPullRequestsReferences ? { closing: c.closedByPullRequestsReferences.nodes } : {}
1488
+ }))
1450
1489
  });
1451
1490
  }
1452
1491
  if (!page.pageInfo.hasNextPage) return items;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-github",
3
- "version": "5.0.0-alpha.491",
3
+ "version": "5.0.0-alpha.492",
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,21 +44,21 @@
44
44
  "tsx": "4.23.15",
45
45
  "typescript": "^5.9.3",
46
46
  "vitest": "^5.1.0",
47
+ "@theholocron/cli": "5.0.0-alpha.492",
47
48
  "@theholocron/eslint-config": "^8.9.0-alpha.21",
48
49
  "@theholocron/fs-utils": "^1.17.0-alpha.5",
49
- "@theholocron/github-client": "^1.58.0-alpha.42",
50
+ "@theholocron/github-client": "^1.58.0-alpha.44",
50
51
  "@theholocron/misc-utils": "^1.17.0-alpha.5",
51
- "@theholocron/cli": "5.0.0-alpha.491",
52
- "@theholocron/http-client": "^1.58.0-alpha.42",
52
+ "@theholocron/http-client": "^1.58.0-alpha.44",
53
53
  "@theholocron/tsconfig": "^8.9.0-alpha.21",
54
- "@theholocron/vitest-config": "^8.9.0-alpha.21",
55
- "@theholocron/tsdown-config": "^8.9.0-alpha.21"
54
+ "@theholocron/tsdown-config": "^8.9.0-alpha.21",
55
+ "@theholocron/vitest-config": "^8.9.0-alpha.21"
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.491"
61
+ "@theholocron/cli": "5.0.0-alpha.492"
62
62
  },
63
63
  "engines": {
64
64
  "node": ">=22"