@theholocron/holocron-plugin-github 5.0.0-alpha.503 → 5.0.0-alpha.505

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 +65 -7
  2. package/package.json +6 -6
package/dist/index.mjs CHANGED
@@ -262,6 +262,43 @@ function createFieldSetter(client, repo) {
262
262
  }
263
263
  };
264
264
  }
265
+ // src/capabilities/issue-kind.ts
266
+ /** The Type name of each kind. */
267
+ const KIND_TYPE_NAMES = {
268
+ bug: "Bug",
269
+ feature: "Feature",
270
+ task: "Task"
271
+ };
272
+ /** The kind each label names where there is no Type. */
273
+ const LABEL_KINDS = {
274
+ bug: "bug",
275
+ enhancement: "feature",
276
+ chore: "task"
277
+ };
278
+ const TYPE_KINDS = new Map(Object.entries(KIND_TYPE_NAMES).map(([kind, name]) => [name.toLowerCase(), kind]));
279
+ /** The kind of an issue: its Type, else the one kind its labels name (two different ones name none). */
280
+ function kindOfIssue(issue) {
281
+ const typed = TYPE_KINDS.get(issue.type?.name?.toLowerCase() ?? "");
282
+ if (typed) return typed;
283
+ const named = new Set(issue.labels.flatMap((l) => LABEL_KINDS[l.name.toLowerCase()] ?? []));
284
+ return named.size === 1 ? [...named][0] : void 0;
285
+ }
286
+ /** Whether the issue's Type is already the kind's. */
287
+ function hasKindType(issue, kind) {
288
+ return issue.type?.name?.toLowerCase() === KIND_TYPE_NAMES[kind].toLowerCase();
289
+ }
290
+ /** Sets the Type of issue `number`; a refusal is returned as a `dropped` line, anything else (a rate limit) is thrown. */
291
+ async function writeKind(client, repo, number, kind) {
292
+ const name = KIND_TYPE_NAMES[kind];
293
+ try {
294
+ await client.issues.updateIssue(repo, number, { type: name });
295
+ return;
296
+ } catch (err) {
297
+ const why = fieldRefusal(err);
298
+ if (why === void 0) throw err;
299
+ return `kind ${name} (${why})`;
300
+ }
301
+ }
265
302
  // src/capabilities/issue-priority.ts
266
303
  /** The Priority field's option for each level. */
