@kaynooo/cli-forgejo 0.28.1 → 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 +68 -48
  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
@@ -124,7 +124,7 @@ function Fe(r = {}) {
124
124
  var o = Fe();
125
125
 
126
126
  // ../kit/src/theme.ts
127
- import { existsSync as existsSync3, readFileSync, statSync } from "fs";
127
+ import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
128
128
  import { homedir as homedir2 } from "os";
129
129
  import { join as join3, resolve as resolve2 } from "path";
130
130
  import process5 from "process";
@@ -145,7 +145,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
145
145
  }
146
146
 
147
147
  // ../kit/src/user-config.ts
148
- import { existsSync as existsSync2 } from "fs";
148
+ import { existsSync as existsSync2, readFileSync } from "fs";
149
149
  import { homedir } from "os";
150
150
  import { join as join2 } from "path";
151
151
  import process4 from "process";
@@ -163,6 +163,21 @@ function userConfigReadPath(bin, legacy = [], where = {}) {
163
163
  const base = configBase(where);
164
164
  return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
165
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
+ }
166
181
 
167
182
  // ../kit/src/theme.ts
168
183
  function toLinear(channel) {
@@ -264,7 +279,7 @@ function readThemeFile(path, warn) {
264
279
  warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
265
280
  return;
266
281
  }
267
- const parsed = JSON.parse(readFileSync(path, "utf8"));
282
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
268
283
  if (isRecord(parsed))
269
284
  return parsed;
270
285
  warn(`${path} is not a JSON object, theme ignored`);
@@ -403,6 +418,9 @@ function note(text, detail) {
403
418
  function warn(text, detail) {
404
419
  console.error(marked("warn", text, process6.stderr, detail));
405
420
  }
421
+ function problem(text, detail) {
422
+ console.error(marked("problem", text, process6.stderr, detail));
423
+ }
406
424
  function role(name, stream, env = process6.env) {
407
425
  const colors = paint(stream, env);
408
426
  return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
@@ -1050,8 +1068,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
1050
1068
  // ../kit/src/progress.ts
1051
1069
  var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
1052
1070
  var FRAME_MS = 200;
1053
- var CLEAR_LINE = "\r\x1B[2K";
1054
- var LINE_UP = "\x1B[1A\x1B[2K";
1071
+ var CLEAR_BELOW = "\r\x1B[J";
1055
1072
  var ESC = String.fromCharCode(27);
1056
1073
  var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
1057
1074
  var RESET_STYLE = `${ESC}[0m`;
@@ -1068,13 +1085,15 @@ function liveRegion(render, stream = process13.stderr, env = process13.env) {
1068
1085
  } };
1069
1086
  const write = stream.write.bind(stream);
1070
1087
  let frame = 0;
1071
- let drawn = [];
1072
- const columns = () => stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns;
1073
- 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
+ };
1074
1093
  const clear = () => {
1075
- if (drawn.length > 0)
1076
- write(`${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}`);
1077
- drawn = [];
1094
+ if (drawn)
1095
+ write(CLEAR_BELOW);
1096
+ drawn = false;
1078
1097
  };
1079
1098
  const draw = () => {
1080
1099
  const width = columns() - 1;
@@ -1084,9 +1103,9 @@ function liveRegion(render, stream = process13.stderr, env = process13.env) {
1084
1103
  clear();
1085
1104
  return;
1086
1105
  }
1087
- write(`${drawn.length > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}` : CLEAR_LINE}${lines.join(`
1088
- `)}`);
1089
- 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;
1090
1109
  };
1091
1110
  const timer = setInterval(draw, FRAME_MS);
1092
1111
  stream.on?.("resize", draw);
@@ -1311,7 +1330,7 @@ function ciHeader(spinner, label, startedAt, out) {
1311
1330
  return `${spinner} ${label} ${paint(out).dim(formatElapsed(Date.now() - startedAt))}`;
1312
1331
  }
1313
1332
  // ../kit/src/cli.ts
1314
- import { readFileSync as readFileSync2, realpathSync } from "fs";
1333
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
1315
1334
  import { dirname as dirname3, join as join5 } from "path";
1316
1335
  import process16 from "process";
1317
1336
 
@@ -1619,7 +1638,7 @@ async function printCandidates(found) {
1619
1638
  function packageVersion(entry = Bun.main) {
1620
1639
  for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1621
1640
  try {
1622
- const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
1641
+ const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
1623
1642
  if (typeof version === "string")
1624
1643
  return version;
1625
1644
  } catch {}
@@ -2023,6 +2042,35 @@ function good(text) {
2023
2042
  return role("ok", process21.stdout)(text);
2024
2043
  }
2025
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
+
2026
2074
  // src/forge.ts
2027
2075
  import { homedir as homedir5 } from "os";
2028
2076
  import { join as join7 } from "path";
@@ -2201,7 +2249,7 @@ async function commentsOf(number, repo) {
2201
2249
  }
2202
2250
  async function commentsOfAll(issues, repo) {
2203
2251
  const commented = issues.filter((issue) => issue.comments > 0);
2204
- 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));
2205
2253
  return new Map(commented.map((issue, index) => [issue.number, comments[index]]));
2206
2254
  }
2207
2255
  async function editIssue(number, change, repo) {
@@ -2514,7 +2562,7 @@ async function eachIssue(command, numbers, step) {
2514
2562
  } catch (error) {
2515
2563
  if (!(error instanceof Exit) || numbers.length === 1)
2516
2564
  throw error;
2517
- console.error(`ft ${command}: ${error.message}`);
2565
+ problem(`ft ${command}: ${error.message}`);
2518
2566
  if (error.hint !== undefined)
2519
2567
  printHint(error.hint);
2520
2568
  code = Math.max(code, error.code);
@@ -3524,7 +3572,7 @@ async function issue(args) {
3524
3572
  if (values.copy === true && !await copyText(bodies.join(`
3525
3573
 
3526
3574
  `)))
3527
- console.error("warning: no clipboard tool found (wl-copy, xclip, xsel, pbcopy)");
3575
+ warn("no clipboard tool found (wl-copy, xclip, xsel, pbcopy)");
3528
3576
  return 0;
3529
3577
  }
3530
3578
  const read = await Promise.all(numbers.map(async (number) => Promise.all([getIssue(number, values.repo), commentsOf(number, values.repo)])));
@@ -3617,7 +3665,7 @@ function milestoneCells(each, showState) {
3617
3665
  async function printWithIssues(list, repo) {
3618
3666
  const colors = paint(process25.stdout);
3619
3667
  const id = role("id", process25.stdout);
3620
- 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)]));
3621
3669
  const blocks = list.map((each, index) => {
3622
3670
  const byNumber = (left, right) => left.number - right.number;
3623
3671
  const [open, closed] = issuesOf[index].map((found) => found.toSorted(byNumber));
@@ -4412,34 +4460,6 @@ ${push.stderr.trim()}`, signal === undefined ? 1 : exitCodeOf(null, signal));
4412
4460
  // src/commands/remote.ts
4413
4461
  import { lookup } from "dns/promises";
4414
4462
  var {$: $3 } = globalThis.Bun;
4415
-
4416
- // src/config.ts
4417
- function settingsPath(home) {
4418
- return userConfigReadPath("ft", [["ft", "config.json"]], { home });
4419
- }
4420
- async function loadSettings(home) {
4421
- const path = settingsPath(home);
4422
- const file = Bun.file(path);
4423
- if (!await file.exists())
4424
- return {};
4425
- let raw;
4426
- try {
4427
- raw = await file.json();
4428
- } catch (error) {
4429
- warn(`${path} is not valid JSON, so its settings are ignored`, error instanceof Error ? error.message : String(error));
4430
- return {};
4431
- }
4432
- if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
4433
- warn(`${path} is not a JSON object, so its settings are ignored`);
4434
- return {};
4435
- }
4436
- const host = "remoteHost" in raw ? raw.remoteHost : undefined;
4437
- if (host !== undefined && (typeof host !== "string" || host === ""))
4438
- warn(`remoteHost in ${path} must be a non-empty string, so it is ignored`);
4439
- return typeof host === "string" && host !== "" ? { remoteHost: host } : {};
4440
- }
4441
-
4442
- // src/commands/remote.ts
4443
4463
  var usage7 = `ft remote [--fix]
4444
4464
 
4445
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\`.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-forgejo",
3
3
  "type": "module",
4
- "version": "0.28.1",
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.36.0"
34
+ "@kaynooo/cli-kit": "0.37.0"
35
35
  }
36
36
  }