@davidbyoung/software-factory 0.1.11 → 0.1.13

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 (85) hide show
  1. package/agents/factory-e2e-reviewer.md +1 -1
  2. package/agents/factory-test-reviewer.md +1 -1
  3. package/agents/factory-ui-reviewer.md +2 -2
  4. package/dist/board.d.mts +9 -7
  5. package/dist/board.mjs +59 -36
  6. package/dist/build.d.mts +4 -0
  7. package/dist/build.mjs +9 -4
  8. package/dist/cli.mjs +8 -1
  9. package/dist/code-host/github.mjs +9 -4
  10. package/dist/code-host/types.d.mts +4 -2
  11. package/dist/commands.d.mts +1 -1
  12. package/dist/commands.mjs +16 -7
  13. package/dist/config.d.mts +7 -0
  14. package/dist/config.mjs +68 -5
  15. package/dist/explain.mjs +6 -0
  16. package/dist/guard-commit.d.mts +3 -3
  17. package/dist/guard-commit.mjs +31 -6
  18. package/dist/guard-ticket-text.d.mts +3 -2
  19. package/dist/guard-ticket-text.mjs +7 -4
  20. package/dist/labels.d.mts +28 -0
  21. package/dist/labels.mjs +36 -0
  22. package/dist/lib/clock.d.mts +3 -1
  23. package/dist/lib/clock.mjs +12 -6
  24. package/dist/lib/pull-tickets.d.mts +15 -0
  25. package/dist/lib/pull-tickets.mjs +12 -0
  26. package/dist/lib/refined-check.d.mts +1 -1
  27. package/dist/lib/refined-check.mjs +3 -5
  28. package/dist/lib/usage.d.mts +3 -1
  29. package/dist/lib/usage.mjs +4 -2
  30. package/dist/lib/work-status.d.mts +29 -23
  31. package/dist/lib/work-status.mjs +30 -33
  32. package/dist/merge-policy.d.mts +9 -7
  33. package/dist/merge-policy.mjs +13 -11
  34. package/dist/poller.d.mts +5 -3
  35. package/dist/poller.mjs +27 -17
  36. package/dist/pr.d.mts +22 -0
  37. package/dist/pr.mjs +60 -10
  38. package/dist/remove.mjs +16 -9
  39. package/dist/review-tickets.d.mts +12 -0
  40. package/dist/review-tickets.mjs +59 -0
  41. package/dist/review-verdict.d.mts +6 -1
  42. package/dist/review-verdict.mjs +15 -9
  43. package/dist/reviewers.d.mts +7 -4
  44. package/dist/reviewers.mjs +19 -12
  45. package/dist/runner/github-actions.mjs +6 -7
  46. package/dist/runner/types.d.mts +7 -6
  47. package/dist/status.d.mts +19 -7
  48. package/dist/status.mjs +38 -23
  49. package/dist/sync.d.mts +8 -0
  50. package/dist/sync.mjs +30 -1
  51. package/dist/ticket-fields.d.mts +4 -2
  52. package/dist/ticket-fields.mjs +10 -3
  53. package/dist/ticket.d.mts +14 -7
  54. package/dist/ticket.mjs +121 -72
  55. package/dist/tickets/github.d.mts +10 -2
  56. package/dist/tickets/github.mjs +74 -20
  57. package/dist/tickets/index.d.mts +9 -2
  58. package/dist/tickets/index.mjs +20 -5
  59. package/dist/tickets/types.d.mts +59 -30
  60. package/dist/tickets/types.mjs +13 -3
  61. package/dist/tool-names.d.mts +7 -0
  62. package/dist/tool-names.mjs +1 -0
  63. package/dist/tools.d.mts +4 -1
  64. package/dist/tools.mjs +5 -0
  65. package/docs/cli.md +12 -8
  66. package/docs/configuration.md +179 -9
  67. package/docs/developing.md +17 -9
  68. package/docs/github/by-hand.md +2 -2
  69. package/docs/github/reference.md +22 -22
  70. package/docs/plugins.md +6 -6
  71. package/docs/workflow.md +8 -6
  72. package/package.json +1 -1
  73. package/review.md +11 -11
  74. package/rules.md +25 -16
  75. package/settings.schema.json +45 -0
  76. package/skills/factory-address-review/SKILL.md +7 -6
  77. package/skills/factory-build/SKILL.md +28 -22
  78. package/skills/factory-refine/SKILL.md +1 -1
  79. package/skills/factory-resolve-conflicts/SKILL.md +5 -4
  80. package/workflows/factory-build.yml +6 -5
  81. package/workflows/factory-claude-review.yml +38 -1
  82. package/workflows/factory-conflicts.yml +1 -1
  83. package/workflows/factory-merge-policy.yml +8 -7
  84. package/workflows/factory-review-verdict.yml +1 -1
  85. package/workflows/factory-review.yml +1 -1
