@kaynooo/cli-forgejo 0.28.0 → 0.28.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 +2 -0
  2. package/dist/cli.js +81 -59
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -33,6 +33,8 @@ Needs [tea](https://gitea.com/gitea/tea) logged in to the Forgejo instance (`tea
33
33
  | `ft milestone <title\|id>` | shows a milestone's open issues as `ft board` does (available, taken, claimed by one gone); `ft milestone new <title> [-d text] [--due YYYY-MM-DD]` creates one through the API, sending no `due_on` unless `--due` is given, never a zero date; `ft milestone close <m>` refuses while issues are open in it, naming them, unless `--force` |
34
34
  | `ft remote [--fix]` | switches an origin using an ssh alias (`forgejo:owner/repo`) to `git@<host>:owner/repo.git`, which tea matches; the host comes from `--host` or `remoteHost` in `~/.config/kaynooo-cli/ft.json` (`{"remoteHost": "git.example.com"}`; the older `~/.config/ft/config.json` is read while the new file is missing), and with neither it checks nothing |
35
35
 
36
+ `concurrency` (a positive whole number) in the same `ft.json` sets how many forge calls run at once when `ft` reads comments (8 by default) and milestone issues (4 by default).
37
+
36
38
  `ft <command> --help` lists each command's options. Waiting commands show one line per run with how long it has been waiting or running (`● running for 1m 12s`), redrawn in place on a terminal and left at its last status with the time it took (`✓ success in 3m 2s`), and a line per status change in a log or a pipe; they exit 0 when the runs pass, 1 when one fails, 2 on a timeout, a stalled queue or bad usage; the other commands exit 0 when done, 1 when Forgejo refuses or a check fails, 2 on a usage error.
37
39
 
38
40
  ## CI
package/dist/cli.js CHANGED
@@ -9,6 +9,7 @@ import { parseArgs } from "util";
9
9
 
10
10
  // ../kit/src/format.ts
11
11
  import process7 from "process";
12
+
12
13
  // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
13
14
  var ct = /[aeiou]y$/;
14
15
  var N = new Map;
@@ -45,6 +46,7 @@ function ko(t, e, r = "...") {
45
46
  }
46
47
  var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
47
48
  var z = new Map;
49
+
48
50
  // ../kit/src/mode.ts
49
51
  import process2 from "process";
50
52
  var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
@@ -90,7 +92,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
90
92
  return false;
91
93
  return r?.isTTY === true;
92
94
  }
93
- function f2(r, e = []) {
95
+ function f(r, e = []) {
94
96
  let l = "", n = "";
95
97
  for (let t = 0, i = e.length;t < i; t++)
96
98
  l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
@@ -100,7 +102,7 @@ function f2(r, e = []) {
100
102
  if (Array.isArray(a)) {
101
103
  let s = g.get(i);
102
104
  if (s === undefined)
103
- s = f2(r, [...e, a]), g.set(i, s);
105
+ s = f(r, [...e, a]), g.set(i, s);
104
106
  return s;
105
107
  }
106
108
  if (typeof a === "function")
@@ -109,20 +111,20 @@ function f2(r, e = []) {
109
111
  if (u === undefined) {
110
112
  if (g.size >= 64)
111
113
  g.clear();
112
- u = f2(r, [...e, a(...s)]), g.set(y, u);
114
+ u = f(r, [...e, a(...s)]), g.set(y, u);
113
115
  }
114
116
  return u;
115
117
  };
116
118
  throw Error(`Unknown style: ${String(i)}`);
117
119
  } });
118
120
  }
119
- function Fe2(r = {}) {
120
- return f2(r);
121
+ function Fe(r = {}) {
122
+ return f(r);
121
123
  }
122
- var o2 = Fe2();
124
+ var o = Fe();
123
125
 
124
126
  // ../kit/src/theme.ts
125
- import { existsSync as existsSync3, readFileSync, statSync } from "fs";
127
+ import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
126
128
  import { homedir as homedir2 } from "os";
127
129
  import { join as join3, resolve as resolve2 } from "path";
128
130
  import process5 from "process";
@@ -143,7 +145,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
143
145
  }
144
146
 
145
147
  // ../kit/src/user-config.ts
146
- import { existsSync as existsSync2 } from "fs";
148
+ import { existsSync as existsSync2, readFileSync } from "fs";
147
149
  import { homedir } from "os";
148
150
  import { join as join2 } from "path";
149
151
  import process4 from "process";
@@ -161,6 +163,21 @@ function userConfigReadPath(bin, legacy = [], where = {}) {
161
163
  const base = configBase(where);
162
164
  return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
163
165
  }
