@kaynooo/cli-forgejo 0.29.1 → 0.30.2

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 (3) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +479 -140
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -6,7 +6,7 @@ Forgejo tools for the terminal: CI runs and their failures, releases, issue chec
6
6
  bun install -g @kaynooo/cli-forgejo
7
7
  ```
8
8
 
9
- Needs [tea](https://gitea.com/gitea/tea) logged in to the Forgejo instance (`tea login add`). Every call goes through `tea api`, so ft has no token of its own: tea owns the login and finds the repository from origin. Run ft from the repository, or pass `--repo owner/name` to the commands that take it.
9
+ Needs [tea](https://gitea.com/gitea/tea) logged in to the Forgejo instance (`tea login add`), or [gt](https://gitea.com/gitea/gitea-cli) (gitea-cli) when tea is not installed: ft then hands gt the token and host of the matching login in `~/.config/tea/config.yml` through `GITEA_TOKEN` and `GITEA_CLI_HOST` (a `GITEA_TOKEN` already set wins), so no second login is needed, and issues are written through the API. Every call goes through `tea api` (`gt api`), so ft has no token of its own: the client owns the login and finds the repository from origin. Run ft from the repository, or pass `--repo owner/name` to the commands that take it.
10
10
 
11
11
  ## Commands
12
12
 
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/cli.ts
5
- import process29 from "process";
5
+ import process31 from "process";
6
6
  // ../kit/src/args.ts
7
7
  import process10 from "process";
8
8
  import { parseArgs } from "util";
@@ -568,7 +568,7 @@ function formatPercent(ratio, digits = 0) {
568
568
 
569
569
  // ../kit/src/help.ts
570
570
  import process8 from "process";
571
- var OPTIONAL = /\[[^\]]+\]/g;
571
+ var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
572
572
  var USAGE_PREFIX = /^usage:\s*/i;
573
573
  var FULL_STOP = /\.$/;
574
574
  function usageLine(usage, colors = paint(process8.stdout)) {
@@ -607,29 +607,44 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
607
607
  return [];
608
608
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
609
609
  }
610
+ var MAX_INLINE_CHOICES = 24;
610
611
  function optionRows(options, colors = paint(process8.stdout)) {
611
612
  const rows = Object.entries(options).map(([name, option]) => {
612
613
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
613
- const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
614
+ const choices = option.choices?.join("|");
615
+ const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
616
+ const named = inline ? `<${choices}>` : "<value>";
614
617
  const placeholder = option.optional === undefined ? named : `[${named}]`;
615
618
  const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
616
- return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
619
+ const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
620
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
617
621
  });
618
622
  const width = Math.max(0, ...rows.map((row) => row.width));
619
623
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
620
624
  }
621
625
 
622
626
  // ../kit/src/text.ts
623
- var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
627
+ var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
628
+ function stripAnsi(text) {
629
+ return text.replace(ANSI, "");
630
+ }
624
631
  function distance(a, b) {
625
- let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
626
- for (const [i, left] of [...a].entries()) {
632
+ const left = [...a];
633
+ const right = [...b];
634
+ let before = [];
635
+ let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
636
+ for (const [i, x] of left.entries()) {
627
637
  const current = [i + 1];
628
- for (const [j, right] of [...b].entries())
629
- current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
638
+ for (const [j, y] of right.entries()) {
639
+ let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
640
+ if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
641
+ cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
642
+ current.push(cost);
643
+ }
644
+ before = previous;
630
645
  previous = current;
631
646
  }
632
- return previous[b.length] ?? 0;
647
+ return previous[right.length] ?? 0;
633
648
  }
634
649
  function closest(name, names) {
635
650
  const started = names.find((known) => known.startsWith(name));
@@ -721,7 +736,7 @@ class Completing {
721
736
  }
722
737
  var completion = { active: false };
723
738
  var OUTPUT_OPTIONS = {
724
- color: { type: "string", description: "auto (on a terminal alone), always or never" },
739
+ color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
725
740
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
726
741
  };
727
742
  function applyOutput(color, plain, env = process10.env) {
@@ -1352,13 +1367,91 @@ function ciHeader(spinner, label, startedAt, out) {
1352
1367
  // ../kit/src/cli.ts
1353
1368
  import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
1354
1369
  import { dirname as dirname3, join as join5 } from "path";
1355
- import process17 from "process";
1370
+ import process18 from "process";
1371
+
1372
+ // ../kit/src/completions.ts
1373
+ var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
1374
+ var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
1375
+ set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
1376
+ set -l current (commandline -ct)
1377
+ for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
1378
+ if test "$line" = __files__
1379
+ __fish_complete_path $current
1380
+ else
1381
+ echo $line
1382
+ end
1383
+ end
1384
+ end`;
1385
+ var BASH_FUNCTION = `__kaynooo_cli_complete() {
1386
+ local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
1387
+ local -a lines
1388
+ COMPREPLY=()
1389
+ lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
1390
+ for line in "\${lines[@]}"; do
1391
+ if [[ $line == __files__ ]]; then
1392
+ COMPREPLY+=($(compgen -f -- "$cur"))
1393
+ else
1394
+ words+="\${line%%$'\\t'*}"$'\\n'
1395
+ fi
1396
+ done
1397
+ COMPREPLY+=($(compgen -W "$words" -- "$cur"))
1398
+ }`;
1399
+ var ZSH_FUNCTION = `__kaynooo_cli_complete() {
1400
+ local line
1401
+ local -a described plain
1402
+ for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
1403
+ if [[ $line == __files__ ]]; then
1404
+ _files
1405
+ elif [[ $line == *$'\\t'* ]]; then
1406
+ described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
1407
+ else
1408
+ plain+=("$line")
1409
+ fi
1410
+ done
1411
+ (( \${#described} )) && _describe -V value described
1412
+ (( \${#plain} )) && compadd -- "\${plain[@]}"
1413
+ return 0
1414
+ }`;
1415
+ function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
1416
+ if (shell === "fish")
1417
+ return `${header}
1418
+ ${FISH_FUNCTION}
1419
+ ${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
1420
+ `).join("")}`;
1421
+ if (shell === "bash")
1422
+ return `${header}
1423
+ ${BASH_FUNCTION}
1424
+ complete -F __kaynooo_cli_complete ${bins.join(" ")}
1425
+ `;
1426
+ return `${header}
1427
+ ${ZSH_FUNCTION}
1428
+ compdef __kaynooo_cli_complete ${bins.join(" ")}
1429
+ `;
1430
+ }
1431
+
1432
+ // ../kit/src/notify.ts
1433
+ import process16 from "process";
1434
+ var NOTIFY_AFTER_MS = 1e4;
1435
+ var CANCELLED = 130;
1436
+ function base64(text) {
1437
+ return Buffer.from(text).toString("base64");
1438
+ }
1439
+ function notification(title, body, env = process16.env) {
1440
+ const id = `kit${process16.pid}`;
1441
+ const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
1442
+ return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
1443
+ }
1444
+ function notifyEnd(command, code, ms, { stream = process16.stderr, env = process16.env } = {}) {
1445
+ if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
1446
+ return;
1447
+ stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
1448
+ }
1356
1449
 
1357
1450
  // ../kit/src/usage.ts
1358
1451
  import { appendFileSync, mkdirSync } from "fs";
1359
1452
  import { homedir as homedir3 } from "os";
1360
1453
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
1361
- import process16 from "process";
1454
+ import process17 from "process";
1362
1455
 
1363
1456
  // ../kit/src/logs.ts
1364
1457
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -1372,14 +1465,14 @@ var usageError;
1372
1465
  function noteUsageError(message) {
1373
1466
  usageError = message;
1374
1467
  }
1375
- function stateHome(env = process16.env) {
1468
+ function stateHome(env = process17.env) {
1376
1469
  const dir = env.XDG_STATE_HOME;
1377
1470
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
1378
1471
  }
1379
- function usagePath(env = process16.env) {
1472
+ function usagePath(env = process17.env) {
1380
1473
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
1381
1474
  }
1382
- function usageRecorded(env = process16.env) {
1475
+ function usageRecorded(env = process17.env) {
1383
1476
  const off = env.KAYNOOO_CLI_NO_USAGE;
1384
1477
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1385
1478
  }
@@ -1393,7 +1486,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1393
1486
  usageError = undefined;
1394
1487
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1395
1488
  }
1396
- function recordUsage(entry, env = process16.env) {
1489
+ function recordUsage(entry, env = process17.env) {
1397
1490
  if (!usageRecorded(env))
1398
1491
  return;
1399
1492
  try {
@@ -1409,7 +1502,11 @@ var LEVEL_OPTIONS = {
1409
1502
  ...OUTPUT_OPTIONS,
1410
1503
  help: { type: "boolean", short: "h", description: "show this help" }
1411
1504
  };
1412
- var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1505
+ var TOP_OPTIONS = {
1506
+ ...LEVEL_OPTIONS,
1507
+ version: { type: "boolean", short: "v", description: "print the version" },
1508
+ completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
1509
+ };
1413
1510
  async function commandRows(all, colors) {
1414
1511
  const commands = shown(all);
1415
1512
  const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
@@ -1483,8 +1580,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
1483
1580
  `);