267
304
  const PRIORITY_OPTION_NAMES = {
@@ -392,6 +429,7 @@ async function readIssues(client, repo, selector, info) {
392
429
  const { labels, priority } = splitLabels(issue.labels.map((l) => l.name));
393
430
  const body = issue.body?.replace(MARKER, "").trimEnd();
394
431
  const migratedFrom = issue.body ? MARKER.exec(issue.body)?.[1] : void 0;
432
+ const kind = kindOfIssue(issue);
395
433
  records.push({
396
434
  key: `#${issue.number}`,
397
435
  url: issue.html_url,
@@ -401,6 +439,7 @@ async function readIssues(client, repo, selector, info) {
401
439
  closed: issue.state === "closed",
402
440
  ...priority ? { priority } : {},
403
441
  labels: labels.filter((l) => !l.toLowerCase().startsWith("status:")),
442
+ ...kind ? { kind } : {},
404
443
  ...issue.assignee ? { assignee: {
405
444
  id: issue.assignee.login,
406
445
  displayName: issue.assignee.name ?? issue.assignee.login,
@@ -457,6 +496,8 @@ async function importIssues(client, repo, records, options = {}) {
457
496
  const number = await createFromRecord(client, repo, record, options);
458
497
  const field = await priority.set(number, record.priority, { isNew: true });
459
498
  if (field.note) dropped.push(field.note);
499
+ const kindNote = record.kind ? await writeKind(client, repo, number, record.kind) : void 0;
500
+ if (kindNote) dropped.push(kindNote);
460
501
  results.push({
461
502
  source: record.key,
462
503
  key: `#${number}`,
@@ -569,6 +610,8 @@ async function create(client, repo, record, options, priority) {
569
610
  const number = await createFromRecord(client, repo, record, options);
570
611
  const field = await priority.set(number, record.priority, { isNew: true });
571
612
  if (field.note) dropped.push(field.note);
613
+ const kindNote = record.kind ? await writeKind(client, repo, number, record.kind) : void 0;
614
+ if (kindNote) dropped.push(kindNote);
572
615
  return {
573
616
  source: record.key,
574
617
  key: `#${number}`,
@@ -608,6 +651,9 @@ async function update(client, repo, issue, record, options, priority) {
608
651
  }
609
652
  const field = await priority.set(issue.number, record.priority, { dryRun: options.dryRun });
610
653
  if (field.changed) changes.push("priority field");
654
+ const kindWrong = record.kind !== void 0 && !hasKindType(issue, record.kind);
655
+ if (kindWrong) changes.push("kind");
656
+ const kindNote = kindWrong && !options.dryRun ? await writeKind(client, repo, issue.number, record.kind) : void 0;
611
657
  const comments = await client.issues.listComments(repo, issue.number);
612
658
  const seen = new Set(comments.map((c) => COMMENT_HEADER.exec(c.body)?.[1]));
613
659
  const missing = record.comments.filter((c) => !seen.has(c.createdAt));
@@ -622,7 +668,11 @@ async function update(client, repo, issue, record, options, priority) {
622
668
  created: false,
623
669
  updated: changes.length > 0,
624
670
  changes,
625
- dropped: [...droppedFor(record), ...field.note ? [field.note] : []]
671
+ dropped: [
672
+ ...droppedFor(record),
673
+ ...field.note ? [field.note] : [],
674
+ ...kindNote ? [kindNote] : []
675
+ ]
626
676
  };
627
677
  }
628
678
  // src/capabilities/issues-update.ts
@@ -3032,10 +3082,11 @@ function reportBackfill(ctx, input) {
3032
3082
  status: "heading",
3033
3083
  label: "Backfill"
3034
3084
  });
3085
+ const passed = tally.pullRequestsSkipped;
3035
3086
  ctx.say({
3036
3087
  status: "info",
3037
- label: "read",
3038
- detail: `${plural(tally.examined, "item")} finished` + (tally.pullRequestsSkipped > 0 ? `, ${plural(tally.pullRequestsSkipped, "pull request")} passed over` : "") + (tally.failed > 0 ? `, ${plural(tally.failed, "failure")}` : "")
3088
+ label: "summary",
3089
+ detail: `read ${plural(tally.examined, "item")}` + (tally.pullRequestsRead > 0 ? ` (${plural(tally.pullRequestsRead, "pull request")})` : "") + `; ${dryRun ? "would change" : "changed"} ${tally.changed}; passed over ${plural(passed, "pull request")}${passed > 0 ? " (give --pull-requests to include them)" : ""}; ${plural(tally.failed, "failure")}` + (more ? `; ${rateLimited ? "stopped by GitHub's rate limit" : `stopped at the limit of ${options.limit}`}, more remain` : "; the window is finished")
3039
3090
  });
3040
3091
  const types = Object.entries(tally.typeSet).map(([name, n]) => `${name} ${n}`).join(", ");
3041
3092
  ctx.say({
@@ -3073,17 +3124,17 @@ function reportBackfill(ctx, input) {
3073
3124
  label: `Still lacking, among the ${plural(tally.examined, "item")} read${dryRun ? ", after the changes above" : ""}`
3074
3125
  });
3075
3126
  if (tally.skippedFields !== void 0) ctx.say({
3076
- status: "info",
3127
+ status: "fail",
3077
3128
  label: "Priority, Effort",
3078
- detail: `not listed: the issue fields could not be read (${tally.skippedFields})`
3129
+ detail: `NOT checked, so the lists below are incomplete: the token (github.issues) was refused reading the organization issue fields (${tally.skippedFields})`
3079
3130
  });
3080
3131
  for (const [group, noun] of GROUPS) {
3081
3132
  if (!(group === "project" || group === "milestone" || fields.includes(group))) continue;
3082
3133
  const items = tally.lacking[group];
3083
3134
  ctx.say({
3084
- status: items.length === 0 ? "ok" : "info",
3135
+ status: "info",
3085
3136
  label: `without ${noun}`,
3086
- detail: String(items.length)
3137
+ detail: `${items.length} of ${plural(tally.examined, "item")} read`
3087
3138
  });
3088
3139
  for (const item of items) ctx.say({
3089
3140
  status: "info",
@@ -3130,9 +3181,13 @@ const emptyTally = () => ({
3130
3181
  effort: []
3131
3182
  },
3132
3183
  failed: 0,
3184
+ changed: 0,
3185
+ pullRequestsRead: 0,
3133
3186
  last: void 0,
3134
3187
  skippedFields: void 0
3135
3188
  });
3189
+ /** How many changes the tally holds, to tell whether one item added any. */
3190
+ const changes = (t) => Object.values(t.typeSet).reduce((a, b) => a + b, 0) + t.areaLabelsAdded + t.milestoneSet.parent + t.milestoneSet.explicit + t.projectSet;
3136
3191
  /** How an issue is named in a row. */
3137
3192
  const labelOf = (item) => `#${item.number}`;
3138
3193
  /** Reads what the run needs before it starts: labels, the named milestone and project, the organization's issue fields. Says why and returns nothing when a name does not exist. */
@@ -3257,8 +3312,10 @@ async function runBackfill(run) {
3257
3312
  }
3258
3313
  let stopped = read.rateLimited;
3259
3314
  for (const item of read.items) {
3315
+ const before = changes(tally);
3260
3316
  try {
3261
3317
  await handle(run, setup, tally, item, projects.get(item.nodeId) ?? []);
3318
+ if (changes(tally) > before) tally.changed++;
3262
3319
  } catch (err) {
3263
3320
  if (run.isRateLimited(err)) {
3264
3321
  stopped = true;
@@ -3272,6 +3329,7 @@ async function runBackfill(run) {
3272
3329
  tally.failed++;
3273
3330
  }
3274
3331
  tally.examined++;
3332
+ if (item.isPullRequest) tally.pullRequestsRead++;
3275
3333
  tally.last = item.number;
3276
3334
  }
3277
3335
  reportBackfill(ctx, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-github",
3
- "version": "5.0.0-alpha.503",
3
+ "version": "5.0.0-alpha.505",
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.503",
47
+ "@theholocron/cli": "5.0.0-alpha.505",
48
+ "@theholocron/fs-utils": "^1.17.0-alpha.5",
48
49
  "@theholocron/eslint-config": "^8.9.0-alpha.21",
49
- "@theholocron/github-client": "^1.58.0-alpha.46",
50
50
  "@theholocron/http-client": "^1.58.0-alpha.46",
51
- "@theholocron/fs-utils": "^1.17.0-alpha.5",
52
- "@theholocron/tsconfig": "^8.9.0-alpha.21",
51
+ "@theholocron/github-client": "^1.58.0-alpha.46",
53
52
  "@theholocron/misc-utils": "^1.17.0-alpha.5",
54
53
  "@theholocron/tsdown-config": "^8.9.0-alpha.21",
54
+ "@theholocron/tsconfig": "^8.9.0-alpha.21",
55
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.503"
61
+ "@theholocron/cli": "5.0.0-alpha.505"
62
62
  },
63
63
  "engines": {
64
64
  "node": ">=22"