@theholocron/holocron-plugin-github 5.0.0-alpha.521 → 5.0.0-alpha.523

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.
Files changed (2) hide show
  1. package/dist/index.mjs +86 -10
  2. package/package.json +6 -6
package/dist/index.mjs CHANGED
@@ -329,6 +329,73 @@ function createPrioritySetter(client, repo) {
329
329
  value: PRIORITY_OPTION_NAMES[level]
330
330
  }, flags) };
331
331
  }
332
+ // src/capabilities/issue-work-fields.ts
333
+ /** The Effort field's option for each effort. */
334
+ const EFFORT_NAMES = {
335
+ high: "High",
336
+ medium: "Medium",
337
+ low: "Low"
338
+ };
339
+ /** Makes the reader for the issues of `repo` (`owner/name`); the organization's field list is read once, on first use. */
340
+ function createWorkFieldReader(client, repo) {
341
+ const org = repo.split("/")[0];
342
+ let fields;
343
+ const listFields = () => fields ??= client.issueFields.list(org).catch((err) => {
344
+ if (fieldRefusal(err) === void 0) throw err;
345
+ return [];
346
+ });
347
+ const idOf = (list, name) => list.find((f) => f.name.toLowerCase() === name)?.id;
348
+ return { async read(number) {
349
+ const list = await listFields();
350
+ const effortId = idOf(list, "effort");
351
+ const startId = idOf(list, "start date");
352
+ const targetId = idOf(list, "target date");
353
+ if (effortId === void 0 && startId === void 0 && targetId === void 0) return {};
354
+ const values = await client.issueFields.values(repo, number).catch((err) => {
355
+ if (fieldRefusal(err) === void 0) throw err;
356
+ return [];
357
+ });
358
+ const valueOf = (id) => values.find((v) => v.issue_field_id === id);
359
+ const effort = (valueOf(effortId)?.single_select_option?.name ?? "").toLowerCase();
360
+ const start = valueOf(startId);
361
+ const target = valueOf(targetId);
362
+ return {
363
+ ...effort in EFFORT_NAMES ? { effort } : {},
364
+ ...start ? { startDate: String(start.value).slice(0, 10) } : {},
365
+ ...target ? { targetDate: String(target.value).slice(0, 10) } : {}
366
+ };
367
+ } };
368
+ }
369
+ /** Sets the work fields the record carries; one it does not carry is not touched. */
370
+ async function writeWorkFields(fields, number, record, flags) {
371
+ const wanted = [
372
+ ["effort", {
373
+ name: "Effort",
374
+ type: "select",
375
+ value: record.effort && EFFORT_NAMES[record.effort]
376
+ }],
377
+ ["startDate", {
378
+ name: "Start date",
379
+ type: "date",
380
+ value: record.startDate
381
+ }],
382
+ ["targetDate", {
383
+ name: "Target date",
384
+ type: "date",
385
+ value: record.targetDate
386
+ }]
387
+ ];
388
+ const out = {
389
+ changed: [],
390
+ notes: []
391
+ };
392
+ for (const [label, target] of wanted) {
393
+ const result = await fields.set(number, target, flags);
394
+ if (result.note) out.notes.push(result.note);
395
+ else if (result.changed) out.changed.push(label);
396
+ }
397
+ return out;
398
+ }
332
399
  // src/capabilities/issues-migration.ts
