@theholocron/holocron-plugin-github 5.0.0-alpha.446 → 5.0.0-alpha.453

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,3 +1,12 @@
1
+ /**
2
+ * `@theholocron/holocron-plugin-github` — entrypoint.
3
+ *
4
+ * Holocron loads a plugin by resolving its package and reading the
5
+ * default export, which is a `Plugin` object declaring which
6
+ * capabilities it implements. The factory for each capability
7
+ * receives plugin-level options from `holocron.config.json` and
8
+ * returns the bound implementation.
9
+ */
1
10
  import { AddedItem, Auth, AuthError, BoardItem, BoardItemInput, BoardState, BoardSummary, BoardTemplate, Ci, CiRun, CiRunFilter, EnsureReport, Environment, Environments, ExportInfo, ImportOptions, ImportResult, Issue, IssueRecord, IssueSearchFilter, IssueSelector, Issues, LabelDef, LifecycleResult, LifecycleSlot, MoveReport, PagesConfig, PluginToken, Projects, PullRequest, 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";
2
11
  import { GitHubClient, GitHubClientOptions, GraphQLClient, createGitHubClient } from "@theholocron/github-client";
3
12
  /** Resolves the token for read-only GitHub access (`HOLOCRON_READ_TOKEN`, keyring key `github.read`). */
package/dist/index.mjs CHANGED
@@ -151,6 +151,70 @@ var GitHubEnvironments = class {
151
151
  }));
152
152
  }
153
153
  };
154
+ // src/capabilities/issue-priority.ts
155
+ const OPTION_NAMES = {
156
+ urgent: "Urgent",
157
+ high: "High",
158
+ medium: "Medium",
159
+ low: "Low"
160
+ };
161
+ /** Whether GitHub refused for a reason about access or setup, which a run reports and goes on from. */
162
+ function refusal(err) {
163
+ if (!(err instanceof ProviderApiError)) return void 0;
164
+ if (err.status === void 0 || ![
165
+ 401,
166
+ 403,
167
+ 404,
168
+ 422
169
+ ].includes(err.status)) return void 0;
170
+ if (/rate limit/i.test(`${err.message} ${String(err.details)}`)) return void 0;
171
+ return `GitHub refused: ${err.status}`;
172
+ }
173
+ function createPrioritySetter(client, repo) {
174
+ const org = repo.split("/")[0];
175
+ let lookup;
176
+ const findField = () => lookup ??= client.issueFields.list(org).then((fields) => {
177
+ const field = fields.find((f) => f.name === "Priority" && f.data_type === "single_select");
178
+ return field ? { field } : { note: `priority field (${org} has no Priority issue field)` };
179
+ }, (err) => {
180
+ const why = refusal(err);
181
+ if (why === void 0) throw err;
182
+ return { note: `priority field (${why})` };
183
+ });
184
+ return { async set(number, level, flags = {}) {
185
+ if (!level || level === "none") return { changed: false };
186
+ const found = await findField();
187
+ if ("note" in found) return {
188
+ changed: false,
189
+ note: found.note
190
+ };
191
+ const { field } = found;
192
+ const optionName = OPTION_NAMES[level];
193
+ const option = field.options?.find((o) => o.name.toLowerCase() === optionName.toLowerCase());
194
+ if (!option) return {
195
+ changed: false,
196
+ note: `priority field (no "${optionName}" option)`
197
+ };
198
+ try {
199
+ const current = flags.isNew ? void 0 : (await client.issueFields.values(repo, number)).find((v) => v.issue_field_id === field.id);
200
+ if ((current ? current.single_select_option?.name ?? String(current.value) : void 0)?.toLowerCase() === option.name.toLowerCase()) return { changed: false };
201
+ if (flags.dryRun) return { changed: true };
202
+ if (current) await client.issueFields.deleteValue(repo, number, field.id);
203
+ await client.issueFields.addValues(repo, number, [{
204
+ field_id: field.id,
205
+ value: option.name
206
+ }]);
207
+ return { changed: true };
208
+ } catch (err) {
209
+ const why = refusal(err);
210
+ if (why === void 0) throw err;
211
+ return {
212
+ changed: false,
213
+ note: `priority field (${why})`
214
+ };
215
+ }
216
+ } };
217
+ }
154
218
  // src/capabilities/issues-migration.ts
155
219
  /**
156
220
  * Export and import of GitHub issues for `holocron migrate`.
@@ -162,6 +226,7 @@ var GitHubEnvironments = class {
162
226
  * author go in the text;
163
227
  * - an import does not set parent or blocked-by links (they need GraphQL node ids of issues made in the same run);
164
228
  * - an assignee is not mapped (a Linear user is not a GitHub login).
229
+ * - the organization's `Priority` issue field is set from the priority (`issue-priority.ts`), beside the label.
165
230
  * A migrated issue ends with `<!-- holocron:migrated-from <url> -->`, which is how a second run finds it.
166
231
  */