166
+ function readUserConfig(bin, where = {}, legacy = []) {
167
+ const path = userConfigReadPath(bin, legacy, where);
168
+ if (!existsSync2(path))
169
+ return {};
170
+ try {
171
+ const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
172
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
173
+ } catch {
174
+ return {};
175
+ }
176
+ }
177
+ function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
178
+ const value = readUserConfig(bin, where, legacy)[key];
179
+ return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
180
+ }
164
181
 
165
182
  // ../kit/src/theme.ts
166
183
  function toLinear(channel) {
@@ -262,7 +279,7 @@ function readThemeFile(path, warn) {
262
279
  warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
263
280
  return;
264
281
  }
265
- const parsed = JSON.parse(readFileSync(path, "utf8"));
282
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
266
283
  if (isRecord(parsed))
267
284
  return parsed;
268
285
  warn(`${path} is not a JSON object, theme ignored`);
@@ -384,7 +401,7 @@ function takesControlCodes(stream, env = process6.env) {
384
401
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
385
402
  }
386
403
  function paint(stream, env = process6.env) {
387
- return Fe2({ stream: { isTTY: takesControlCodes(stream, env) }, env });
404
+ return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
388
405
  }
389
406
  function marked(mark, text, stream, detail, env = process6.env) {
390
407
  const colors = paint(stream, env);
@@ -401,6 +418,9 @@ function note(text, detail) {
401
418
  function warn(text, detail) {
402
419
  console.error(marked("warn", text, process6.stderr, detail));
403
420
  }
421
+ function problem(text, detail) {
422
+ console.error(marked("problem", text, process6.stderr, detail));
423
+ }
404
424
  function role(name, stream, env = process6.env) {
405
425
  const colors = paint(stream, env);
406
426
  return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
@@ -1048,8 +1068,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
1048
1068
  // ../kit/src/progress.ts
1049
1069
  var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
1050
1070
  var FRAME_MS = 200;
1051
- var CLEAR_LINE = "\r\x1B[2K";
1052
- var LINE_UP = "\x1B[1A\x1B[2K";
1071
+ var CLEAR_BELOW = "\r\x1B[J";
1053
1072
  var ESC = String.fromCharCode(27);
1054
1073
  var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
1055
1074
  var RESET_STYLE = `${ESC}[0m`;
@@ -1066,13 +1085,15 @@ function liveRegion(render, stream = process13.stderr, env = process13.env) {
1066
1085
  } };
1067
1086
  const write = stream.write.bind(stream);
1068
1087
  let frame = 0;
1069
- let drawn = [];
1070
- const columns = () => stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns;
1071
- const rowsDrawn = () => drawn.reduce((sum, width) => sum + Math.max(1, Math.ceil(width / columns())), 0);
1088
+ let drawn = false;
1089
+ const columns = () => {
1090
+ const now = stream.getWindowSize?.()[0] ?? stream.columns;
1091
+ return now === undefined || now === 0 ? 80 : now;
1092
+ };
1072
1093
  const clear = () => {
1073
- if (drawn.length > 0)
1074
- write(`${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}`);
1075
- drawn = [];
1094
+ if (drawn)
1095
+ write(CLEAR_BELOW);
1096
+ drawn = false;
1076
1097
  };
1077
1098
  const draw = () => {
1078
1099
  const width = columns() - 1;
@@ -1082,9 +1103,9 @@ function liveRegion(render, stream = process13.stderr, env = process13.env) {
1082
1103
  clear();
1083
1104
  return;
1084
1105
  }
1085
- write(`${drawn.length > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}` : CLEAR_LINE}${lines.join(`
1086
- `)}`);
1087
- drawn = lines.map((line) => Bun.stringWidth(line));
1106
+ write(`${CLEAR_BELOW}${lines.join(`
1107
+ `)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
1108
+ drawn = true;
1088
1109
  };
1089
1110
  const timer = setInterval(draw, FRAME_MS);
1090
1111
  stream.on?.("resize", draw);
@@ -1309,7 +1330,7 @@ function ciHeader(spinner, label, startedAt, out) {
1309
1330
  return `${spinner} ${label} ${paint(out).dim(formatElapsed(Date.now() - startedAt))}`;
1310
1331
  }
1311
1332
  // ../kit/src/cli.ts
1312
- import { readFileSync as readFileSync2, realpathSync } from "fs";
1333
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
1313
1334
  import { dirname as dirname3, join as join5 } from "path";
1314
1335
  import process16 from "process";
1315
1336
 
@@ -1617,7 +1638,7 @@ async function printCandidates(found) {
1617
1638
  function packageVersion(entry = Bun.main) {
1618
1639
  for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1619
1640
  try {
1620
- const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
1641
+ const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
1621
1642
  if (typeof version === "string")
1622
1643
  return version;
1623
1644
  } catch {}
@@ -2021,6 +2042,35 @@ function good(text) {
2021
2042
  return role("ok", process21.stdout)(text);
2022
2043
  }
2023
2044
 
2045
+ // src/config.ts
2046
+ function concurrencyOf(fallback, home) {
2047
+ return configuredNumber("ft", "concurrency", fallback, { home }, [["ft", "config.json"]]);
2048
+ }
2049
+ function settingsPath(home) {
2050
+ return userConfigReadPath("ft", [["ft", "config.json"]], { home });
2051
+ }
2052
+ async function loadSettings(home) {
2053
+ const path = settingsPath(home);
2054
+ const file = Bun.file(path);
2055
+ if (!await file.exists())
2056
+ return {};
2057
+ let raw;
2058
+ try {
2059
+ raw = await file.json();
2060
+ } catch (error) {
2061
+ warn(`${path} is not valid JSON, so its settings are ignored`, error instanceof Error ? error.message : String(error));
2062
+ return {};
2063
+ }
2064
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
2065
+ warn(`${path} is not a JSON object, so its settings are ignored`);
2066
+ return {};
2067
+ }
2068
+ const host = "remoteHost" in raw ? raw.remoteHost : undefined;
2069
+ if (host !== undefined && (typeof host !== "string" || host === ""))
2070
+ warn(`remoteHost in ${path} must be a non-empty string, so it is ignored`);
2071
+ return typeof host === "string" && host !== "" ? { remoteHost: host } : {};
2072
+ }
2073
+
2024
2074
  // src/forge.ts
2025
2075
  import { homedir as homedir5 } from "os";
2026
2076
  import { join as join7 } from "path";
@@ -2199,7 +2249,7 @@ async function commentsOf(number, repo) {
2199
2249
  }
2200
2250
  async function commentsOfAll(issues, repo) {
2201
2251
  const commented = issues.filter((issue) => issue.comments > 0);
2202
- const comments = await pool(commented, CONCURRENCY, async (issue) => commentsOf(issue.number, repo));
2252
+ const comments = await pool(commented, concurrencyOf(CONCURRENCY), async (issue) => commentsOf(issue.number, repo));
2203
2253
  return new Map(commented.map((issue, index) => [issue.number, comments[index]]));
2204
2254
  }
2205
2255
  async function editIssue(number, change, repo) {
@@ -2472,7 +2522,7 @@ async function board(args) {
2472
2522
  console.log(rows.length === 0 && (query !== undefined || state !== undefined) ? "no open issue matches" : renderBoard(rows, Date.now(), limit));
2473
2523
  return 0;
2474
2524
  }
2475
- async function me2(as, sessions) {
2525
+ async function me(as, sessions) {
2476
2526
  if (as !== undefined)
2477
2527
  return as;
2478
2528
  const session = await currentSession(sessions);
@@ -2496,7 +2546,7 @@ var takeOptions = {
2496
2546
  ...repoOption
2497
2547
  };
2498
2548
  async function claimant(values, sessions) {
2499
- const name = await me2(values.as, sessions);
2549
+ const name = await me(values.as, sessions);
2500
2550
  if (values.lane !== true)
2501
2551
  return () => name;
2502
2552
  const suffix = laneSuffix(name);
@@ -2512,7 +2562,7 @@ async function eachIssue(command, numbers, step) {
2512
2562
  } catch (error) {
2513
2563
  if (!(error instanceof Exit) || numbers.length === 1)
2514
2564
  throw error;
2515
- console.error(`ft ${command}: ${error.message}`);
2565
+ problem(`ft ${command}: ${error.message}`);
2516
2566
  if (error.hint !== undefined)
2517
2567
  printHint(error.hint);
2518
2568
  code = Math.max(code, error.code);
@@ -2844,7 +2894,7 @@ function commitsToAsk(commits, passedOver, max = MAX_LOOKUPS) {
2844
2894
  function settled(latest) {
2845
2895
  return latest !== undefined && latest.every((run) => FINISHED.has(run.status)) && judge(latest, false, false).kind === "runs" ? latest : undefined;
2846
2896
  }
2847
- async function ci3(args) {
2897
+ async function ci2(args) {
2848
2898
  const parsed = parse(args, usage2, options);
2849
2899
  const { values, positionals } = parsed;
2850
2900
  const branch = values.branch ?? await defaultBranch();
@@ -3522,7 +3572,7 @@ async function issue(args) {
3522
3572
  if (values.copy === true && !await copyText(bodies.join(`
3523
3573
 
3524
3574
  `)))
3525
- console.error("warning: no clipboard tool found (wl-copy, xclip, xsel, pbcopy)");
3575
+ warn("no clipboard tool found (wl-copy, xclip, xsel, pbcopy)");
3526
3576
  return 0;
3527
3577
  }
3528
3578
  const read = await Promise.all(numbers.map(async (number) => Promise.all([getIssue(number, values.repo), commentsOf(number, values.repo)])));
@@ -3615,7 +3665,7 @@ function milestoneCells(each, showState) {
3615
3665
  async function printWithIssues(list, repo) {
3616
3666
  const colors = paint(process25.stdout);
3617
3667
  const id = role("id", process25.stdout);
3618
- const issuesOf = await pool(list, CONCURRENCY2, async (each) => Promise.all([openIssues(undefined, repo, each.id), closedIssues(each.id, repo)]));
3668
+ const issuesOf = await pool(list, concurrencyOf(CONCURRENCY2), async (each) => Promise.all([openIssues(undefined, repo, each.id), closedIssues(each.id, repo)]));
3619
3669
  const blocks = list.map((each, index) => {
3620
3670
  const byNumber = (left, right) => left.number - right.number;
3621
3671
  const [open, closed] = issuesOf[index].map((found) => found.toSorted(byNumber));
@@ -4410,34 +4460,6 @@ ${push.stderr.trim()}`, signal === undefined ? 1 : exitCodeOf(null, signal));
4410
4460
  // src/commands/remote.ts
4411
4461
  import { lookup } from "dns/promises";
4412
4462
  var {$: $3 } = globalThis.Bun;
4413
-
4414
- // src/config.ts
4415
- function settingsPath(home) {
4416
- return userConfigReadPath("ft", [["ft", "config.json"]], { home });
4417
- }
4418
- async function loadSettings(home) {
4419
- const path = settingsPath(home);
4420
- const file = Bun.file(path);
4421
- if (!await file.exists())
4422
- return {};
4423
- let raw;
4424
- try {
4425
- raw = await file.json();
4426
- } catch (error) {
4427
- warn(`${path} is not valid JSON, so its settings are ignored`, error instanceof Error ? error.message : String(error));
4428
- return {};
4429
- }
4430
- if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
4431
- warn(`${path} is not a JSON object, so its settings are ignored`);
4432
- return {};
4433
- }
4434
- const host = "remoteHost" in raw ? raw.remoteHost : undefined;
4435
- if (host !== undefined && (typeof host !== "string" || host === ""))
4436
- warn(`remoteHost in ${path} must be a non-empty string, so it is ignored`);
4437
- return typeof host === "string" && host !== "" ? { remoteHost: host } : {};
4438
- }
4439
-
4440
- // src/commands/remote.ts
4441
4463
  var usage7 = `ft remote [--fix]
4442
4464
 
4443
4465
  Checks that origin's URLs name the Forgejo host itself: tea only finds the repository when origin's host is the login's ssh_host, never through an ssh alias such as \`forgejo\` or \`gitea\`.
@@ -4591,7 +4613,7 @@ process28.exitCode = await runCli({
4591
4613
  examples: [["ft ci", "wait for the runs of origin's tip, failures printed"], ["ft issue 12 -c", "an issue with its boxes numbered and its comments"]],
4592
4614
  commands: {
4593
4615
  runs: { run: runs, summary: "recent runs with workflow, ref, duration and age", group: "CI and release" },
4594
- ci: { run: ci3, summary: "wait for the runs covering a commit, printing what failed", group: "CI and release" },
4616
+ ci: { run: ci2, summary: "wait for the runs covering a commit, printing what failed", group: "CI and release" },
4595
4617
  watch: { run: watch2, summary: "wait for runs newer than an id, or those in progress", group: "CI and release" },
4596
4618
  logs: { run: logs2, summary: "what the failed jobs of a run say went wrong", group: "CI and release" },
4597
4619
  release: { run: release, summary: "bump, push branch and tag atomically, wait for runs and registry", group: "CI and release" },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-forgejo",
3
3
  "type": "module",
4
- "version": "0.28.0",
4
+ "version": "0.28.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.35.0"
34
+ "@kaynooo/cli-kit": "0.37.0"
35
35
  }
36
36
  }