333
400
  /**
334
401
  * Export and import of GitHub issues for `holocron migrate`.
@@ -430,6 +497,7 @@ async function readIssues(client, repo, selector, info, kinds) {
430
497
  info.matched = issues.length;
431
498
  if (limit !== void 0) issues = pickByCreation(issues, (i) => i.created_at ?? i.updated_at, order, limit);
432
499
  }
500
+ const work = createWorkFieldReader(client, repo);
433
501
  const records = [];
434
502
  for (const issue of issues) {
435
503
  reportProgress(info.onProgress, records.length, issues.length);
@@ -443,6 +511,7 @@ async function readIssues(client, repo, selector, info, kinds) {
443
511
  const body = issue.body?.replace(MARKER, "").trimEnd();
444
512
  const migratedFrom = issue.body ? MARKER.exec(issue.body)?.[1] : void 0;
445
513
  const kind = kindOfIssue(issue, kinds);
514
+ const workFields = await work.read(issue.number);
446
515
  records.push({
447
516
  key: `#${issue.number}`,
448
517
  url: issue.html_url,
@@ -453,6 +522,7 @@ async function readIssues(client, repo, selector, info, kinds) {
453
522
  ...priority ? { priority } : {},
454
523
  labels: labels.filter((l) => !l.toLowerCase().startsWith("status:")),
455
524
  ...kind ? { kind } : {},
525
+ ...workFields,
456
526
  ...issue.assignee ? { assignee: {
457
527
  id: issue.assignee.login,
458
528
  displayName: issue.assignee.name ?? issue.assignee.login,
@@ -482,6 +552,7 @@ async function importIssues(client, repo, records, options = {}, kinds = CORE_KI
482
552
  if (url) existing.set(url, issue.number);
483
553
  }
484
554
  const priority = createPrioritySetter(client, repo);
555
+ const fields = createFieldSetter(client, repo);
485
556
  const results = [];
486
557
  const tick = () => reportProgress(options.onProgress, results.length, records.length);
487
558
  for (const record of records) {
@@ -509,6 +580,7 @@ async function importIssues(client, repo, records, options = {}, kinds = CORE_KI
509
580
  const number = await createFromRecord(client, repo, record, options);
510
581
  const field = await priority.set(number, record.priority, { isNew: true });
511
582
  if (field.note) dropped.push(field.note);
583
+ dropped.push(...(await writeWorkFields(fields, number, record, { isNew: true })).notes);
512
584
  const kindNote = record.kind ? await writeKind(client, repo, number, record.kind, kinds) : void 0;
513
585
  if (kindNote) dropped.push(kindNote);
514
586
  results.push({
@@ -600,10 +672,11 @@ async function syncIssues(client, repo, records, options = {}, kinds = CORE_KIND
600
672
  if (url) existing.set(url, issue);
601
673
  }
602
674
  const priority = createPrioritySetter(client, repo);
675
+ const fields = createFieldSetter(client, repo);
603
676
  const results = [];
604
677
  for (const record of records) try {
605
678
  const found = existing.get(record.url);
606
- results.push(found ? await update(client, repo, found, record, options, priority, kinds) : await create(client, repo, record, options, priority, kinds));
679
+ results.push(found ? await update(client, repo, found, record, options, priority, fields, kinds) : await create(client, repo, record, options, priority, fields, kinds));
607
680
  reportProgress(options.onProgress, results.length, records.length);
608
681
  } catch (err) {
609
682
  if (isRateLimited(err)) return results;
@@ -611,7 +684,7 @@ async function syncIssues(client, repo, records, options = {}, kinds = CORE_KIND
611
684
  }
612
685
  return results;
613
686
  }
614
- async function create(client, repo, record, options, priority, kinds) {
687
+ async function create(client, repo, record, options, priority, fields, kinds) {
615
688
  const dropped = droppedFor(record);
616
689
  if (options.dryRun) return {
617
690
  source: record.key,
@@ -623,6 +696,7 @@ async function create(client, repo, record, options, priority, kinds) {
623
696
  const number = await createFromRecord(client, repo, record, options);
624
697
  const field = await priority.set(number, record.priority, { isNew: true });
625
698
  if (field.note) dropped.push(field.note);
699
+ dropped.push(...(await writeWorkFields(fields, number, record, { isNew: true })).notes);
626
700
  const kindNote = record.kind ? await writeKind(client, repo, number, record.kind, kinds) : void 0;
627
701
  if (kindNote) dropped.push(kindNote);
628
702
  return {
@@ -634,7 +708,7 @@ async function create(client, repo, record, options, priority, kinds) {
634
708
  dropped
635
709
  };
636
710
  }
637
- async function update(client, repo, issue, record, options, priority, kinds) {
711
+ async function update(client, repo, issue, record, options, priority, fields, kinds) {
638
712
  const patch = {};
639
713
  const changes = [];
640
714
  if (issue.title !== record.title) {
@@ -664,6 +738,8 @@ async function update(client, repo, issue, record, options, priority, kinds) {
664
738
  }
665
739
  const field = await priority.set(issue.number, record.priority, { dryRun: options.dryRun });
666
740
  if (field.changed) changes.push("priority field");
741
+ const work = await writeWorkFields(fields, issue.number, record, { dryRun: options.dryRun });
742
+ changes.push(...work.changed);
667
743
  const kindWrong = record.kind !== void 0 && !hasKindType(issue, record.kind, kinds);
668
744
  if (kindWrong) changes.push("kind");
669
745
  const kindNote = kindWrong && !options.dryRun ? await writeKind(client, repo, issue.number, record.kind, kinds) : void 0;
@@ -684,16 +760,12 @@ async function update(client, repo, issue, record, options, priority, kinds) {
684
760
  dropped: [
685
761
  ...droppedFor(record),
686
762
  ...field.note ? [field.note] : [],
763
+ ...work.notes,
687
764
  ...kindNote ? [kindNote] : []
688
765
  ]
689
766
  };
690
767
  }
691
768
  // src/capabilities/issues-update.ts
692
- const EFFORT_NAMES = {
693
- high: "High",
694
- medium: "Medium",
695
- low: "Low"
696
- };
697
769
  /** Runs one step; a refusal or a bad key is a `dropped` line, anything else (a rate limit) is thrown. */