@@ -97,6 +97,6 @@ A high or medium finding outside the change under review, such as an
97
97
  existing test that cannot fail, is also written as one follow-up line, in
98
98
  the format under "Follow-ups" in `.claude/factory/rules.md`, led by the test's file, so
99
99
  the author can append it as it stands to the follow-ups issue, rather than
100
- open an issue. Write `#N` for the build number; the author fills it in.
100
+ open an issue. Write `TICKET` for the ticket being built; the author fills it in.
101
101
 
102
102
  End with exactly one line: `Verdict: pass` when there is no high or medium finding, or `Verdict: fail, N findings to fix` with N the number of high and medium findings ("1 finding" when there is one). A low finding does not count. Nothing after that line.
@@ -86,6 +86,6 @@ A high or medium finding outside the change under review, such as an
86
86
  existing test that cannot fail, is also written as one follow-up line, in
87
87
  the format under "Follow-ups" in `.claude/factory/rules.md`, led by the test's file, so
88
88
  the author can append it as it stands to the follow-ups issue, rather than
89
- open an issue. Write `#N` for the build number; the author fills it in.
89
+ open an issue. Write `TICKET` for the ticket being built; the author fills it in.
90
90
 
91
91
  End with exactly one line: `Verdict: pass` when there is no high or medium finding, or `Verdict: fail, N findings to fix` with N the number of high and medium findings ("1 finding" when there is one). A low finding does not count. Nothing after that line.
@@ -152,8 +152,8 @@ A finding the builder will leave for the owner, because it needs a decision or
152
152
  is already on the default branch, is also written as one follow-up line, in
153
153
  the format under "Follow-ups" in `.claude/factory/rules.md`, led by the page or
154
154
  file it is about, so the builder can append it to the follow-ups issue as it
155
- stands, rather than open an issue. Write `#N` for the build number; the builder
156
- fills it in.
155
+ stands, rather than open an issue. Write `TICKET` for the ticket being built; the
156
+ builder fills it in.
157
157
 
158
158
  End with exactly one line: `Verdict: pass` when there are no findings, or