167
232
  const MARKER = /<!-- holocron:migrated-from (\S+) -->/;
@@ -300,6 +365,7 @@ async function importIssues(client, repo, records, options = {}) {
300
365
  const url = issue.body ? MARKER.exec(issue.body)?.[1] : void 0;
301
366
  if (url) existing.set(url, issue.number);
302
367
  }
368
+ const priority = createPrioritySetter(client, repo);
303
369
  const results = [];
304
370
  const tick = () => reportProgress(options.onProgress, results.length, records.length);
305
371
  for (const record of records) {
@@ -325,6 +391,8 @@ async function importIssues(client, repo, records, options = {}) {
325
391
  continue;
326
392
  }
327
393
  const number = await createFromRecord(client, repo, record, options);
394
+ const field = await priority.set(number, record.priority, { isNew: true });
395
+ if (field.note) dropped.push(field.note);
328
396
  results.push({
329
397
  source: record.key,
330
398
  key: `#${number}`,
@@ -338,7 +406,7 @@ async function importIssues(client, repo, records, options = {}) {
338
406
  /** What GitHub cannot hold of this record, for the report. */
339
407
  function droppedFor(record) {
340
408
  const dropped = ["createdAt (GitHub sets it; the original date is in the text)"];
341
- if (record.assignee) dropped.push("assignee (not mapped)");
409
+ if (record.assignee && !record.assignee.login) dropped.push("assignee (not mapped)");
342
410
  if (record.parent) dropped.push("parent (not set on GitHub)");
343
411
  if (record.blockedBy.length > 0) dropped.push("blockedBy (not set on GitHub)");
344
412
  return dropped;
@@ -360,7 +428,8 @@ async function createFromRecord(client, repo, record, options) {
360
428
  title: record.title,
361
429
  body: withProvenance(record),
362
430
  ...labels.length > 0 ? { labels } : {},
363
- ...milestone !== void 0 ? { milestone } : {}
431
+ ...milestone !== void 0 ? { milestone } : {},
432
+ ...record.assignee?.login ? { assignees: [record.assignee.login] } : {}
364
433
  });
365
434
  for (const comment of record.comments) await client.issues.createComment(repo, created.number, renderComment(comment));
366
435
  if (record.closed) await client.issues.updateIssue(repo, created.number, {
@@ -412,10 +481,11 @@ async function syncIssues(client, repo, records, options = {}) {
412
481
  const url = issue.body ? MARKER.exec(issue.body)?.[1] : void 0;
413
482
  if (url) existing.set(url, issue);
414
483
  }
484
+ const priority = createPrioritySetter(client, repo);
415
485
  const results = [];
416
486
  for (const record of records) try {
417
487
  const found = existing.get(record.url);
418
- results.push(found ? await update(client, repo, found, record, options) : await create(client, repo, record, options));
488
+ results.push(found ? await update(client, repo, found, record, options, priority) : await create(client, repo, record, options, priority));
419
489
  reportProgress(options.onProgress, results.length, records.length);
420
490
  } catch (err) {
421
491
  if (isRateLimited(err)) return results;
@@ -423,7 +493,7 @@ async function syncIssues(client, repo, records, options = {}) {
423
493
  }
424
494
  return results;
425
495
  }
426
- async function create(client, repo, record, options) {
496
+ async function create(client, repo, record, options, priority) {
427
497
  const dropped = droppedFor(record);
428
498
  if (options.dryRun) return {
429
499
  source: record.key,
@@ -433,6 +503,8 @@ async function create(client, repo, record, options) {
433
503
  dropped
434
504
  };
435
505
  const number = await createFromRecord(client, repo, record, options);
506
+ const field = await priority.set(number, record.priority, { isNew: true });
507
+ if (field.note) dropped.push(field.note);
436
508
  return {
437
509
  source: record.key,
438
510
  key: `#${number}`,
@@ -442,7 +514,7 @@ async function create(client, repo, record, options) {
442
514
  dropped
443
515
  };
444
516
  }
445
- async function update(client, repo, issue, record, options) {
517
+ async function update(client, repo, issue, record, options, priority) {
446
518
  const patch = {};
447
519
  const changes = [];
448
520
  if (issue.title !== record.title) {
@@ -465,6 +537,13 @@ async function update(client, repo, issue, record, options) {
465
537
  patch.labels = finalLabels;
466
538
  changes.push("labels");
467
539
  }
540
+ const login = record.assignee?.login;
541
+ if (login && issue.assignee?.login.toLowerCase() !== login.toLowerCase()) {
542
+ patch.assignees = [login];
543
+ changes.push("assignee");
544
+ }
545
+ const field = await priority.set(issue.number, record.priority, { dryRun: options.dryRun });
546
+ if (field.changed) changes.push("priority field");
468
547
  const comments = await client.issues.listComments(repo, issue.number);
469
548
  const seen = new Set(comments.map((c) => COMMENT_HEADER.exec(c.body)?.[1]));
470
549
  const missing = record.comments.filter((c) => !seen.has(c.createdAt));
@@ -479,7 +558,7 @@ async function update(client, repo, issue, record, options) {
479
558
  created: false,
480
559
  updated: changes.length > 0,
481
560
  changes,
482
- dropped: droppedFor(record)
561
+ dropped: [...droppedFor(record), ...field.note ? [field.note] : []]
483
562
  };
484
563
  }
485
564
  // src/capabilities/issues.ts
@@ -1639,7 +1718,7 @@ async function getOrgPropertyValues(client, repo, name) {
1639
1718
  * definition on a write, so the current one is read and sent back with the allowed values extended, in their order,
1640
1719
  * and nothing removed. A write is made only when something is missing.
1641
1720
  */
1642
- async function addOrgPropertyValues(client, repo, name, values) {
1721
+ async function addOrgPropertyValues(client, repo, name, values, viaOrgToken = true) {
1643
1722
  const org = repo.split("/")[0];
1644
1723
  const current = (await client.properties.orgSchema(org)).find((p) => p.property_name === name);
1645
1724
  if (!current) throw new Error(`the organization ${org} has no custom property "${name}"; create it first`);
@@ -1647,10 +1726,16 @@ async function addOrgPropertyValues(client, repo, name, values) {
1647
1726
  const have = new Set(current.allowed_values);
1648
1727
  const added = [...new Set(values)].filter((v) => !have.has(v));
1649
1728
  if (added.length === 0) return [];
1650
- await client.properties.setOrgProperty(org, {
1651
- ...current,
1652
- allowed_values: [...current.allowed_values, ...added]
1653
- });
1729
+ try {
1730
+ await client.properties.setOrgProperty(org, {
1731
+ ...current,
1732
+ allowed_values: [...current.allowed_values, ...added]
1733
+ });
1734
+ } catch (err) {
1735
+ if (!(err instanceof ProviderApiError$1) || err.status !== 403 && err.status !== 401) throw err;
1736
+ const token = viaOrgToken ? "the organization token (HOLOCRON_ORG_TOKEN, or the token passed with --token)" : "the admin token, because no organization token was found (set HOLOCRON_ORG_TOKEN or pass --token)";
1737
+ throw new Error(`GitHub refused to change the "${name}" definition (${err.status}): it needs the organization permission Custom properties: Read and write (admin) on ${org}, and this ran with ${token}`, { cause: err });
1738
+ }
1654
1739
  return added;
1655
1740
  }
1656
1741
  // src/capabilities/read-repo.ts
@@ -2004,7 +2089,7 @@ var GitHubSource = class {
2004
2089
  return getOrgPropertyValues(this.orgClient ?? this.client, this.repo, name);
2005
2090
  }
2006
2091
  async addOrgPropertyValues(name, values) {
2007
- return addOrgPropertyValues(this.orgClient ?? this.client, this.repo, name, values);
2092
+ return addOrgPropertyValues(this.orgClient ?? this.client, this.repo, name, values, this.orgClient !== void 0);
2008
2093
  }
2009
2094
  async checkPropertyValues(values) {
2010
2095
  return checkPropertyValues(this.orgClient ?? this.client, this.repo, values);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-github",
3
- "version": "5.0.0-alpha.446",
3
+ "version": "5.0.0-alpha.453",
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",
@@ -40,25 +40,25 @@
40
40
  "eslint": "^10.14.0",
41
41
  "eslint-plugin-n": "^18.5.0",
42
42
  "globals": "^17.14.0",
43
- "tsdown": "^0.23.5",
43
+ "tsdown": "^0.23.7",
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.446",
48
- "@theholocron/eslint-config": "^8.9.0-alpha.17",
49
- "@theholocron/fs-utils": "^1.17.0-alpha.4",
50
- "@theholocron/github-client": "^1.58.0-alpha.32",
51
- "@theholocron/http-client": "^1.58.0-alpha.32",
47
+ "@theholocron/cli": "5.0.0-alpha.453",
48
+ "@theholocron/eslint-config": "^8.9.0-alpha.18",
49
+ "@theholocron/http-client": "^1.58.0-alpha.37",
52
50
  "@theholocron/misc-utils": "^1.17.0-alpha.4",
53
- "@theholocron/tsconfig": "^8.9.0-alpha.17",
54
- "@theholocron/tsdown-config": "^8.9.0-alpha.17",
55
- "@theholocron/vitest-config": "^8.9.0-alpha.17"
51
+ "@theholocron/fs-utils": "^1.17.0-alpha.4",
52
+ "@theholocron/tsconfig": "^8.9.0-alpha.18",
53
+ "@theholocron/tsdown-config": "^8.9.0-alpha.18",
54
+ "@theholocron/github-client": "^1.58.0-alpha.37",
55
+ "@theholocron/vitest-config": "^8.9.0-alpha.18"
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.446"
61
+ "@theholocron/cli": "5.0.0-alpha.453"
62
62
  },
63
63
  "engines": {
64
64
  "node": ">=22"