698
770
  async function guarded(what, out, step) {
699
771
  try {
@@ -2503,15 +2575,19 @@ async function readRepoInfo(client, repo) {
2503
2575
  settings
2504
2576
  };
2505
2577
  }
2506
- /** A ruleset reduced to what `setup` writes: its enforcement, rule types and required status checks. */
2578
+ /** A ruleset reduced to what `setup` writes: its enforcement, rule types, required status checks and the app a check is pinned to. */
2507
2579
  function toRulesetDetail(data) {
2508
2580
  const rules = data.rules ?? [];
2509
2581
  const checks = rules.find((r) => r.type === "required_status_checks")?.parameters?.required_status_checks;
2582
+ const entries = Array.isArray(checks) ? checks : [];
2583
+ const sources = {};
2584
+ for (const entry of entries) if (typeof entry.integration_id === "number") sources[String(entry.context)] = entry.integration_id;
2510
2585
  return {
2511
2586
  name: data.name,
2512
2587
  enforcement: data.enforcement,
2513
2588
  ruleTypes: rules.map((r) => r.type),
2514
- requiredChecks: Array.isArray(checks) ? checks.map((c) => String(c.context)) : []
2589
+ requiredChecks: entries.map((c) => String(c.context)),
2590
+ ...Object.keys(sources).length > 0 ? { requiredCheckSources: sources } : {}
2515
2591
  };
2516
2592
  }
2517
2593
  /** The value, or `undefined` when GitHub refuses the read (permission, plan, feature absent). Other errors still throw. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-github",
3
- "version": "5.0.0-alpha.521",
3
+ "version": "5.0.0-alpha.523",
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": "^6.0.3",
46
46
  "vitest": "^5.1.0",
47
- "@theholocron/cli": "5.0.0-alpha.521",
47
+ "@theholocron/cli": "5.0.0-alpha.523",
48
48
  "@theholocron/eslint-config": "^8.9.0-alpha.22",
49
+ "@theholocron/github-client": "^1.58.0-alpha.53",
49
50
  "@theholocron/fs-utils": "^1.17.0-alpha.5",
50
- "@theholocron/http-client": "^1.58.0-alpha.53",
51
51
  "@theholocron/tsconfig": "^8.9.0-alpha.22",
52
- "@theholocron/github-client": "^1.58.0-alpha.53",
52
+ "@theholocron/misc-utils": "^1.17.0-alpha.5",
53
53
  "@theholocron/tsdown-config": "^8.9.0-alpha.22",
54
54
  "@theholocron/vitest-config": "^8.9.0-alpha.22",
55
- "@theholocron/misc-utils": "^1.17.0-alpha.5"
55
+ "@theholocron/http-client": "^1.58.0-alpha.53"
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.521"
61
+ "@theholocron/cli": "5.0.0-alpha.523"
62
62
  },
63
63
  "engines": {
64
64
  "node": ">=22"