159
159
  `Verdict: fail, N findings to fix` with N the number of findings ("1 finding"
package/dist/board.d.mts CHANGED
@@ -3,7 +3,7 @@ import { type Paint } from "./lib/color.mts";
3
3
  import { type Settings } from "./config.mts";
4
4
  import { type Columns, type Board, type BoardField, type Derived, type PullRequest, type RepoSnapshot } from "./lib/work-status.mts";
5
5
  import { type Runner } from "./runner/index.mts";
6
- import { type Ticket, type Tickets, type Write } from "./tickets/types.mts";
6
+ import { type Key, type Links, type Ticket, type Tickets, type Write } from "./tickets/types.mts";
7
7
  export type { Write };
8
8
  /** Which of the board's fields the sync writes, named as the settings name
9
9
  * them; null means never. */
@@ -17,6 +17,8 @@ export type FieldNames = {
17
17
  export type BoardConfig = {
18
18
  columns: Columns;
19
19
  fields: FieldNames;
20
+ /** The name of the follow-ups ticket's label. */
21
+ followUp: string;
20
22
  };
21
23
  export declare const DEFAULT_FIELDS: FieldNames;
22
24
  export declare const DEFAULT_BOARD: BoardConfig;
@@ -65,7 +67,7 @@ export declare function boardRows(fields: BoardField[], cfg: BoardConfig, settin
65
67
  * field, under the setting each comes from. */
66
68
  export declare function boardReport(number: number, board: Board, cfg: BoardConfig, settings: Pick<Settings, "builds">, paint?: Paint): string[];
67
69
  export type Plan = {
68
- number: number;
70
+ key: Key;
69
71
  itemId: string | null;
70
72
  derived: Derived;
71
73
  /** The cost markers' sum as subscription dollars, or null when there are
@@ -80,9 +82,9 @@ export type Plan = {
80
82
  * A card's Session is an Actions run's page, which `runPage` gives for its
81
83
  * ID, and any other session as it is. */
82
84
  export declare function planSync(snapshot: RepoSnapshot, board: Board, runPage: (id: string) => string, cfg?: BoardConfig): Plan[];
83
- export declare function logLine(plan: Plan): string;
85
+ export declare function logLine(plan: Plan, ref: (key: Key) => string): string;
84
86
  export type Comment = {
85
- issue: number;
87
+ issue: Key;
86
88
  body: string;
87
89
  };
88
90
  type PullEvent = {
@@ -96,10 +98,10 @@ type PullEvent = {
96
98
  /** The comments a closed pull request calls for: one on each issue it
97
99
  * closes when it was not merged, and one on each open follow-ups issue it
98
100
  * built part of without closing. */
99
- export declare function closedPullComments(event: PullEvent, closes: number[], openFollowUps: number[], columns?: Columns): Comment[];
101
+ export declare function closedPullComments(event: PullEvent, links: Links, openFollowUps: Key[], columns: Columns, ref: (key: Key) => string): Comment[];
100
102
  /** The nightly run's clears: claims and starts over 24 hours old with no
101
103
  * pull request. */
102
- export declare function nightlyComments(snapshot: RepoSnapshot, now: Date, columns?: Columns): Comment[];
104
+ export declare function nightlyComments(snapshot: RepoSnapshot, now: Date, columns: Columns, ref: (key: Key) => string, followUp: string): Comment[];
103
105
  /** What collect saves for apply: the tickets and the pull requests. */
104
106
  export type Saved = {
105
107
  tickets: Ticket[];
@@ -113,7 +115,7 @@ export type PullSource = {
113
115
  costs: boolean;
114
116
  }): Promise<PullRequest[]>;
115
117
  linking(skip: number[]): Promise<PullRequest[]>;
116
- closes(pull: number): Promise<number[]>;
118
+ closes(pull: number): Promise<Key[]>;
117
119
  };
118
120
  export type Deps = {
119
121
  /** The ticket system and the pull requests for the repository and board
package/dist/board.mjs CHANGED
@@ -20,16 +20,18 @@
20
20
  //
21
21
  // Tickets and the board go through the ticket interface (`tickets/`); the
22
22
  // pull requests through `code-host/`.
23
+ import { TICKET_LABELS } from "./labels.mjs";
23
24
  import { colorOn, painter, plain, } from "./lib/color.mjs";
24
25
  import { readFileSync, writeFileSync } from "node:fs";
25
26
  import { join } from "node:path";
26
27
  import { columnsOf, fieldNamesOf, loadSettings, } from "./config.mjs";
27
- import { DEFAULT_COLUMNS, STATE_KEYS, cardOf, columnFor, columnsFor, sameName, statusOfColumn, commentBody, derive, buildsPartOf, issueCost, toClear, toSnapshot, actionsRunLink, } from "./lib/work-status.mjs";
28
+ import { DEFAULT_COLUMNS, STATE_KEYS, cardOf, columnFor, columnsFor, sameName, statusOfColumn, commentBody, derive, issueCost, toClear, toSnapshot, actionsRunLink, } from "./lib/work-status.mjs";
28
29
  import { subscriptionDollars } from "./lib/pricing.mjs";
29
30
  import { openCodeHost } from "./code-host/index.mjs";
30
31
  import { openRunner } from "./runner/index.mjs";
31
32
  import { toBoard } from "./tickets/github.mjs";
32
- import { openTickets } from "./tickets/index.mjs";
33
+ import { openTickets, refOf } from "./tickets/index.mjs";
34
+ import { linkPulls, ownLinks, ticketsOf } from "./lib/pull-tickets.mjs";
33
35
  import { need, readAll, } from "./tickets/types.mjs";
34
36
  export const DEFAULT_FIELDS = {
35
37
  session: "Session",
@@ -39,10 +41,15 @@ export const DEFAULT_FIELDS = {
39
41
  export const DEFAULT_BOARD = {
40
42
  columns: DEFAULT_COLUMNS,
41
43
  fields: DEFAULT_FIELDS,
44
+ followUp: TICKET_LABELS["follow-up"],
42
45
  };
43
46
  /** The columns and fields the settings name. */
44
47
  export function boardConfigOf(s) {
45
- return { columns: columnsOf(s), fields: fieldNamesOf(s) };
48
+ return {
49
+ columns: columnsOf(s),
50
+ fields: fieldNamesOf(s),
51
+ followUp: s.tickets.labels["follow-up"],
52
+ };
46
53
  }
47
54
  const FIELD_KINDS = [
48
55
  {
@@ -260,14 +267,14 @@ export function planSync(snapshot, board, runPage, cfg = DEFAULT_BOARD) {
260
267
  const everyPull = [...snapshot.pulls, ...(snapshot.donePulls ?? [])];
261
268
  const fields = checkFields(board.fields, cfg);
262
269
  return snapshot.issues.map((issue) => {
263
- const derived = derive(issue, cardOf(board, issue.number, cfg.columns), snapshot.pulls, cfg.columns);
270
+ const derived = derive(issue, cardOf(board, issue.key, cfg.columns), snapshot.pulls, cfg.columns, cfg.followUp);
264
271
  const listPrice = issueCost(issue, everyPull);
265
272
  const cost = listPrice === null
266
273
  ? null
267
274
  : Math.round(subscriptionDollars(listPrice) * 100) / 100;
268
- const item = board.items.get(issue.number);
275
+ const item = board.items.get(issue.key);
269
276
  const base = {
270
- number: issue.number,
277
+ key: issue.key,
271
278
  itemId: item?.itemId ?? null,
272
279
  derived,
273
280
  cost,
@@ -306,27 +313,29 @@ export function planSync(snapshot, board, runPage, cfg = DEFAULT_BOARD) {
306
313
  return { ...base, writes };
307
314
  });
308
315
  }
309
- export function logLine(plan) {
316
+ export function logLine(plan, ref) {
310
317
  const d = plan.derived;
318
+ const name = ref(plan.key);
311
319
  if (plan.unmapped !== undefined)
312
- return `#${plan.number} card is in "${plan.unmapped}", which no state names (left alone)`;
320
+ return `${name} card is in "${plan.unmapped}", which no state names (left alone)`;
313
321
  const cost = plan.cost === null ? "(empty)" : plan.cost.toFixed(2);
314
322
  const values = `Status=${d.status}, Session=${d.session || "(empty)"}, Runs in=${d.runsIn || "(empty)"}, Cost=${cost}`;
315
323
  if (plan.writes.length === 0)
316
- return `#${plan.number} ${values} (unchanged)`;
324
+ return `${name} ${values} (unchanged)`;
317
325
  const added = plan.itemId ? "" : "added to the board; ";
318
- return `#${plan.number} ${values} (${added}set ${plan.writes.map((w) => w.field).join(", ")})`;
326
+ return `${name} ${values} (${added}set ${plan.writes.map((w) => w.field).join(", ")})`;
319
327
  }
320
328
  /** The comments a closed pull request calls for: one on each issue it
321
329
  * closes when it was not merged, and one on each open follow-ups issue it
322
330
  * built part of without closing. */
323
- export function closedPullComments(event, closes, openFollowUps, columns = DEFAULT_COLUMNS) {
331
+ export function closedPullComments(event, links, openFollowUps, columns, ref) {
324
332
  if (event.action !== "closed")
325
333
  return [];
326
334
  const pull = event.pull_request;
335
+ const { closes } = links;
327
336
  const closedKind = (issue) => ({
328
337
  kind: "pull-closed",
329
- issue,
338
+ issue: { key: issue, ref: ref(issue) },
330
339
  pull: pull.number,
331
340
  });
332
341
  const comments = [];
@@ -334,7 +343,7 @@ export function closedPullComments(event, closes, openFollowUps, columns = DEFAU
334
343
  for (const issue of closes)
335
344
  comments.push({ issue, body: commentBody(closedKind(issue), columns) });
336
345
  for (const followUps of openFollowUps) {
337
- if (closes.includes(followUps) || !buildsPartOf(pull.body ?? "", followUps))
346
+ if (closes.includes(followUps) || !links.partOf.includes(followUps))
338
347
  continue;
339
348
  comments.push({
340
349
  issue: followUps,
@@ -347,21 +356,18 @@ export function closedPullComments(event, closes, openFollowUps, columns = DEFAU
347
356
  }
348
357
  /** The nightly run's clears: claims and starts over 24 hours old with no
349
358
  * pull request. */
350
- export function nightlyComments(snapshot, now, columns = DEFAULT_COLUMNS) {
359
+ export function nightlyComments(snapshot, now, columns, ref, followUp) {
351
360
  return snapshot.issues.flatMap((issue) => {
352
- const clear = toClear(issue, snapshot.pulls, now);
361
+ const clear = toClear(issue, snapshot.pulls, now, followUp);
353
362
  if (!clear)
354
363
  return [];
364
+ const named = { key: issue.key, ref: ref(issue.key) };
355
365
  return [
356
366
  {
357
- issue: issue.number,
367
+ issue: issue.key,
358
368
  body: commentBody(clear.kind === "claim"
359
- ? { kind: "cleared-claim", issue: issue.number, since: clear.since }
360
- : {
361
- kind: "cleared-start",
362
- issue: issue.number,
363
- since: clear.since,
364
- }, columns),
369
+ ? { kind: "cleared-claim", issue: named, since: clear.since }
370
+ : { kind: "cleared-start", issue: named, since: clear.since }, columns),
365
371
  },
366
372
  ];
367
373
  });
@@ -370,19 +376,24 @@ async function postAll(comments, d, dryRun) {
370
376
  for (const c of comments) {
371
377
  const first = c.body.split("\n")[0];
372
378
  if (dryRun) {
373
- d.out(`would comment on #${c.issue}: ${first}`);
379
+ d.out(`would comment on ${d.tickets.ref(c.issue)}: ${first}`);
374
380
  continue;
375
381
  }
376
382
  await d.tickets.comment(c.issue, c.body);
377
- d.out(`commented on #${c.issue}: ${first}`);
383
+ d.out(`commented on ${d.tickets.ref(c.issue)}: ${first}`);
378
384
  }
379
385
  }
380
386
  async function read(d) {
381
- const [tickets, pulls] = await Promise.all([
387
+ const [tickets, open] = await Promise.all([
382
388
  readAll(d.tickets),
383
389
  d.pulls.open({ costs: true }),
384
390
  ]);
385
- const donePulls = await d.pulls.linking(pulls.map((p) => p.number));
391
+ const pulls = linkPulls(open, d.tickets, d.own);
392
+ // Only the code host's own links say which closed pull requests built a
393
+ // ticket.
394
+ const donePulls = d.own
395
+ ? linkPulls(await d.pulls.linking(pulls.map((p) => p.number)), d.tickets, d.own)
396
+ : [];
386
397
  return { tickets, pulls, donePulls };
387
398
  }
388
399
  const snapshotOf = (saved, now) => toSnapshot(saved.tickets, saved.pulls, now, saved.donePulls);
@@ -393,9 +404,13 @@ async function collect(d, opts) {
393
404
  const event = JSON.parse(d.readFile(opts.event));
394
405
  if (event.action === "closed") {
395
406
  const followUps = snapshot.issues
396
- .filter((i) => i.state === "open" && i.labels.includes("follow-up"))
397
- .map((i) => i.number);
398
- const comments = closedPullComments(event, await d.pulls.closes(event.pull_request.number), followUps, d.config.columns);
407
+ .filter((i) => i.state === "open" && i.labels.includes(d.config.followUp))
408
+ .map((i) => i.key);
409
+ const links = ticketsOf({
410
+ body: event.pull_request.body ?? "",
411
+ closes: d.own ? await d.pulls.closes(event.pull_request.number) : [],
412
+ }, d.tickets, d.own);
413
+ const comments = closedPullComments(event, links, followUps, d.config.columns, (k) => d.tickets.ref(k));
399
414
  await postAll(comments, d, opts.dryRun);
400
415
  if (comments.length && !opts.dryRun) {
401
416
  saved = await read(d);
@@ -404,7 +419,7 @@ async function collect(d, opts) {
404
419
  }
405
420
  }
406
421
  if (opts.nightly) {
407
- const comments = nightlyComments(snapshot, d.now(), d.config.columns);
422
+ const comments = nightlyComments(snapshot, d.now(), d.config.columns, (k) => d.tickets.ref(k), d.config.followUp);
408
423
  await postAll(comments, d, opts.dryRun);
409
424
  if (comments.length && !opts.dryRun)
410
425
  saved = await read(d);
@@ -422,10 +437,10 @@ async function apply(saved, board, d, write) {
422
437
  d.out(`${line.label} ${line.text}`);
423
438
  const plans = planSync(snapshotOf(saved, d.now()), board, d.runPage, d.config);
424
439
  for (const plan of plans) {
425
- d.out(logLine(plan));
440
+ d.out(logLine(plan, d.ref));
426
441
  if (!write || plan.writes.length === 0)
427
442
  continue;
428
- const itemId = plan.itemId ?? (await write.add(plan.number));
443
+ const itemId = plan.itemId ?? (await write.add(plan.key));
429
444
  await write.set(itemId, plan.writes);
430
445
  }
431
446
  }
@@ -455,6 +470,7 @@ export async function main(argv, deps) {
455
470
  const repository = deps.env.GITHUB_REPOSITORY || settings.repository;
456
471
  const runner = deps.runner(repository, settings.builds.runner);
457
472
  const runPage = (id) => runner.runPage(id);
473
+ const ref = refOf(settings.tickets.type);
458
474
  const fixture = option(argv, "--fixture");
459
475
  if (argv[0] !== "collect" &&
460
476
  argv[0] !== "apply" &&
@@ -464,12 +480,19 @@ export async function main(argv, deps) {
464
480
  if (fixture) {
465
481
  const saved = JSON.parse(deps.readFile(join(fixture, "repo.json")));
466
482
  const boardPages = JSON.parse(deps.readFile(join(fixture, "board.json")));
467
- await apply(saved, toBoard(boardPages, repository), { ...deps, repository, config, runPage }, null);
483
+ await apply(saved, toBoard(boardPages, repository), { ...deps, repository, config, runPage, ref }, null);
468
484
  return 0;
469
485
  }
470
486
  const board = argv[0] === "collect" ? null : await projectNumber(deps);
471
487
  const opened = await deps.open(settings, { repository, board });
472
- const d = { ...deps, config, repository, runPage, ...opened };
488
+ const d = {
489
+ ...deps,
490
+ config,
491
+ repository,
492
+ runPage,
493
+ ...opened,
494
+ own: ownLinks(settings),
495
+ };
473
496
  if (argv[0] === "collect") {
474
497
  const out = option(argv, "--out");
475
498
  if (!out)
@@ -500,11 +523,11 @@ export async function main(argv, deps) {
500
523
  throw new Error("apply needs --in FILE.");
501
524
  if (!d.env.GH_TOKEN)
502
525
  throw new Error("FACTORY_BOARD_TOKEN is not set.");
503
- await apply(JSON.parse(d.readFile(input)), await boardOps.read(), d, dryRun ? null : boardOps);
526
+ await apply(JSON.parse(d.readFile(input)), await boardOps.read(), { ...d, ref }, dryRun ? null : boardOps);
504
527
  return 0;
505
528
  }
506
529
  const saved = await collect(d, { nightly: false, dryRun: true });
507
- await apply(saved, await boardOps.read(), d, null);
530
+ await apply(saved, await boardOps.read(), { ...d, ref }, null);
508
531
  return 0;
509
532
  }
510
533
  catch (error) {
package/dist/build.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { type Settings } from "./config.mts";
2
2
  import { type CodeHost } from "./code-host/index.mts";
3
3
  import { type Runner } from "./runner/index.mts";
4
+ import type { Key } from "./tickets/types.mts";
4
5
  export type Deps = {
5
6
  settings: () => Promise<Settings>;
6
7
  env: Record<string, string | undefined>;
@@ -8,6 +9,9 @@ export type Deps = {
8
9
  codeHost: (repository: string, type: string) => CodeHost;
9
10
  /** The runner of that name. */
10
11
  runner: (repository: string, name: string) => Runner;
12
+ /** How the settings' ticket system reads a key and writes a ticket. */
13
+ keyOf: (type: string) => (typed: string) => Key;
14
+ refOf: (type: string) => (key: Key) => string;
11
15
  now: () => Date;
12
16
  sleep: (ms: number) => Promise<unknown>;
13
17
  out: (line: string) => void;
package/dist/build.mjs CHANGED
@@ -10,18 +10,21 @@ import { setTimeout as sleep } from "node:timers/promises";
10
10
  import { loadSettings, targetOf } from "./config.mjs";
11
11
  import { openCodeHost } from "./code-host/index.mjs";
12
12
  import { openRunner } from "./runner/index.mjs";
13
+ import { keyOf, refOf } from "./tickets/index.mjs";
13
14
  const USAGE = "Usage: factory build N";
14
15
  /** How long to look for the run, and how often. */
15
16
  const FIND_FOR_MS = 15_000;
16
17
  const EVERY_MS = 3_000;
17
18
  export async function main(argv, d) {
18
- const ticket = Number(argv[0]);
19
- if (argv.length !== 1 || !Number.isInteger(ticket) || ticket <= 0) {
19
+ if (argv.length !== 1 || !argv[0] || argv[0].startsWith("-")) {
20
20
  d.err(USAGE);
21
21
  return 2;
22
22
  }
23
23
  try {
24
24
  const settings = await d.settings();
25
+ const ticket = d.keyOf(settings.tickets.type)(argv[0]);
26
+ const ref = d.refOf(settings.tickets.type)(ticket);
27
+ const runName = `Build ${ref}`;
25
28
  const { repository } = targetOf(settings, d.env);
26
29
  const runner = d.runner(repository, settings.builds.runner);
27
30
  const branch = await d
@@ -31,12 +34,12 @@ export async function main(argv, d) {
31
34
  await runner.startBuild(ticket, branch);
32
35
  let link = null;
33
36
  for (;;) {
34
- link = await runner.findBuild(ticket, since);
37
+ link = await runner.findBuild(runName, since);
35
38
  if (link || d.now().getTime() - since >= FIND_FOR_MS)
36
39
  break;
37
40
  await d.sleep(EVERY_MS);
38
41
  }
39
- d.out(`Started a build of #${ticket} in GitHub Actions:`);
42
+ d.out(`Started a build of ${ref} in GitHub Actions:`);
40
43
  d.out(link ?? runner.buildsPage());
41
44
  return 0;
42
45
  }
@@ -52,6 +55,8 @@ export async function run(argv) {
52
55
  env: process.env,
53
56
  codeHost: (repository, type) => openCodeHost(repository, type),
54
57
  runner: (repository, name) => openRunner(repository, name),
58
+ keyOf,
59
+ refOf,
55
60
  now: () => new Date(),
56
61
  sleep,
57
62
  out: (line) => console.log(line),
package/dist/cli.mjs CHANGED
@@ -36,6 +36,7 @@ const PR_STEPS = [
36
36
  "resolve",
37
37
  "ready",
38
38
  "closes",
39
+ "cost",
39
40
  "for-branch",
40
41
  "comments",
41
42
  "comment",
@@ -64,7 +65,8 @@ const pr = (sub, args) => ({
64
65
  const TICKET_ARGS = {
65
66
  refined: "N [--check] [--before-file FILE]",
66
67
  stop: 'N "reason"',
67
- view: "N [--field title|state|labels|body] [--json]",
68
+ view: "N [--field title|state|labels|body|ref] [--json]",
69
+ link: "N [--part]",
68
70
  list: '[--label LABEL] [--title "TITLE"] [--json]',
69
71
  edit: "N --body-file FILE [--attach FILE]",
70
72
  comment: "N --body-file FILE [--attach FILE]",
@@ -272,6 +274,11 @@ export const COMMANDS = [
272
274
  args: "",
273
275
  run: async () => (await import("./review-tools.mjs")).run(),
274
276
  },
277
+ {
278
+ words: ["review", "tickets"],
279
+ args: "N",
280
+ run: async (argv) => (await import("./review-tickets.mjs")).run(argv),
281
+ },
275
282
  {
276
283
  words: ["reviewers", "start"],
277
284
  args: "",
@@ -139,7 +139,7 @@ fragment links on Issue {
139
139
  }
140
140
  }`;
141
141
  const toComments = (raw) => (raw?.nodes ?? []).map((c) => ({
142
- id: c.databaseId,
142
+ id: String(c.databaseId),
143
143
  createdAt: c.createdAt,
144
144
  body: c.body,
145
145
  author: c.author?.login ?? "ghost",
@@ -153,7 +153,8 @@ export function toPull(raw, repository) {
153
153
  author: raw.author?.login ?? "ghost",
154
154
  closes: raw.closingIssuesReferences.nodes
155
155
  .filter((ref) => ref.repository.nameWithOwner === repository)
156
- .map((ref) => ref.number),
156
+ .map((ref) => String(ref.number)),
157
+ partOf: [],
157
158
  openThreads: (raw.reviewThreads?.nodes ?? []).filter((t) => !t.isResolved)
158
159
  .length,
159
160
  checks: raw.commits?.nodes[0]?.commit.statusCheckRollup?.state ?? null,
@@ -184,7 +185,7 @@ const CLOSING_QUERY = `
184
185
  query ClosingIssues($owner: String!, $name: String!, $number: Int!) {
185
186
  repository(owner: $owner, name: $name) {
186
187
  pullRequest(number: $number) {
187
- closingIssuesReferences(first: 25) { nodes { number } }
188
+ closingIssuesReferences(first: 25) { nodes { number repository { nameWithOwner } } }
188
189
  }
189
190
  }
190
191
  }`;
@@ -346,7 +347,11 @@ export function githubCodeHost(o) {
346
347
  },
347
348
  async closes(n) {
348
349
  const result = await t.graphql(CLOSING_QUERY, { owner, name, number: n });
349
- return result.data.repository.pullRequest.closingIssuesReferences.nodes.map((x) => x.number);
350
+ return result.data.repository.pullRequest.closingIssuesReferences.nodes
351
+ .filter((x) => !x.repository ||
352
+ x.repository.nameWithOwner.toLowerCase() ===
353
+ o.repository.toLowerCase())
354
+ .map((x) => String(x.number));
350
355
  },
351
356
  async open(options = {}) {
352
357
  const page = await t.graphql(OPEN_PULLS_QUERY, {
@@ -1,4 +1,5 @@
1
1
  import type { PullRequest } from "../lib/work-status.mts";
2
+ import type { Key } from "../tickets/types.mts";
2
3
  /** One end of a pull request: the commit, its branch, and the repository
3
4
  * the branch is in, as owner/name. */
4
5
  export type PullEnd = {
@@ -171,8 +172,9 @@ export type CodeHost = {
171
172
  /** One line for each commit on the pull request the code host does not
172
173
  * show as signed: its short ID and the reason, such as `unsigned`. */
173
174
  unverifiedCommits(pull: number): Promise<string[]>;
174
- /** The tickets the pull request closes when it merges. */
175
- closes(pull: number): Promise<number[]>;
175
+ /** The tickets the pull request closes when it merges, by the code
176
+ * host's own links: only tickets the code host keeps itself. */
177
+ closes(pull: number): Promise<Key[]>;
176
178
  /** The open pull requests, as the views and the sync read them: with
177
179
  * their check state when `checks` is asked, and their comments, for the
178
180
  * cost markers, when `costs` is. */
@@ -13,7 +13,7 @@ export type Deps = {
13
13
  paint?: Paint;
14
14
  specTools: SpecTools;
15
15
  /** Ticket `id`'s labels; throws when it can't be read. */
16
- labels: (settings: Settings, id: number) => Promise<string[]>;
16
+ labels: (settings: Settings, id: string) => Promise<string[]>;
17
17
  };
18
18
  /** `argv` is the command's name, then its arguments. */
19
19
  export declare function main(argv: string[], d: Deps): Promise<number>;
package/dist/commands.mjs CHANGED
@@ -21,7 +21,8 @@ import { spawnSync } from "node:child_process";
21
21
  import { colorOn, painter, plain } from "./lib/color.mjs";
22
22
  import { defaultDeps, loadSettings, repoRoot, SETTINGS_FILE, SettingsError, } from "./config.mjs";
23
23
  import { specTools } from "./specs/index.mjs";
24
- import { openTickets } from "./tickets/index.mjs";
24
+ import { keyOf, openTickets } from "./tickets/index.mjs";
25
+ import { KeyError } from "./tickets/types.mjs";
25
26
  const USAGE = {
26
27
  gate: "Usage: factory gate",
27
28
  "test-one": "Usage: factory test-one FILE [NAME]",
@@ -63,9 +64,7 @@ export async function main(argv, d) {
63
64
  return usage();
64
65
  }
65
66
  else if (name === "specs-new" || name === "specs-finish") {
66
- // A ticket as the ticket system writes it: GitHub's, the only one
67
- // built, are whole numbers.
68
- if (args.length !== 1 || !/^[1-9]\d*$/.test(args[0]))
67
+ if (args.length !== 1 || args[0].startsWith("-"))
69
68
  return usage();
70
69
  }
71
70
  else if (name === "test-one") {
@@ -86,6 +85,16 @@ export async function main(argv, d) {
86
85
  d.err(e.message);
87
86
  return 1;
88
87
  }
88
+ if (name === "specs-new" || name === "specs-finish")
89
+ try {
90
+ keyOf(s.tickets.type)(args[0]);
91
+ }
92
+ catch (e) {
93
+ if (!(e instanceof KeyError))
94
+ throw e;
95
+ d.err(e.message);
96
+ return 1;
97
+ }
89
98
  const paint = d.paint ?? plain;
90
99
  /** The command's own closing line, after the output passed through. */
91
100
  const ended = (status, passed, failed) => {
@@ -169,7 +178,7 @@ export async function main(argv, d) {
169
178
  }
170
179
  let labels;
171
180
  try {
172
- labels = await d.labels(s, Number(id));
181
+ labels = await d.labels(s, id);
173
182
  }
174
183
  catch (e) {
175
184
  d.err(e instanceof Error ? e.message : String(e));
@@ -185,7 +194,7 @@ export async function main(argv, d) {
185
194
  return failed(`Could not start ticket ${id}'s spec in ${folder}`);
186
195
  d.out(`Started ticket ${id}'s spec in ${folder}`);
187
196
  }
188
- const files = tool.files(id, labels.includes("spec"));
197
+ const files = tool.files(id, labels.includes(s.tickets.labels.spec));
189
198
  const width = Math.max(...files.map((f) => f.path.length)) + 2;
190
199
  const kinds = Math.max(...files.map((f) => f.kind.length));
191
200
  d.out(`Write each file from ticket ${id}'s body:`);
@@ -218,7 +227,7 @@ export async function run(argv) {
218
227
  repository: settings.repository,
219
228
  board: null,
220
229
  });
221
- return (await tickets.read(id)).labels;
230
+ return (await tickets.read(tickets.key(id))).labels;
222
231
  },
223
232
  });
224
233
  }
package/dist/config.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { type Paint } from "./lib/color.mts";
3
3
  import { type FieldMapping } from "./ticket-fields.mts";
4
+ import { type Labels } from "./labels.mts";
4
5
  import { type Built } from "./tool-names.mts";
5
6
  import { type Watch, type Columns, type StateKey } from "./lib/work-status.mts";
6
7
  export declare class SettingsError extends Error {
@@ -59,6 +60,8 @@ export type Settings = {
59
60
  * first and then any heading of the repository's own, with the ticket
60
61
  * field that holds it, or null for the description. */
61
62
  ticketFields: FieldMapping;
63
+ /** The name of each label the factory puts on tickets. */
64
+ labels: Labels["tickets"];
62
65
  };
63
66
  /** Where pull requests are, and the pattern a build's branch is named
64
67
  * by. The pattern is null only when init reads settings without it, to
@@ -66,6 +69,8 @@ export type Settings = {
66
69
  codeHost: {
67
70
  type: string;
68
71
  branchName: string | null;
72
+ /** The name of each label the factory puts on pull requests. */
73
+ labels: Labels["codeHost"];
69
74
  };
70
75
  builds: {
71
76
  /** What notices a card moved to Ready and starts its build. */
@@ -297,6 +302,8 @@ export type Target = {
297
302
  watch: Watch | null;
298
303
  /** The column each state shows in on the board. */
299
304
  columns: Columns;
305
+ /** The name of the follow-ups ticket's label. */
306
+ followUp: string;
300
307
  };
301
308
  /** The settings' answer, with GITHUB_REPOSITORY and FACTORY_BOARD_NUMBER
302
309
  * winning where they are set. */