1484
1581
  }
1485
1582
  function printError(prefix, message, hint, cause) {
1486
- const colors = paint(process17.stderr);
1487
- const styled = takesControlCodes(process17.stderr);
1583
+ const colors = paint(process18.stderr);
1584
+ const styled = takesControlCodes(process18.stderr);
1488
1585
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1489
1586
  const under = (label, text, tint) => text === undefined ? "" : `
1490
1587
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1494,8 +1591,8 @@ function runHint(command, effect) {
1494
1591
  return `run \`${command}\`${effect === undefined ? "" : ` to ${effect}`}`;
1495
1592
  }
1496
1593
  function printHint(hint) {
1497
- const colors = paint(process17.stderr);
1498
- console.error(` ${takesControlCodes(process17.stderr) ? colors.yellow("hint") : "hint:"} ${hint}`);
1594
+ const colors = paint(process18.stderr);
1595
+ console.error(` ${takesControlCodes(process18.stderr) ? colors.yellow("hint") : "hint:"} ${hint}`);
1499
1596
  }
1500
1597
  function printJsonError(message, hint, cause) {
1501
1598
  console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
@@ -1534,11 +1631,11 @@ async function dispatch(level, typed, { version, redact }) {
1534
1631
  }
1535
1632
  }
1536
1633
  if (name === undefined && level.path.length > 1) {
1537
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process17.stderr));
1634
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process18.stderr));
1538
1635
  return 2;
1539
1636
  }
1540
1637
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
1541
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process17.stdout));
1638
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process18.stdout));
1542
1639
  return 0;
1543
1640
  }
1544
1641
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1649,6 +1746,19 @@ async function candidates(scope, defaultCommand, words, before = []) {
1649
1746
  }
1650
1747
  return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
1651
1748
  }
1749
+ var COMPLETIONS = "--completions";
1750
+ function flagValue([flag = "", ...rest]) {
1751
+ return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
1752
+ }
1753
+ function printCompletionScript(name, args) {
1754
+ const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
1755
+ if (shell === undefined || args.length !== 1) {
1756
+ printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
1757
+ return 2;
1758
+ }
1759
+ console.log(completionScript(shell, [name]).trimEnd());
1760
+ return 0;
1761
+ }
1652
1762
  async function printCandidates(found) {
1653
1763
  for (const line of await found)
1654
1764
  console.log(line);
@@ -1673,10 +1783,15 @@ async function runCli(cli, argv = scriptArgs()) {
1673
1783
  const version = cli.version ?? packageVersion();
1674
1784
  if (argv[0] === COMPLETE)
1675
1785
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
1786
+ if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
1787
+ return printCompletionScript(cli.name, flagValue(argv));
1788
+ const started = performance.now();
1676
1789
  const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
1790
+ const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
1791
+ notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
1677
1792
  if (cli.usage !== false) {
1678
1793
  try {
1679
- recordUsage(usageEntry(cli.name, commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv), argv, code));
1794
+ recordUsage(usageEntry(cli.name, command, argv, code));
1680
1795
  } catch {}
1681
1796
  }
1682
1797
  return code;
@@ -1696,11 +1811,130 @@ function commandPath(scope, argv) {
1696
1811
  }
1697
1812
  return path.length === 0 ? undefined : path.join(" ");
1698
1813
  }
1814
+ // ../kit/src/excerpt.ts
1815
+ var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
1816
+ var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
1817
+ var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
1818
+ var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
1819
+ var TSC_ERROR = /\berror TS\d+/;
1820
+ var TSC_CONTINUATION = /^\s{2,}\S/;
1821
+ var TSC_FRAME = /^\s*[~^|]/;
1822
+ var TSC_SUMMARY = /^Found \d+ errors?/;
1823
+ var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
1824
+ var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
1825
+ var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
1826
+ var PHPSTAN_NOISE = /^\s*\[OK\]/;
1827
+ var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
1828
+ var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
1829
+ var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
1830
+ var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
1831
+ var MAX_LINES = 100;
1832
+ var bunCheck = (lines) => {
1833
+ const text = lines.join(`
1834
+ `);
1835
+ const blocks = text.match(BUN_CHECK_BLOCK);
1836
+ if (blocks === null)
1837
+ return;
1838
+ const errors = blocks.map((block) => {
1839
+ const { file, line, column, code, message } = bunCheckFields(block);
1840
+ return `${file}:${line}:${column} ${code}: ${message}`;
1841
+ });
1842
+ return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
1843
+ };
1844
+ function bunCheckFields(block) {
1845
+ const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
1846
+ `)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
1847
+ return {
1848
+ file: attributes.file ?? "",
1849
+ line: attributes.line ?? "",
1850
+ column: attributes.column ?? "",
1851
+ code: attributes.code ?? "",
1852
+ message: block.replace(BUN_CHECK_SOURCE, "").split(`
1853
+ `).slice(1, -1).join(`
1854
+ `).trim()
1855
+ };
1856
+ }
1857
+ var tsc = (lines) => {
1858
+ const kept = [];
1859
+ let inError = false;
1860
+ for (const line of lines) {
1861
+ if (TSC_ERROR.test(line)) {
1862
+ inError = true;
1863
+ kept.push(line);
1864
+ } else if (TSC_SUMMARY.test(line)) {
1865
+ inError = false;
1866
+ kept.push(line);
1867
+ } else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
1868
+ kept.push(line);
1869
+ } else {
1870
+ inError = false;
1871
+ }
1872
+ }
1873
+ return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
1874
+ };
1875
+ var eslint = (lines) => {
1876
+ const kept = [];
1877
+ let file = "";
1878
+ let shown = "";
1879
+ for (const line of lines) {
1880
+ if (ESLINT_PROBLEM.test(line)) {
1881
+ if (file !== shown) {
1882
+ kept.push(file);
1883
+ shown = file;
1884
+ }
1885
+ kept.push(line);
1886
+ } else if (ESLINT_SUMMARY.test(line)) {
1887
+ kept.push(line);
1888
+ } else if (line.trim() !== "") {
1889
+ file = line;
1890
+ }
1891
+ }
1892
+ return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
1893
+ };
1894
+ var phpstan = (lines) => {
1895
+ const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
1896
+ return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
1897
+ };
1898
+ var vitest = (lines) => {
1899
+ const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
1900
+ return start === -1 ? undefined : lines.slice(start);
1901
+ };
1902
+ var playwright = (lines) => {
1903
+ const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
1904
+ return start === -1 ? undefined : lines.slice(start);
1905
+ };
1906
+ var phpCsFixer = (lines) => {
1907
+ const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
1908
+ return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
1909
+ };
1910
+ var TOOL_PARSERS = [bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan];
1911
+ function squeeze(lines) {
1912
+ const out = [];
1913
+ for (const line of lines.map((text) => text.trimEnd())) {
1914
+ if (line !== "" || out.at(-1) !== "")
1915
+ out.push(line);
1916
+ }
1917
+ while (out.at(-1) === "")
1918
+ out.pop();
1919
+ return out;
1920
+ }
1921
+ function cut(shown) {
1922
+ return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
1923
+ `) : shown.join(`
1924
+ `);
1925
+ }
1926
+ function recognised(lines, parsers) {
1927
+ return parsers.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
1928
+ }
1929
+ function toolExcerpt(lines) {
1930
+ const found = recognised(lines.map((line) => stripAnsi(line)), TOOL_PARSERS);
1931
+ return found === undefined ? undefined : cut(squeeze(found));
1932
+ }
1699
1933
  // ../kit/src/folders.ts
