@kaynooo/cli-forgejo 0.21.0 → 0.23.0

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/cli.js +52 -19
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -336,13 +336,13 @@ function userConfigReadPath(bin, legacy = [], where = {}) {
336
336
  // ../kit/src/theme.ts
337
337
  var DEFAULT = {
338
338
  colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
339
- glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501" },
339
+ glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D" },
340
340
  accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
341
341
  bins: {}
342
342
  };
343
343
  var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
344
344
  var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
345
- var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#" };
345
+ var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+" };
346
346
  var PRESETS = {
347
347
  default: {},
348
348
  "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
@@ -549,11 +549,39 @@ function badge(word, stream, env = process6.env) {
549
549
  const { theme } = activeTheme();
550
550
  return tinted(paint(stream, env), theme.colors[status], env)(`${theme.glyphs[status]} ${word}`);
551
551
  }
552
+ function header(bin, context, stream, env = process6.env) {
553
+ if (!takesControlCodes(stream, env))
554
+ return "";
555
+ const colors = paint(stream, env);
556
+ const hash = [...bin].reduce((sum, char) => sum + char.charCodeAt(0), 0);
557
+ const { theme } = activeTheme();
558
+ const spec = theme.bins[bin] ?? theme.accents[hash % theme.accents.length];
559
+ const accent = tinted(typeof spec === "string" && spec.split(" ").includes("bold") ? colors : colors.bold, spec, env);
560
+ return `${accent(bin)}${context === undefined ? "" : colors.dim(` \u203A ${context}`)}`;
561
+ }
552
562
  function link(text, url, stream, env = process6.env) {
553
563
  if (takesControlCodes(stream, env))
554
564
  return `\x1B]8;;${url}\x1B\\${text}\x1B]8;;\x1B\\`;
555
565
  return text === url ? text : `${text} (${url})`;
556
566
  }
567
+ function printHeader(bin, context, stream = process6.stdout, env = process6.env) {
568
+ const line = header(bin, context, stream, env);
569
+ if (line !== "")
570
+ console.log(line);
571
+ }
572
+ function section(title, count, stream = process6.stdout, env = process6.env, tone) {
573
+ const label = count === undefined ? title : `${title} (${count})`;
574
+ if (!takesControlCodes(stream, env))
575
+ return label;
576
+ const { glyphs } = activeTheme().theme;
577
+ const head = `${glyphs.corner}${glyphs.rule} ${label} `;
578
+ const width = Math.min(stream.columns ?? 60, 100);
579
+ const rule = head + glyphs.rule.repeat(Math.max(3, width - Bun.stringWidth(head)));
580
+ return tone === undefined ? paint(stream, env).dim(rule) : tinted(paint(stream, env), activeTheme().theme.colors[tone], env)(rule);
581
+ }
582
+ function hyperlink(text, url, stream, env = process6.env) {
583
+ return takesControlCodes(stream, env) ? link(text, url, stream, env) : text;
584
+ }
557
585
 
558
586
  // ../kit/src/format.ts
559
587
  var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
@@ -2423,7 +2451,7 @@ function dimmed(text) {
2423
2451
  }
2424
2452
  function issueNumber2(issue) {
2425
2453
  const number = role("id", process.stdout)(`#${issue.number}`);
2426
- return takesControlCodes(process.stdout) ? link(number, issue.html_url, process.stdout) : number;
2454
+ return hyperlink(number, issue.html_url, process.stdout);
2427
2455
  }
2428
2456
  function boxesLeft(issue) {
2429
2457
  const list = boxes(issue.body);
@@ -2451,11 +2479,11 @@ function renderBoard(rows, now = Date.now(), limit = Number.POSITIVE_INFINITY) {
2451
2479
  const taken = claimed("taken");
2452
2480
  const away = claimed("away");
2453
2481
  const sections = [
2454
- { heading: "available", count: available.length, ...within(available, limit, ({ issue }) => [issueNumber2(issue), truncate(issue.title, TITLE_WIDTH), dimmed(issue.labels.map((label) => label.name).join(", "))]) },
2455
- { heading: "taken", count: taken.length, ...within(taken, limit, ({ issue, row }) => claimRow(issue, row, now)) },
2456
- { heading: "claimed, no live session here", count: away.length, ...within(away, limit, ({ issue, row }) => claimRow(issue, row, now), (line, index) => [line, ...noteLine(away[index]?.comments ?? [], now)]) }
2482
+ { heading: "available", tone: "ok", count: available.length, ...within(available, limit, ({ issue }) => [issueNumber2(issue), truncate(issue.title, TITLE_WIDTH), dimmed(issue.labels.map((label) => label.name).join(", "))]) },
2483
+ { heading: "taken", tone: "running", count: taken.length, ...within(taken, limit, ({ issue, row }) => claimRow(issue, row, now)) },
2484
+ { heading: "claimed, no live session here", tone: "warn", count: away.length, ...within(away, limit, ({ issue, row }) => claimRow(issue, row, now), (line, index) => [line, ...noteLine(away[index]?.comments ?? [], now)]) }
2457
2485
  ].filter((section) => section.count > 0);
2458
- return sections.length === 0 ? "no open issue" : sections.map(({ heading, count, lines }) => `${paint(process.stdout).bold(`${heading} (${count})`)}
2486
+ return sections.length === 0 ? "no open issue" : sections.map(({ heading, tone, count, lines }) => `${section(heading, count, process.stdout, process.env, tone)}
2459
2487
  ${lines.join(`
2460
2488
  `).replace(LINE_START, " ")}`).join(`
2461
2489
 
@@ -2536,6 +2564,7 @@ async function board(args) {
2536
2564
  printJson(boardJson(rows.slice(0, limit)));
2537
2565
  return 0;
2538
2566
  }
2567
+ printHeader("ft", "board");
2539
2568
  console.log(rows.length === 0 && (query !== undefined || state !== undefined) ? "no open issue matches" : renderBoard(rows, Date.now(), limit));
2540
2569
  return 0;
2541
2570
  }
@@ -3065,24 +3094,25 @@ async function staleTodos() {
3065
3094
  return [...byIssue.values()];
3066
3095
  }
3067
3096
  function claimLine(row, now) {
3068
- return [`#${row.number}`, row.holder, formatAge(row.since, now), row.boxesTotal === 0 ? "" : `${row.boxesLeft}/${row.boxesTotal} left`, truncate(row.title, TITLE_WIDTH2)];
3097
+ const id = role("id", process22.stdout);
3098
+ return [id(`#${row.number}`), row.holder, paint(process22.stdout).dim(formatAge(row.since, now)), row.boxesTotal === 0 ? "" : `${row.boxesLeft}/${row.boxesTotal} left`, truncate(row.title, TITLE_WIDTH2)];
3069
3099
  }
3070
3100
  function capped2(lines) {
3071
3101
  return lines.length > SHOWN ? [...lines.slice(0, SHOWN), `... ${lines.length - SHOWN} more`] : lines;
3072
3102
  }
3073
3103
  function renderDigest(digest, now = Date.now()) {
3074
3104
  const sections = [
3075
- { heading: "held by this session", count: digest.held.length, lines: table(digest.held.map((row) => claimLine(row, now))).split(`
3105
+ { heading: "held by this session", tone: "running", count: digest.held.length, lines: table(digest.held.map((row) => claimLine(row, now))).split(`
3076
3106
  `) },
3077
- { heading: "claimed, no live session here", count: digest.away.length, lines: table(digest.away.map((row) => claimLine(row, now))).split(`
3107
+ { heading: "claimed, no live session here", tone: "warn", count: digest.away.length, lines: table(digest.away.map((row) => claimLine(row, now))).split(`
3078
3108
  `) },
3079
- { heading: "CI on the default branch", count: digest.ci.length, lines: digest.ci.map((run) => `${run.workflow} ${run.status} (run ${run.id}) ${truncate(upTo(run.title, `
3109
+ { heading: "CI on the default branch", tone: "failed", count: digest.ci.length, lines: digest.ci.map((run) => `${run.workflow} ${badge(run.status, process22.stdout)} (run ${run.id}) ${truncate(upTo(run.title, `
3080
3110
  `), TITLE_WIDTH2)}`) },
3081
- { heading: "unpushed commits", count: digest.unpushed.length, lines: capped2(digest.unpushed) },
3082
- { heading: "dirty files", count: digest.dirty.length, lines: capped2(digest.dirty.map((file) => `${file.status} ${file.path}`)) },
3083
- { heading: "stale TODO comments", count: digest.stale.length, lines: capped2(digest.stale.map((todo) => `${todo.issue} closed: ${todo.comments.map((each) => `${each.path}:${each.line}`).join(", ")}`)) }
3084
- ].filter((section) => section.count > 0);
3085
- return sections.length === 0 ? "nothing to pick up" : sections.map(({ heading, count, lines }) => `${heading} (${count})
3111
+ { heading: "unpushed commits", tone: "queued", count: digest.unpushed.length, lines: capped2(digest.unpushed) },
3112
+ { heading: "dirty files", tone: "warn", count: digest.dirty.length, lines: capped2(digest.dirty.map((file) => `${file.status} ${role("path", process22.stdout)(file.path)}`)) },
3113
+ { heading: "stale TODO comments", tone: "skipped", count: digest.stale.length, lines: capped2(digest.stale.map((todo) => `${todo.issue} closed: ${todo.comments.map((each) => `${each.path}:${each.line}`).join(", ")}`)) }
3114
+ ].filter((each) => each.count > 0);
3115
+ return sections.length === 0 ? "nothing to pick up" : sections.map(({ heading, tone, count, lines }) => `${section(heading, count, process22.stdout, process22.env, tone)}
3086
3116
  ${lines.join(`
3087
3117
  `).replace(LINE_START2, " ")}`).join(`
3088
3118
 
@@ -3111,10 +3141,12 @@ async function digest(args) {
3111
3141
  const rows = issues.map((issue) => ({ issue, claim: latestClaim(comments.get(issue.number) ?? [], author) }));
3112
3142
  const [unpushed, dirty, stale] = await Promise.all([quietly(unpushedCommits), quietly(dirtyTree), staleTodos()]);
3113
3143
  const summary = { ...claims(rows, sessions, me), ci: unsettled(runs, branch), unpushed, dirty, stale };
3114
- if (values.json === true)
3144
+ if (values.json === true) {
3115
3145
  printJson(summary);
3116
- else
3146
+ } else {
3147
+ printHeader("ft", "digest");
3117
3148
  console.log(renderDigest(summary));
3149
+ }
3118
3150
  return 0;
3119
3151
  }
3120
3152
 
@@ -4588,13 +4620,14 @@ async function runs(args) {
4588
4620
  printJson(list.map((run) => ({ id: run.id, number: run.index_in_repo, status: run.status, workflow: run.workflow_id, ref: run.prettyref, event: run.event, sha: run.commit_sha, seconds: runSeconds(run), started: run.started, title: run.title, url: run.html_url })));
4589
4621
  return 0;
4590
4622
  }
4623
+ printHeader("ft", "runs");
4591
4624
  if (list.length === 0) {
4592
4625
  console.log("no run");
4593
4626
  return 0;
4594
4627
  }
4595
4628
  console.log(table([
4596
4629
  ["ID", "STATUS", "WORKFLOW", "REF", "EVENT", "TOOK", "STARTED", "TITLE"],
4597
- ...list.map((run) => [String(run.id), badge(run.status, process.stdout), run.workflow_id, run.prettyref, run.event, run.duration > 0 ? formatSeconds(runSeconds(run)) : "-", startedAge(run), truncate(upTo(run.title, `
4630
+ ...list.map((run) => [hyperlink(String(run.id), run.html_url, process.stdout), badge(run.status, process.stdout), run.workflow_id, run.prettyref, run.event, run.duration > 0 ? formatSeconds(runSeconds(run)) : "-", startedAge(run), truncate(upTo(run.title, `
4598
4631
  `), TITLE_WIDTH4)])
4599
4632
  ], { header: true }));
4600
4633
  if (more > 0)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-forgejo",
3
3
  "type": "module",
4
- "version": "0.21.0",
4
+ "version": "0.23.0",
5
5
  "description": "ft: Forgejo CI runs, logs, releases and issue checklists from the terminal, through tea.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -28,6 +28,6 @@
28
28
  "ft": "$npm_execpath src/cli.ts"
29
29
  },
30
30
  "devDependencies": {
31
- "@kaynooo/cli-kit": "0.27.1"
31
+ "@kaynooo/cli-kit": "0.28.0"
32
32
  }
33
33
  }