1700
1934
  var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
1701
1935
  // ../kit/src/git.ts
1702
1936
  import { basename, dirname as dirname4 } from "path";
1703
- import process18 from "process";
1937
+ import process19 from "process";
1704
1938
  var ORIGIN_PREFIX = /^origin\//;
1705
1939
  var GIT_NETWORK_MS = 60000;
1706
1940
  async function git(args, timeoutMs) {
@@ -1730,7 +1964,7 @@ async function defaultBranch() {
1730
1964
  async function leaveWorktree() {
1731
1965
  const common = await git(["rev-parse", "--path-format=absolute", "--git-common-dir"]);
1732
1966
  if (basename(common) === ".git")
1733
- process18.chdir(dirname4(common));
1967
+ process19.chdir(dirname4(common));
1734
1968
  }
1735
1969
  // ../kit/src/limit.ts
1736
1970
  function limitOptions(fallback) {
@@ -1771,15 +2005,15 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
1771
2005
  // ../kit/src/sessions.ts
1772
2006
  import { homedir as homedir4 } from "os";
1773
2007
  import { join as join6 } from "path";
1774
- import process19 from "process";
2008
+ import process20 from "process";
1775
2009
  var {Glob } = globalThis.Bun;
1776
2010
  var SESSION_FILES = new Glob("*.json");
1777
2011
  var ACCOUNT_DIRS = new Glob("*/sessions");
1778
2012
  async function sessionDirs() {
1779
2013
  const home = homedir4();
1780
2014
  const dirs = new Set([join6(home, ".claude", "sessions")]);
1781
- if (process19.env.CLAUDE_CONFIG_DIR !== undefined)
1782
- dirs.add(join6(process19.env.CLAUDE_CONFIG_DIR, "sessions"));
2015
+ if (process20.env.CLAUDE_CONFIG_DIR !== undefined)
2016
+ dirs.add(join6(process20.env.CLAUDE_CONFIG_DIR, "sessions"));
1783
2017
  try {
1784
2018
  for await (const dir of ACCOUNT_DIRS.scan({ cwd: join6(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
1785
2019
  dirs.add(dir);
@@ -1825,7 +2059,7 @@ async function liveSessions() {
1825
2059
  }
1826
2060
  async function currentSession(sessions) {
1827
2061
  const byPid = new Map(sessions.map((session) => [session.pid, session]));
1828
- let pid = process19.ppid;
2062
+ let pid = process20.ppid;
1829
2063
  for (let depth = 0;depth < 32 && pid > 1; depth++) {
1830
2064
  const session = byPid.get(pid);
1831
2065
  if (session !== undefined)
@@ -1838,7 +2072,7 @@ async function currentSession(sessions) {
1838
2072
  return;
1839
2073
  }
1840
2074
  // ../kit/src/watch.ts
1841
- import process20 from "process";
2075
+ import process21 from "process";
1842
2076
  import { format } from "util";
1843
2077
  var CLEAR_SCREEN = "\x1B[H\x1B[2J";
1844
2078
  var DEFAULT_SECONDS = 2;
@@ -1860,7 +2094,7 @@ function withoutWatch(args) {
1860
2094
  }
1861
2095
  return rest;
1862
2096
  }
1863
- async function watching(value, step, stream = process20.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
2097
+ async function watching(value, step, stream = process21.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1864
2098
  const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
1865
2099
  if (!takesControlCodes(stream))
1866
2100
  badUsage("--watch redraws the screen, so it needs a terminal");
@@ -1868,12 +2102,12 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
1868
2102
  for (let round = 0;round < rounds; round++) {
1869
2103
  const held = [];
1870
2104
  const { log, info } = console;
1871
- const write = process20.stdout.write.bind(process20.stdout);
2105
+ const write = process21.stdout.write.bind(process21.stdout);
1872
2106
  const hold = (...parts) => void held.push(`${format(...parts)}
1873
2107
  `);
1874
2108
  console.log = hold;
1875
2109
  console.info = hold;
1876
- process20.stdout.write = (text) => {
2110
+ process21.stdout.write = (text) => {
1877
2111
  held.push(typeof text === "string" ? text : Buffer.from(text).toString());
1878
2112
  return true;
1879
2113
  };
@@ -1882,7 +2116,7 @@ async function watching(value, step, stream = process20.stdout, sleep = Bun.slee
1882
2116
  } finally {
1883
2117
  console.log = log;
1884
2118
  console.info = info;
1885
- process20.stdout.write = write;
2119
+ process21.stdout.write = write;
1886
2120
  }
1887
2121
  stream.write(`${CLEAR_SCREEN}${held.join("")}`);
1888
2122
  await sleep(interval);
@@ -2060,9 +2294,9 @@ function holderSession(holder, sessions) {
2060
2294
  }
2061
2295
 
2062
2296
  // src/good.ts
2063
- import process22 from "process";
2297
+ import process23 from "process";
2064
2298
  function good(text) {
2065
- return role("ok", process22.stdout)(text);
2299
+ return role("ok", process23.stdout)(text);
2066
2300
  }
2067
2301
 
2068
2302
  // src/config.ts
@@ -2094,10 +2328,13 @@ async function loadSettings(home) {
2094
2328
  return typeof host === "string" && host !== "" ? { remoteHost: host } : {};
2095
2329
  }
2096
2330
 
2331
+ // src/tea.ts
2332
+ import process25 from "process";
2333
+
2097
2334
  // src/forge.ts
2098
2335
  import { homedir as homedir5 } from "os";
2099
2336
  import { join as join7 } from "path";
2100
- import process23 from "process";
2337
+ import process24 from "process";
2101
2338
 
2102
2339
  // src/remote.ts
2103
2340
  var SCP_LIKE = /^(?:([^@/]+)@)?([^:/]+):(?!\/)(.+?)(?:\.git)?\/?$/;
@@ -2136,6 +2373,8 @@ async function reachesHost(hostname, host, hostAddresses, addressesOf) {
2136
2373
  // src/forge.ts
2137
2374
  var LOGIN_HOST = /^\s*(?:-\s*)?(?:url|ssh_host):\s*["']?([^\s"']+)/gm;
2138
2375
  var PORT = /:\d+$/;
2376
+ var LOGIN_LINE = /^\s*(-\s+)?([a-z_]+):(.*)$/;
2377
+ var QUOTES = /^["']|["']$/g;
2139
2378
  var SCP_REMOTE = /^(?:[^@/\s]+@)?([^:/\s]+):(?!\/\/)/;
2140
2379
  var URL_REMOTE = /^[a-z+]+:\/\/(?:[^@/\s]+@)?(\[[^\]]+\]|[^:/\s]+)/i;
2141
2380
  function originHost(remote) {
@@ -2152,7 +2391,7 @@ function loginHosts(config) {
2152
2391
  return hosts;
2153
2392
  }
2154
2393
  function teaConfigPath() {
2155
- const base = process23.env.XDG_CONFIG_HOME;
2394
+ const base = process24.env.XDG_CONFIG_HOME;
2156
2395
  return join7(base !== undefined && base !== "" ? base : join7(homedir5(), ".config"), "tea", "config.yml");
2157
2396
  }
2158
2397
  async function readConfig() {
@@ -2171,35 +2410,105 @@ async function requireForgeOrigin() {
2171
2410
  const origin = await runTool("git remote get-url origin", ["git", "remote", "get-url", "origin"], { timeoutMs: 5000 });
2172
2411
  const host = origin.code === 0 ? originHost(origin.stdout) : undefined;
2173
2412
  if (host !== undefined && !hosts.has(host))
2174
- fail(`origin ${redactUrl(origin.stdout.trim())} is not on a Forgejo tea is logged in to (${[...hosts].join(", ")})`, 2, "name the repository with -r owner/name, or run ft in a repository hosted there (an ssh alias origin: ft remote --fix)");
2413
+ fail(`origin ${redactUrl(origin.stdout.trim())} is not on a Forgejo you are logged in to (${[...hosts].join(", ")})`, 2, "name the repository with -r owner/name, or run ft in a repository hosted there (an ssh alias origin: ft remote --fix)");
2175
2414
  })();
2176
2415
  return checked;
2177
2416
  }
2417
+ function teaLogins(config) {
2418
+ const logins = [];
2419
+ let current;
2420
+ const finish = () => {
2421
+ if (current?.url !== undefined && current.token !== undefined && current.token !== "")
2422
+ logins.push({ url: current.url, token: current.token, isDefault: current.default === "true" });
2423
+ };
2424
+ for (const line of config.split(`
2425
+ `)) {
2426
+ const entry = LOGIN_LINE.exec(line);
2427
+ if (entry === null)
2428
+ continue;
2429
+ if (entry[1] !== undefined) {
2430
+ finish();
2431
+ current = {};
2432
+ }
2433
+ if (current !== undefined)
2434
+ current[entry[2]] = (entry[3] ?? "").trim().replace(QUOTES, "");
2435
+ }
2436
+ finish();
2437
+ return logins;
2438
+ }
2439
+ async function pickLogin(useOrigin) {
2440
+ const logins = teaLogins(await readConfig());
2441
+ if (useOrigin) {
2442
+ const origin = await runTool("git remote get-url origin", ["git", "remote", "get-url", "origin"], { timeoutMs: 5000 });
2443
+ const host = origin.code === 0 ? originHost(origin.stdout) : undefined;
2444
+ const match = host === undefined ? undefined : logins.find((each) => URL.canParse(each.url) && new URL(each.url).hostname.toLowerCase() === host);
2445
+ if (match !== undefined)
2446
+ return match;
2447
+ }
2448
+ return logins.find((each) => each.isDefault) ?? logins[0];
2449
+ }
2178
2450
 
2179
2451
  // src/tea.ts
2180
2452
  var TEA_MS = 60000;
2181
2453
  function repoFlag(repo) {
2182
2454
  return repo === undefined ? [] : ["--repo", repo];
2183
2455
  }
2184
- async function request(path, repo) {
2456
+ function usesGt() {
2457
+ const PATH = process25.env.PATH ?? "";
2458
+ return Bun.which("tea", { PATH }) === null && Bun.which("gt", { PATH }) !== null;
2459
+ }
2460
+ var injected;
2461
+ async function injectLogin(repo) {
2462
+ if (process25.env.GITEA_TOKEN !== undefined && process25.env.GITEA_TOKEN !== "")
2463
+ return;
2464
+ const login = await pickLogin(repo === undefined);
2465
+ if (login === undefined)
2466
+ return;
2467
+ injected = login.token;
2468
+ process25.env.GITEA_TOKEN = login.token;
2469
+ process25.env.GITEA_CLI_HOST = login.url;
2470
+ }
2471
+ function scrub(text) {
2472
+ const token = injected ?? process25.env.GITEA_TOKEN;
2473
+ return token === undefined || token === "" ? text : text.replaceAll(token, "***");
2474
+ }
2475
+ function failureText(stdout, stderr, code) {
2476
+ try {
2477
+ const value = JSON.parse(stdout);
2478
+ if (value !== null && typeof value === "object" && "message" in value && typeof value.message === "string")
2479
+ return scrub(value.message);
2480
+ } catch {}
2481
+ return scrub(stderr.trim() || stdout.trim() || `exit ${code}`);
2482
+ }
2483
+ async function runApi(label, args, repo) {
2185
2484
  if (repo === undefined)
2186
2485
  await requireForgeOrigin();
2187
- const result = await runTool(`tea api ${path}`, ["tea", "api", ...repoFlag(repo), path], { timeoutMs: TEA_MS });
2486
+ const gt = usesGt();
2487
+ const bin = gt ? "gt" : "tea";
2488
+ if (gt)
2489
+ await injectLogin(repo);
2490
+ const result = await runTool(`${bin} api ${label}`, [bin, "api", ...repoFlag(repo), ...args], { timeoutMs: TEA_MS });
2188
2491
  if (result.code !== 0)
2189
- throw new Error(`tea api ${path}: ${result.stderr.trim() || `exit ${result.code}`}`);
2190
- return result.stdout;
2492
+ throw new Error(`${bin} api ${label}: ${gt ? failureText(result.stdout, result.stderr, result.code) : result.stderr.trim() || `exit ${result.code}`}`);
2493
+ return gt ? scrub(result.stdout) : result.stdout;
2494
+ }
2495
+ async function request(path, repo) {
2496
+ return runApi(path, [path], repo);
2497
+ }
2498
+ function clientName() {
2499
+ return usesGt() ? "gt" : "tea";
2191
2500
  }
2192
2501
  function parseJson(path, text) {
2193
2502
  let value;
2194
2503
  try {
2195
2504
  value = JSON.parse(text);
2196
2505
  } catch {
2197
- throw new Error(`tea api ${path}: ${upTo(text.trim(), `
2506
+ throw new Error(`${clientName()} api ${path}: ${upTo(text.trim(), `
2198
2507
  `) || "empty answer"}`);
2199
2508
  }
2200
2509
  const failure = apiError(value);
2201
2510
  if (failure !== undefined)
2202
- throw new Error(`tea api ${path}: ${failure}`);
2511
+ throw new Error(`${clientName()} api ${path}: ${failure}`);
2203
2512
  return value;
2204
2513
  }
2205
2514
  function apiError(value) {
@@ -2213,15 +2522,13 @@ async function api(path, repo) {
2213
2522
  async function repoApi(path, repo) {
2214
2523
  return api(`repos/{owner}/{repo}/${path}`, repo);
2215
2524
  }
2216
- async function repoWrite(method, path, fields, repo) {
2525
+ async function repoSend(method, path, fields, repo) {
2217
2526
  const full = `repos/{owner}/{repo}/${path}`;
2218
- const flags = Object.entries(fields).flatMap(([name, value]) => ["-f", `${name}=${value}`]);
2219
- if (repo === undefined)
2220
- await requireForgeOrigin();
2221
- const result = await runTool(`tea api ${full}`, ["tea", "api", ...repoFlag(repo), "-X", method, ...flags, full], { timeoutMs: TEA_MS });
2222
- if (result.code !== 0)
2223
- throw new Error(`tea api ${full}: ${result.stderr.trim() || `exit ${result.code}`}`);
2224
- return parseJson(full, result.stdout);
2527
+ const flags = Object.entries(fields).flatMap(([name, value]) => typeof value === "string" ? ["-f", `${name}=${value}`] : ["-F", `${name}=${JSON.stringify(value)}`]);
2528
+ return runApi(full, ["-X", method, ...flags, full], repo);
2529
+ }
2530
+ async function repoWrite(method, path, fields, repo) {
2531
+ return parseJson(`repos/{owner}/{repo}/${path}`, await repoSend(method, path, fields, repo));
2225
2532
  }
2226
2533
  async function repoApiText(path, repo) {
2227
2534
  const full = `repos/{owner}/{repo}/${path}`;
@@ -2234,7 +2541,7 @@ async function repoApiText(path, repo) {
2234
2541
  }
2235
2542
  const failure = apiError(value);
2236
2543
  if (failure !== undefined)
2237
- throw new Error(`tea api ${full}: ${failure}`);
2544
+ throw new Error(`${clientName()} api ${full}: ${failure}`);
2238
2545
  return text;
2239
2546
  }
2240
2547
  async function tea(command, args, repo) {
@@ -2246,8 +2553,56 @@ async function tea(command, args, repo) {
2246
2553
  return result.stdout;
2247
2554
  }
2248
2555
 
2249
- // src/issues.ts
2556
+ // src/milestones.ts
2250
2557
  var PAGE = 50;
2558
+ var DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
2559
+ var NO_DUE_YEAR = 9999;
2560
+ async function listMilestones(state, repo) {
2561
+ const found = [];
2562
+ for (let page = 1;; page++) {
2563
+ const batch = await repoApi(`milestones?state=${state}&page=${page}&limit=${PAGE}`, repo);
2564
+ found.push(...batch);
2565
+ if (batch.length < PAGE)
2566
+ return found;
2567
+ }
2568
+ }
2569
+ async function findMilestone(reference, repo) {
2570
+ const all = await listMilestones("all", repo);
2571
+ const found = all.find((each) => each.title === reference) ?? all.find((each) => String(each.id) === reference);
2572
+ if (found === undefined)
2573
+ fail(`no milestone ${reference}, ${all.length === 0 ? "the repository has none" : `it has: ${all.map((each) => each.title).join(", ")}`}`, 2, runHint(`ft milestone new ${reference}`, "create it"));
2574
+ return found;
2575
+ }
2576
+ function dueOn(value) {
2577
+ const match = DATE.exec(value);
2578
+ const date = new Date(`${value}T00:00:00Z`);
2579
+ if (match === null || Number.isNaN(date.getTime()) || date.toISOString().slice(0, 10) !== value || date.getUTCFullYear() < 2000)
2580
+ fail(`--due takes a date as YYYY-MM-DD, not ${value}`);
2581
+ return date.toISOString();
2582
+ }
2583
+ function dueDate(milestone) {
2584
+ if (milestone.due_on === null || new Date(milestone.due_on).getUTCFullYear() >= NO_DUE_YEAR)
2585
+ return "";
2586
+ return milestone.due_on.slice(0, 10);
2587
+ }
2588
+ function progress(milestone) {
2589
+ const total = milestone.open_issues + milestone.closed_issues;
2590
+ return total === 0 ? "" : `${Math.round(milestone.closed_issues / total * 100)}%`;
2591
+ }
2592
+ async function createMilestone(title, description, due, repo) {
2593
+ const fields = { title };
2594
+ if (description !== undefined)
2595
+ fields.description = description;
2596
+ if (due !== undefined)
2597
+ fields.due_on = due;
2598
+ return repoWrite("POST", "milestones", fields, repo);
2599
+ }
2600
+ async function closeMilestone(id, repo) {
2601
+ await repoWrite("PATCH", `milestones/${id}`, { state: "closed" }, repo);
2602
+ }
2603
+
2604
+ // src/issues.ts
2605
+ var PAGE2 = 50;
2251
2606
  var CONCURRENCY = 8;
2252
2607
  async function getIssue(number, repo) {
2253
2608
  return repoApi(`issues/${number}`, repo);
@@ -2255,9 +2610,9 @@ async function getIssue(number, repo) {
2255
2610
  async function listIssues(state, filter, repo) {
2256
2611
  const issues = [];
2257
2612
  for (let page = 1;; page++) {
2258
- const batch = await repoApi(`issues?state=${state}&type=issues&page=${page}&limit=${PAGE}${filter}`, repo);
2613
+ const batch = await repoApi(`issues?state=${state}&type=issues&page=${page}&limit=${PAGE2}${filter}`, repo);
2259
2614
  issues.push(...batch);
2260
- if (batch.length < PAGE)
2615
+ if (batch.length < PAGE2)
2261
2616
  return issues;
2262
2617
  }
2263
2618
  }
@@ -2276,6 +2631,10 @@ async function commentsOfAll(issues, repo) {
2276
2631
  return new Map(commented.map((issue, index) => [issue.number, comments[index]]));
2277
2632
  }
2278
2633
  async function editIssue(number, change, repo) {
2634
+ if (usesGt()) {
2635
+ await repoWrite("PATCH", `issues/${number}`, { ...change.title === undefined ? {} : { title: change.title }, ...change.body === undefined ? {} : { body: change.body }, ...change.milestone === undefined ? {} : { milestone: await milestoneId(change.milestone, repo) } }, repo);
2636
+ return;
2637
+ }
2279
2638
  const args = [String(number)];
2280
2639
  if (change.title !== undefined)
2281
2640
  args.push("-t", change.title);
@@ -2289,6 +2648,9 @@ async function setBody(number, body, repo) {
2289
2648
  await editIssue(number, { body }, repo);
2290
2649
  }
2291
2650
  async function createIssue(title, body, labels, milestone, repo) {
2651
+ if (usesGt()) {
2652
+ return repoWrite("POST", "issues", { title, body, ...labels === undefined ? {} : { labels: await labelIds(labels.split(","), repo) }, ...milestone === undefined ? {} : { milestone: await milestoneId(milestone, repo) } }, repo);
2653
+ }
2292
2654
  const args = ["-t", title, "-d", body];
2293
2655
  const same = (found) => found.title === title && sameText(found.body, body);
2294
2656
  const known = new Set((await openIssues(undefined, repo)).filter(same).map((found) => found.number));
@@ -2341,21 +2703,32 @@ async function comment(number, body, repo) {
2341
2703
  await repoWrite("POST", `issues/${number}/comments`, { body }, repo);
2342
2704
  }
2343
2705
  async function close(number, repo) {
2706
+ if (usesGt())
2707
+ return void await repoWrite("PATCH", `issues/${number}`, { state: "closed" }, repo);
2344
2708
  await tea(["issues", "close"], [String(number)], repo);
2345
2709
  }
2346
2710
  async function reopen(number, repo) {
2711
+ if (usesGt())
2712
+ return void await repoWrite("PATCH", `issues/${number}`, { state: "open" }, repo);
2347
2713
  await tea(["issues", "reopen"], [String(number)], repo);
2348
2714
  }
2349
2715
  async function repoLabels(repo) {
2350
2716
  const names = [];
2351
2717
  for (let page = 1;; page++) {
2352
- const batch = await repoApi(`labels?page=${page}&limit=${PAGE}`, repo);
2718
+ const batch = await repoApi(`labels?page=${page}&limit=${PAGE2}`, repo);
2353
2719
  names.push(...batch.map((each) => each.name));
2354
- if (batch.length < PAGE)
2720
+ if (batch.length < PAGE2)
2355
2721
  return names;
2356
2722
  }
2357
2723
  }
2358
2724
  async function editLabels(number, add, remove, repo) {
2725
+ if (usesGt()) {
2726
+ if (add.length > 0)
2727
+ await repoSend("POST", `issues/${number}/labels`, { labels: await labelIds(add, repo) }, repo);
2728
+ for (const id of await labelIds(remove, repo))
2729
+ await repoSend("DELETE", `issues/${number}/labels/${id}`, {}, repo);
2730
+ return;
2731
+ }
2359
2732
  const args = [String(number)];
2360
2733
  if (add.length > 0)
2361
2734
  args.push("--add-labels", add.join(","));
@@ -2363,53 +2736,23 @@ async function editLabels(number, add, remove, repo) {
2363
2736
  args.push("--remove-labels", remove.join(","));
2364
2737
  await tea(["issues", "edit"], args, repo);
2365
2738
  }
2366
-
2367
- // src/milestones.ts
2368
- var PAGE2 = 50;
2369
- var DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
2370
- var NO_DUE_YEAR = 9999;
2371
- async function listMilestones(state, repo) {
2372
- const found = [];
2739
+ async function labelIds(names, repo) {
2740
+ const all = [];
2373
2741
  for (let page = 1;; page++) {
2374
- const batch = await repoApi(`milestones?state=${state}&page=${page}&limit=${PAGE2}`, repo);
2375
- found.push(...batch);
2742
+ const batch = await repoApi(`labels?page=${page}&limit=${PAGE2}`, repo);
2743
+ all.push(...batch);
2376
2744
  if (batch.length < PAGE2)
2377
- return found;
2745
+ break;
2378
2746
  }
2747
+ return names.map((name) => name.trim()).filter((name) => name !== "").map((name) => {
2748
+ const found = all.find((each) => each.name === name);
2749
+ if (found === undefined)
2750
+ throw new Error(`no label ${name}, the repository has: ${all.map((each) => each.name).join(", ")}`);
2751
+ return found.id;
2752
+ });
2379
2753
  }
2380
- async function findMilestone(reference, repo) {
2381
- const all = await listMilestones("all", repo);
2382
- const found = all.find((each) => each.title === reference) ?? all.find((each) => String(each.id) === reference);
2383
- if (found === undefined)
2384
- fail(`no milestone ${reference}, ${all.length === 0 ? "the repository has none" : `it has: ${all.map((each) => each.title).join(", ")}`}`, 2, runHint(`ft milestone new ${reference}`, "create it"));
2385
- return found;
2386
- }
2387
- function dueOn(value) {
2388
- const match = DATE.exec(value);
2389
- const date = new Date(`${value}T00:00:00Z`);
2390
- if (match === null || Number.isNaN(date.getTime()) || date.toISOString().slice(0, 10) !== value || date.getUTCFullYear() < 2000)
2391
- fail(`--due takes a date as YYYY-MM-DD, not ${value}`);
2392
- return date.toISOString();
2393
- }
2394
- function dueDate(milestone) {
2395
- if (milestone.due_on === null || new Date(milestone.due_on).getUTCFullYear() >= NO_DUE_YEAR)
2396
- return "";
2397
- return milestone.due_on.slice(0, 10);
2398
- }
2399
- function progress(milestone) {
2400
- const total = milestone.open_issues + milestone.closed_issues;
2401
- return total === 0 ? "" : `${Math.round(milestone.closed_issues / total * 100)}%`;
2402
- }
2403
- async function createMilestone(title, description, due, repo) {
2404
- const fields = { title };
2405
- if (description !== undefined)
2406
- fields.description = description;
2407
- if (due !== undefined)
2408
- fields.due_on = due;
2409
- return repoWrite("POST", "milestones", fields, repo);
2410
- }
2411
- async function closeMilestone(id, repo) {
2412
- await repoWrite("PATCH", `milestones/${id}`, { state: "closed" }, repo);
2754
+ async function milestoneId(title, repo) {
2755
+ return title === "" ? 0 : (await findMilestone(title, repo)).id;
2413
2756
  }
2414
2757
 
2415
2758
  // src/commands/board.ts
@@ -2422,7 +2765,6 @@ function standing(claim, sessions) {
2422
2765
  return session === undefined ? { state: "away", claim } : { state: "taken", claim, session };
2423
2766
  }
2424
2767
  var NOTE_WIDTH = 100;
2425
- var STATES = new Set(["available", "taken", "away"]);
2426
2768
  function dimmed(text) {
2427
2769
  return text === "" ? "" : paint(process.stdout).dim(text);
2428
2770
  }
@@ -2511,7 +2853,7 @@ var boardOptions = {
2511
2853
  labels: { type: "string", short: "L", description: "only issues with these labels, comma separated" },
2512
2854
  milestone: { type: "string", short: "m", description: "only issues of this milestone, a title or an id" },
2513
2855
  query: { type: "string", description: "only issues whose title matches this, a case-insensitive regex such as dom|eager" },
2514
- state: { type: "string", description: "only issues in this state: available, taken or away (claimed, no live session here)" },
2856
+ state: { type: "string", choices: ["available", "taken", "away"], description: "only issues in this state (away: claimed, no live session here)" },
2515
2857
  ...limitOptions(BOARD_LIMIT),
2516
2858
  json: jsonOption("number, title, labels, state, holder, since, session, boxesTotal, boxesLeft and note (author, at, body of the latest comment that is not a claim)"),
2517
2859
  watch: watchOption("the board"),
@@ -2524,8 +2866,6 @@ async function board(args) {
2524
2866
  return watching(values.watch, async () => board(withoutWatch(args)));
2525
2867
  const state = values.state;
2526
2868
  const limit = limitOf(values, BOARD_LIMIT);
2527
- if (state !== undefined && !STATES.has(state))
2528
- fail(`--state takes available, taken or away, not ${state}`);
2529
2869
  let query;
2530
2870
  try {
2531
2871
  query = values.query === undefined ? undefined : new RegExp(values.query, "i");
@@ -2685,7 +3025,7 @@ async function drop(args) {
2685
3025
  }
2686
3026
 
2687
3027
  // src/commands/ci.ts
2688
- import process24 from "process";
3028
+ import process26 from "process";
2689
3029
 
2690
3030
  // src/git.ts
2691
3031
  async function tagsAt(commit) {
@@ -2711,6 +3051,7 @@ var STAMP = /^\S+Z /;
2711
3051
  var FAILED_STEP = /\u274C\s+Failure - Main /;
2712
3052
  var STEP_TAIL = 30;
2713
3053
  var TAIL = 40;
3054
+ var TOOL_WINDOW = 200;
2714
3055
  function logLines(log) {
2715
3056
  return log.split(`
2716
3057
  `).map((line) => line.replace(STAMP, ""));
@@ -2736,7 +3077,7 @@ function excerpt(log) {
2736
3077
  const parts = failedTests(lines);
2737
3078
  for (const [index, line] of lines.entries()) {
2738
3079
  if (FAILED_STEP.test(line))
2739
- parts.push(lines.slice(Math.max(0, index - STEP_TAIL), index + 1).filter((text) => text.trim() !== "" && !text.startsWith(PASS) && !text.startsWith("::")).join(`
3080
+ parts.push(toolExcerpt(lines.slice(Math.max(0, index - TOOL_WINDOW), index)) ?? lines.slice(Math.max(0, index - STEP_TAIL), index + 1).filter((text) => text.trim() !== "" && !text.startsWith(PASS) && !text.startsWith("::")).join(`
2740
3081
  `));
2741
3082
  }
2742
3083
  return parts.length === 0 ? lines.slice(-TAIL).join(`
@@ -2864,7 +3205,7 @@ async function failedJobsOf(run, repo) {
2864
3205
  }
2865
3206
  return failed;
2866
3207
  }
2867
- function failureText(failed, out = process.stderr) {
3208
+ function failureText2(failed, out = process.stderr) {
2868
3209
  const problem = role("failed", out);
2869
3210
  return failed.map((job) => `${problem(`job ${job.name} of ${job.workflow} failed`)}:
2870
3211
  ${job.excerpt}`).join(`
@@ -2951,7 +3292,7 @@ async function ci2(args) {
2951
3292
  return;
2952
3293
  }
2953
3294
  const json = values.json === true;
2954
- const live = takesControlCodes(process24.stderr) && takesControlCodes(process24.stdout) && !json && values.quiet !== true;
3295
+ const live = takesControlCodes(process26.stderr) && takesControlCodes(process26.stdout) && !json && values.quiet !== true;
2955
3296
  const runs = await waitForCi({
2956
3297
  tool: "ft ci",
2957
3298
  short,
@@ -2977,8 +3318,8 @@ async function ci2(args) {
2977
3318
  return stall === undefined ? undefined : { message: `runs queued on ${short} are not moving: ${stall.reason}`, certain: stall.certain };
2978
3319
  },
2979
3320
  lines: (spinner, found, started) => [
2980
- ciHeader(spinner, `CI on ${short}`, started, process24.stderr),
2981
- ...(found ?? []).map((run) => ` ${runLine(run, process24.stderr, undefined, run.commit_sha.slice(0, 7))}`)
3321
+ ciHeader(spinner, `CI on ${short}`, started, process26.stderr),
3322
+ ...(found ?? []).map((run) => ` ${runLine(run, process26.stderr, undefined, run.commit_sha.slice(0, 7))}`)
2982
3323
  ]
2983
3324
  });
2984
3325
  const status = overall(runs);
@@ -2995,7 +3336,7 @@ async function ci2(args) {
2995
3336
  }
2996
3337
  if (live) {
2997
3338
  for (const run of runs)
2998
- console.log(runLine(run, process24.stdout, undefined, run.commit_sha.slice(0, 7)));
3339
+ console.log(runLine(run, process26.stdout, undefined, run.commit_sha.slice(0, 7)));
2999
3340
  }
3000
3341
  if (status !== "failure") {
3001
3342
  if (live)
@@ -3006,7 +3347,7 @@ async function ci2(args) {
3006
3347
  for (const run of runs) {
3007
3348
  if (run.status === "failure")
3008
3349
  console.error(`
3009
- ${failureText(failed.filter((job) => job.run === run.id))}
3350
+ ${failureText2(failed.filter((job) => job.run === run.id))}
3010
3351
 
3011
3352
  run ${run.id} failed${run.commit_sha === sha ? "" : `, testing every commit from ${short} to ${run.commit_sha.slice(0, 7)}`}: ${run.html_url}`);
3012
3353
  }
@@ -3014,7 +3355,7 @@ run ${run.id} failed${run.commit_sha === sha ? "" : `, testing every commit from
3014
3355
  }
3015
3356
 
3016
3357
  // src/commands/digest.ts
3017
- import process25 from "process";
3358
+ import process27 from "process";
3018
3359
  var RUNS_SCANNED = 50;
3019
3360
  var TITLE_WIDTH2 = 70;
3020
3361
  var SHOWN = 8;
@@ -3064,7 +3405,7 @@ async function quietly(read) {
3064
3405
  }
3065
3406
  }
3066
3407
  async function staleTodos() {
3067
- const bin = Bun.which("todo-scan", { PATH: process25.env.PATH ?? "" });
3408
+ const bin = Bun.which("todo-scan", { PATH: process27.env.PATH ?? "" });
3068
3409
  if (bin === null)
3069
3410
  return [];
3070
3411
  let found;
@@ -3086,8 +3427,8 @@ async function staleTodos() {
3086
3427
  return [...byIssue.values()];
3087
3428
  }
3088
3429
  function claimLine(row, now) {
3089
- const id = role("id", process25.stdout);
3090
- return [id(`#${row.number}`), row.holder, paint(process25.stdout).dim(formatAge(row.since, now)), row.boxesTotal === 0 ? "" : `${row.boxesLeft}/${row.boxesTotal} left`, truncate(row.title, TITLE_WIDTH2)];
3430
+ const id = role("id", process27.stdout);
3431
+ return [id(`#${row.number}`), row.holder, paint(process27.stdout).dim(formatAge(row.since, now)), row.boxesTotal === 0 ? "" : `${row.boxesLeft}/${row.boxesTotal} left`, truncate(row.title, TITLE_WIDTH2)];
3091
3432
  }
3092
3433
  function capped2(lines) {
3093
3434
  return lines.length > SHOWN ? [...lines.slice(0, SHOWN), `... ${lines.length - SHOWN} more`] : lines;
@@ -3098,13 +3439,13 @@ function renderDigest(digest, now = Date.now()) {
3098
3439
  `) },
3099
3440
  { heading: "claimed, no live session here", tone: "warn", count: digest.away.length, lines: table(digest.away.map((row) => claimLine(row, now))).split(`
3100
3441
  `) },
3101
- { heading: "CI on the default branch", tone: "failed", count: digest.ci.length, lines: digest.ci.map((run) => `${run.workflow} ${badge(run.status, process25.stdout)} (run ${run.id}) ${truncate(upTo(run.title, `
3442
+ { heading: "CI on the default branch", tone: "failed", count: digest.ci.length, lines: digest.ci.map((run) => `${run.workflow} ${badge(run.status, process27.stdout)} (run ${run.id}) ${truncate(upTo(run.title, `
3102
3443
  `), TITLE_WIDTH2)}`) },
3103
3444
  { heading: "unpushed commits", tone: "queued", count: digest.unpushed.length, lines: capped2(digest.unpushed) },
3104
- { heading: "dirty files", tone: "warn", count: digest.dirty.length, lines: capped2(digest.dirty.map((file) => `${file.status} ${role("path", process25.stdout)(file.path)}`)) },
3445
+ { heading: "dirty files", tone: "warn", count: digest.dirty.length, lines: capped2(digest.dirty.map((file) => `${file.status} ${role("path", process27.stdout)(file.path)}`)) },
3105
3446
  { 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(", ")}`)) }
3106
3447
  ].filter((each) => each.count > 0);
3107
- return sections.length === 0 ? "nothing to pick up" : sections.map(({ heading, tone, count, lines }) => `${section(heading, count, process25.stdout, process25.env, tone)}
3448
+ return sections.length === 0 ? "nothing to pick up" : sections.map(({ heading, tone, count, lines }) => `${section(heading, count, process27.stdout, process27.env, tone)}
3108
3449
  ${lines.join(`
3109
3450
  `).replace(LINE_START2, " ")}`).join(`
3110
3451
 
@@ -3609,7 +3950,7 @@ async function issue(args) {
3609
3950
  // src/commands/logs.ts
3610
3951
  var usage4 = `ft logs <run id>
3611
3952
 
3612
- Prints what the failed jobs of a run say went wrong: each failed bun test's output and the end of each failed step.
3953
+ Prints what the failed jobs of a run say went wrong: each failed bun test's output and the end of each failed step, cut to the errors when it is a tsc, eslint, vitest, playwright, phpstan or php-cs-fixer step.
3613
3954
  With no failed job it prints every job's last lines; --full prints whole logs.`;
3614
3955
  var EXITS3 = [[0, "it printed the logs"], [1, "Forgejo cannot be read"], [2, "a usage error or a job the run lacks"]];
3615
3956
  var options3 = {
@@ -3656,7 +3997,7 @@ ${await text(job)}`);
3656
3997
  }
3657
3998
 
3658
3999
  // src/commands/milestone.ts
3659
- import process26 from "process";
4000
+ import process28 from "process";
3660
4001
  var TITLE_WIDTH3 = 60;
3661
4002
  var LIST_LIMIT = 30;
3662
4003
  var CONCURRENCY2 = 4;
@@ -3665,15 +4006,15 @@ function counts(milestone) {
3665
4006
  }
3666
4007
  function progressBar(milestone) {
3667
4008
  const total = milestone.open_issues + milestone.closed_issues;
3668
- return takesControlCodes(process26.stdout) ? bar(total === 0 ? 0 : milestone.closed_issues / total, { width: 16 }) : "";
4009
+ return takesControlCodes(process28.stdout) ? bar(total === 0 ? 0 : milestone.closed_issues / total, { width: 16 }) : "";
3669
4010
  }
3670
4011
  function milestoneCells(each, showState) {
3671
4012
  const drawn = progressBar(each);
3672
4013
  return [String(each.id), truncate(each.title, TITLE_WIDTH3), `${each.open_issues} open`, `${each.closed_issues} closed`, ...drawn === "" ? [] : [drawn], progress(each), dueDate(each) === "" ? "" : `due ${dueDate(each)}`, ...showState ? [each.state] : []];
3673
4014
  }
3674
4015
  async function printWithIssues(list, repo) {
3675
- const colors = paint(process26.stdout);
3676
- const id = role("id", process26.stdout);
4016
+ const colors = paint(process28.stdout);
4017
+ const id = role("id", process28.stdout);
3677
4018
  const issuesOf = await pool(list, concurrencyOf(CONCURRENCY2), async (each) => Promise.all([openIssues(undefined, repo, each.id), closedIssues(each.id, repo)]));
3678
4019
  const blocks = list.map((each, index) => {
3679
4020
  const byNumber = (left, right) => left.number - right.number;
@@ -3684,7 +4025,7 @@ async function printWithIssues(list, repo) {
3684
4025
  ...open.map((issue) => ` ${id(`#${issue.number}`)} ${truncate(issue.title, TITLE_WIDTH3)}`),
3685
4026
  ...closed.map((issue) => colors.dim(` #${issue.number} ${truncate(issue.title, TITLE_WIDTH3)} (closed)`))
3686
4027
  ];
3687
- return [section(`${each.title}${drawn === "" ? "" : ` ${drawn}`} ${facts}`, undefined, process26.stdout, process26.env, "accent"), ...lines].join(`
4028
+ return [section(`${each.title}${drawn === "" ? "" : ` ${drawn}`} ${facts}`, undefined, process28.stdout, process28.env, "accent"), ...lines].join(`
3688
4029
  `);
3689
4030
  });
3690
4031
  console.log(blocks.join(`
@@ -3696,7 +4037,7 @@ var listUsage = `ft milestones
3696
4037
  Lists the repository's milestones, the open ones unless --state says otherwise, with the issues open and closed in each, the progress and the due date; on a terminal the progress is a bar, and --issues lists the title of every issue under its milestone.`;
3697
4038
  var listExits = [[0, "it listed them"], [1, "Forgejo refuses"], [2, "a usage error"]];
3698
4039
  var listOptions = {
3699
- state: { type: "string", description: "open (the default), closed or all" },
4040
+ state: { type: "string", choices: ["open", "closed", "all"], default: "open", description: "which milestones to list (open)" },
3700
4041
  issues: { type: "boolean", short: "i", description: "list the open and closed issues of each milestone by title" },
3701
4042
  ...limitOptions(LIST_LIMIT),
3702
4043
  json: jsonOption("id, title, state, description, open, closed, due (YYYY-MM-DD or null)"),
@@ -3705,9 +4046,7 @@ var listOptions = {
3705
4046
  async function milestones(args) {
3706
4047
  const parsed = parse(args, listUsage, listOptions, { exits: listExits });
3707
4048
  const { values } = parsed;
3708
- const state = values.state ?? "open";
3709
- if (state !== "open" && state !== "closed" && state !== "all")
3710
- fail(`--state takes open, closed or all, not ${state}`);
4049
+ const state = values.state;
3711
4050
  const limit = limitOf(values, LIST_LIMIT);
3712
4051
  const found = await listMilestones(state, values.repo);
3713
4052
  if (values.issues === true && values.json === true)
@@ -3944,7 +4283,7 @@ function report2(plan, added, skipped) {
3944
4283
 
3945
4284
  // src/commands/release.ts
3946
4285
  import { basename as basename3, join as join11 } from "path";
3947
- import process28 from "process";
4286
+ import process30 from "process";
3948
4287
  var {$: $2 } = globalThis.Bun;
3949
4288
 
3950
4289
  // src/commands/watch.ts
@@ -4007,7 +4346,7 @@ async function followRuns(pick, timeout, repo, idle, out = process.stdout, mode
4007
4346
  failedJobs.push(...jobs);
4008
4347
  if (!json)
4009
4348
  console.error(`
4010
- ${failureText(jobs)}
4349
+ ${failureText2(jobs)}
4011
4350
 
4012
4351
  ${run.html_url}`);
4013
4352
  failed.add(run.id);
@@ -4182,12 +4521,12 @@ async function publishable() {
4182
4521
 
4183
4522
  // src/commands/release-plan.ts
4184
4523
  import { basename as basename2, join as join9, relative } from "path";
4185
- import process27 from "process";
4524
+ import process29 from "process";
4186
4525
  async function planOf({ level, dir, prefix }, registry) {
4187
4526
  const file = Bun.file(join9(dir ?? ".", "package.json"));
4188
4527
  const pkg = await file.exists() ? await file.json() : undefined;
4189
- const name = pkg?.name ?? basename2(dir ?? process27.cwd());
4190
- const where = dir === undefined ? "" : ` in ${relative(process27.cwd(), dir) || "."}`;
4528
+ const name = pkg?.name ?? basename2(dir ?? process29.cwd());
4529
+ const where = dir === undefined ? "" : ` in ${relative(process29.cwd(), dir) || "."}`;
4191
4530
  let version;
4192
4531
  let bump;
4193
4532
  if (level === undefined) {
@@ -4432,7 +4771,7 @@ ${push.stderr.trim()}`, signal === undefined ? 1 : exitCodeOf(null, signal));
4432
4771
  if (late !== undefined)
4433
4772
  fail(`interrupted by ${late} after ${bumped.map((each) => each.tag).join(", ")} ${bumped.length === 1 ? "was pushed: its runs are" : "were pushed: their runs are"} not waited for`, exitCodeOf(null, late));
4434
4773
  say(`pushed ${branch} and ${bumped.map((each) => each.tag).join(", ")}, waiting for their runs`);
4435
- followed = await followRuns((runs) => runs.filter((run) => run.id > before && heads.has(run.commit_sha)), timeout, undefined, NO_RUN2, json ? process28.stderr : process28.stdout, { json });
4774
+ followed = await followRuns((runs) => runs.filter((run) => run.id > before && heads.has(run.commit_sha)), timeout, undefined, NO_RUN2, json ? process30.stderr : process30.stdout, { json });
4436
4775
  if (followed.code !== 0) {
4437
4776
  report();
4438
4777
  return followed.code;
@@ -4607,7 +4946,7 @@ async function runs(args) {
4607
4946
  }
4608
4947
 
4609
4948
  // src/cli.ts
4610
- process29.exitCode = await runCli({
4949
+ process31.exitCode = await runCli({
4611
4950
  name: "ft",
4612
4951
  about: "Forgejo tools over tea, run from a repository whose origin is on Forgejo",
4613
4952
  replaces: "tea api calls piped through jq, and sleep loops waiting on CI",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-forgejo",
3
3
  "type": "module",
4
- "version": "0.29.1",
4
+ "version": "0.30.2",
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",
@@ -31,6 +31,6 @@
31
31
  "@kaynooo/utils": "3.0.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@kaynooo/cli-kit": "0.38.2"
34
+ "@kaynooo/cli-kit": "0.41.0"
35
35
  }
36
36
  }