@kaynooo/cli-forgejo 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -5
- package/dist/cli.js +357 -139
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,10 +13,10 @@ Needs [tea](https://gitea.com/gitea/tea) logged in to the Forgejo instance (`tea
|
|
|
13
13
|
| Command | What it does |
|
|
14
14
|
| --- | --- |
|
|
15
15
|
| `ft runs` | recent runs with workflow, ref, duration and age (`-n`, `--sha`, `-w test.yml`, `--json`) |
|
|
16
|
-
| `ft ci [ref]` | waits for the push runs covering a commit on the default branch and prints each failed test's output |
|
|
17
|
-
| `ft watch` | waits for the runs in progress, or `--after <id>` those newer than a run |
|
|
18
|
-
| `ft logs <run>` | what the failed jobs of a run say went wrong, `-j <name or id>` picks a job, `--full` for whole logs |
|
|
19
|
-
| `ft release <level>` | waits for the runs on HEAD, pushing it first when origin lacks it, then `bun pm version`, one atomic push of branch and tag, and waits for the runs and the registry; `-p <folder>` releases one workspace package as `<folder>-v<version
|
|
16
|
+
| `ft ci [ref]` | waits for the push runs covering a commit on the default branch and prints each failed test's output; `--json` prints `{status, runs, failedJobs, url}`, `--quiet` only the announcement, the failures and the result |
|
|
17
|
+
| `ft watch` | waits for the runs in progress, or `--after <id>` those newer than a run; `--json` and `--quiet` as `ft ci` |
|
|
18
|
+
| `ft logs <run>` | what the failed jobs of a run say went wrong, `-j <name or id>` picks a job, `--full` for whole logs, `--json` for the run, its jobs and the failed ones with their excerpts |
|
|
19
|
+
| `ft release <level>` | waits for the runs on HEAD, pushing it first when origin lacks it, then `bun pm version`, one atomic push of branch and tag, and waits for the runs and the registry; `-p <folder>` releases one workspace package as `<folder>-v<version>`; `--json` prints `{released, tag, package, version, status, runs, failedJobs, url}` (an array with several packages) |
|
|
20
20
|
| `ft board` | open issues: available, taken by a live session, or claimed with no live session here, each claim with its boxes left and a stale one with its latest note (`-q <regex>` on titles, `--state available\|taken\|away`, `-L`, `-m <milestone>`, `--json`) |
|
|
21
21
|
| `ft digest` | one screen for a session starting cold: the issues this session holds with their boxes left, claims no live session answers to, red or running CI on the default branch, unpushed commits, dirty files and TODO comments naming a closed issue (needs `todo-scan` on the PATH; empty sections left out, `--json`) |
|
|
22
22
|
| `ft take <n>...` / `ft drop <n>...` | claims or gives back issues for the calling Claude Code session, `--lane` as `lane-<s>-<n>` |
|
|
@@ -31,7 +31,7 @@ Needs [tea](https://gitea.com/gitea/tea) logged in to the Forgejo instance (`tea
|
|
|
31
31
|
| `ft plan add <plan> <n>...` / `ft plan carry <from> <to>` | adds `- [ ] #<n> <title>` lines to a release plan's checklist, or copies one plan's unticked `#<n>` lines into the next, both under `--section "Bugs:"` (created when missing) and skipping issues already listed |
|
|
32
32
|
| `ft milestones` | lists the milestones (`--state open\|closed\|all`, `--json`) with the issues open and closed in each, the progress and the due date |
|
|
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
|
-
| `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/ft
|
|
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
36
|
`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
37
|
|
|
@@ -45,6 +45,12 @@ ft ci --workflow test.yml --job test # kayjs: the test job is skipped when a n
|
|
|
45
45
|
|
|
46
46
|
With an admin login, a queued run is checked against the runners: a job whose `runs-on` labels no online runner carries fails at once, and a queue no runner works on for 3 minutes fails with the reason.
|
|
47
47
|
|
|
48
|
+
## JSON output
|
|
49
|
+
|
|
50
|
+
`--json` on `ft ci`, `ft watch`, `ft logs` and `ft release` prints `{status, runs, failedJobs, url}`: `status` is the worst status among the runs (`success`, `failure`, `cancelled`, `skipped`, or the running one's) and `none` when no run was followed; a `runs` item is `{id, workflow, status, ref, sha, url}` and a `failedJobs` item `{name, run, workflow, excerpt}`.
|
|
51
|
+
`ft logs --json` adds `jobs`, one `{name, id, status, excerpt}` per picked job, and `ft release --json` adds `released`, `tag`, `package` (null without a name) and `version`, an array of those with several packages.
|
|
52
|
+
`gl` prints the same shape with its statuses renamed (`failed` is `failure`, `canceled` is `cancelled`) and its own item keys, listed in its README.
|
|
53
|
+
|
|
48
54
|
## Releases
|
|
49
55
|
|
|
50
56
|
`ft release patch|minor|major` releases from the default branch. It first pushes any commits origin lacks and waits for their runs, so failing tests stop it before a tag exists that would never publish; a push starting no run within 3 minutes lets it go on. A refused push drops the bump commit and tag. A repo with its own bump script runs it, then `ft release --tagged`. In a monorepo, `ft release patch -p ft` bumps `packages/ft` alone, refreshes `bun.lock`, and commits and tags it `ft-v<version>`, so each package releases on its own. `--dry-run` makes the same checks, then prints the bump (`1.0.0 -> 1.1.0`), the tag, whether HEAD is pushed first, the pushes and the runs and registry it would wait for, and changes nothing. Once released, an open milestone titled like the version (`1.2.0`, `v1.2.0` or the tag) has its closed issues listed and is closed; a failure there only warns.
|
package/dist/cli.js
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import
|
|
6
|
-
|
|
5
|
+
import process20 from "process";
|
|
7
6
|
// ../kit/src/args.ts
|
|
8
7
|
import process6 from "process";
|
|
9
8
|
import { parseArgs } from "util";
|
|
@@ -406,17 +405,23 @@ var FULL_STOP = /\.$/;
|
|
|
406
405
|
function usageLine(usage, colors = paint(process4.stdout)) {
|
|
407
406
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
408
407
|
}
|
|
409
|
-
function helpText(usage, options, colors = paint(process4.stdout), { examples = [], replaces } = {}) {
|
|
410
|
-
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
408
|
+
function helpText(usage, options, colors = paint(process4.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
409
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
411
410
|
`);
|
|
412
411
|
}
|
|
412
|
+
function exitRows(exits, colors = paint(process4.stdout)) {
|
|
413
|
+
if (exits.length === 0)
|
|
414
|
+
return [];
|
|
415
|
+
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
416
|
+
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
417
|
+
}
|
|
413
418
|
function replacesRows(replaces, colors = paint(process4.stdout)) {
|
|
414
419
|
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
415
420
|
}
|
|
416
421
|
function wantsHelpJson(env = process4.env) {
|
|
417
422
|
return env.KIT_HELP === "json";
|
|
418
423
|
}
|
|
419
|
-
function description(usage, { examples = [], replaces } = {}) {
|
|
424
|
+
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
420
425
|
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
421
426
|
`);
|
|
422
427
|
const first = lines[0];
|
|
@@ -427,7 +432,9 @@ function description(usage, { examples = [], replaces } = {}) {
|
|
|
427
432
|
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
428
433
|
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
429
434
|
...replaces === undefined ? {} : { replaces },
|
|
430
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
435
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] }),
|
|
436
|
+
...exits === undefined ? {} : { exits: exits.map(([code, meaning]) => ({ code, meaning })) },
|
|
437
|
+
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
431
438
|
};
|
|
432
439
|
}
|
|
433
440
|
function exampleRows(examples, colors = paint(process4.stdout)) {
|
|
@@ -572,7 +579,7 @@ function parse(args, usage, options, settings = {}) {
|
|
|
572
579
|
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
573
580
|
let parsed;
|
|
574
581
|
try {
|
|
575
|
-
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
582
|
+
parsed = parseArgs({ args: joinDashValues(withBare(withAliases(own, all), all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
576
583
|
} catch (error) {
|
|
577
584
|
const message = parseError(error);
|
|
578
585
|
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
@@ -580,7 +587,7 @@ function parse(args, usage, options, settings = {}) {
|
|
|
580
587
|
const values = parsed.values;
|
|
581
588
|
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
582
589
|
if (values.help === true) {
|
|
583
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
590
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
|
|
584
591
|
throw new HelpShown;
|
|
585
592
|
}
|
|
586
593
|
checkChoices(parsed.values, all);
|
|
@@ -622,6 +629,18 @@ function listed(options, allowNegative) {
|
|
|
622
629
|
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
623
630
|
}));
|
|
624
631
|
}
|
|
632
|
+
function withAliases(args, options) {
|
|
633
|
+
const named = new Map(Object.entries(options).flatMap(([name, { aliases = [] }]) => aliases.map((alias) => [`--${alias}`, `--${name}`])));
|
|
634
|
+
if (named.size === 0)
|
|
635
|
+
return args;
|
|
636
|
+
const separator = args.indexOf("--");
|
|
637
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
638
|
+
return [...own.map((arg) => {
|
|
639
|
+
const at = arg.indexOf("=");
|
|
640
|
+
const current = named.get(at === -1 ? arg : arg.slice(0, at));
|
|
641
|
+
return current === undefined ? arg : `${current}${at === -1 ? "" : arg.slice(at)}`;
|
|
642
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
643
|
+
}
|
|
625
644
|
function withBare(args, options) {
|
|
626
645
|
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
627
646
|
if (bare.size === 0)
|
|
@@ -1005,23 +1024,29 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
1005
1024
|
}
|
|
1006
1025
|
if (ran.timedOut)
|
|
1007
1026
|
throw new Error(`${label}: no answer in ${formatDuration(timeoutMs ?? 0)}`);
|
|
1008
|
-
const
|
|
1027
|
+
const decoders = { stdout: new TextDecoder, stderr: new TextDecoder };
|
|
1009
1028
|
const streams = { stdout: "", stderr: "" };
|
|
1010
1029
|
for (const { stream, data } of ran.chunks)
|
|
1011
|
-
streams[stream] +=
|
|
1030
|
+
streams[stream] += decoders[stream].decode(data, { stream: true });
|
|
1031
|
+
streams.stdout += decoders.stdout.decode();
|
|
1032
|
+
streams.stderr += decoders.stderr.decode();
|
|
1012
1033
|
return { code: ran.code, ...streams };
|
|
1013
1034
|
}
|
|
1014
1035
|
|
|
1015
1036
|
// ../kit/src/ci.ts
|
|
1016
1037
|
var POLL = 15000;
|
|
1017
1038
|
async function waitForCi(wait) {
|
|
1018
|
-
const { tool, short, giveUpMs, noneMs, stalledMs, pollMs = POLL } = wait;
|
|
1039
|
+
const { tool, short, giveUpMs, noneMs, stalledMs, pollMs = POLL, quiet = false } = wait;
|
|
1019
1040
|
const started = Date.now();
|
|
1020
1041
|
let seen = started;
|
|
1021
1042
|
let moving = started;
|
|
1022
1043
|
let followed = "";
|
|
1023
1044
|
let found;
|
|
1024
|
-
const region = wait.lines === undefined ? undefined : liveRegion((spinner) => wait.lines?.(spinner, found, started) ?? []);
|
|
1045
|
+
const region = wait.lines === undefined || quiet ? undefined : liveRegion((spinner) => wait.lines?.(spinner, found, started) ?? []);
|
|
1046
|
+
const retrying = (error) => {
|
|
1047
|
+
if (!quiet)
|
|
1048
|
+
console.warn(`${tool}: ${error instanceof Error ? error.message : String(error)}, polling again`);
|
|
1049
|
+
};
|
|
1025
1050
|
const suffix = () => found === undefined ? "" : `: ${wait.links(found)}`;
|
|
1026
1051
|
async function stallOf(current) {
|
|
1027
1052
|
try {
|
|
@@ -1029,7 +1054,7 @@ async function waitForCi(wait) {
|
|
|
1029
1054
|
} catch (error) {
|
|
1030
1055
|
if (error instanceof Exit || isPermanentFailure(error))
|
|
1031
1056
|
throw error;
|
|
1032
|
-
|
|
1057
|
+
retrying(error);
|
|
1033
1058
|
return "unknown";
|
|
1034
1059
|
}
|
|
1035
1060
|
}
|
|
@@ -1046,7 +1071,7 @@ async function waitForCi(wait) {
|
|
|
1046
1071
|
fail(`the working directory was removed while waiting for CI on ${short}${suffix()}`);
|
|
1047
1072
|
if (isPermanentFailure(error))
|
|
1048
1073
|
fail(error instanceof Error ? error.message : String(error));
|
|
1049
|
-
|
|
1074
|
+
retrying(error);
|
|
1050
1075
|
const latest = found === undefined ? undefined : await wait.settle(found);
|
|
1051
1076
|
if (latest !== undefined)
|
|
1052
1077
|
return latest;
|
|
@@ -1078,6 +1103,8 @@ async function waitForCi(wait) {
|
|
|
1078
1103
|
}
|
|
1079
1104
|
}
|
|
1080
1105
|
// ../kit/src/cli.ts
|
|
1106
|
+
import { readFileSync, realpathSync } from "fs";
|
|
1107
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
1081
1108
|
import process11 from "process";
|
|
1082
1109
|
|
|
1083
1110
|
// ../kit/src/usage.ts
|
|
@@ -1381,10 +1408,22 @@ async function printCandidates(found) {
|
|
|
1381
1408
|
console.log(line);
|
|
1382
1409
|
return 0;
|
|
1383
1410
|
}
|
|
1411
|
+
function packageVersion(entry = Bun.main) {
|
|
1412
|
+
for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
|
|
1413
|
+
try {
|
|
1414
|
+
const { version } = JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
|
|
1415
|
+
if (typeof version === "string")
|
|
1416
|
+
return version;
|
|
1417
|
+
} catch {}
|
|
1418
|
+
if (dirname2(dir) === dir)
|
|
1419
|
+
return "0.0.0";
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1384
1422
|
async function runCli(cli, argv = process11.argv.slice(2)) {
|
|
1423
|
+
const version = cli.version ?? packageVersion();
|
|
1385
1424
|
if (argv[0] === COMPLETE)
|
|
1386
1425
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1387
|
-
const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(
|
|
1426
|
+
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 });
|
|
1388
1427
|
if (cli.usage !== false) {
|
|
1389
1428
|
try {
|
|
1390
1429
|
recordUsage(usageEntry(cli.name, commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv), argv, code));
|
|
@@ -1408,7 +1447,7 @@ function commandPath(scope, argv) {
|
|
|
1408
1447
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1409
1448
|
}
|
|
1410
1449
|
// ../kit/src/git.ts
|
|
1411
|
-
import { basename, dirname as
|
|
1450
|
+
import { basename, dirname as dirname3 } from "path";
|
|
1412
1451
|
import process12 from "process";
|
|
1413
1452
|
var ORIGIN_PREFIX = /^origin\//;
|
|
1414
1453
|
var GIT_NETWORK_MS = 60000;
|
|
@@ -1439,7 +1478,7 @@ async function defaultBranch() {
|
|
|
1439
1478
|
async function leaveWorktree() {
|
|
1440
1479
|
const common = await git(["rev-parse", "--path-format=absolute", "--git-common-dir"]);
|
|
1441
1480
|
if (basename(common) === ".git")
|
|
1442
|
-
process12.chdir(
|
|
1481
|
+
process12.chdir(dirname3(common));
|
|
1443
1482
|
}
|
|
1444
1483
|
// ../kit/src/limit.ts
|
|
1445
1484
|
function limitOptions(fallback) {
|
|
@@ -1466,18 +1505,18 @@ function capped(rows, limit) {
|
|
|
1466
1505
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1467
1506
|
// ../kit/src/sessions.ts
|
|
1468
1507
|
import { homedir as homedir2 } from "os";
|
|
1469
|
-
import { join as
|
|
1508
|
+
import { join as join3 } from "path";
|
|
1470
1509
|
import process13 from "process";
|
|
1471
1510
|
var {Glob } = globalThis.Bun;
|
|
1472
1511
|
var SESSION_FILES = new Glob("*.json");
|
|
1473
1512
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1474
1513
|
async function sessionDirs() {
|
|
1475
1514
|
const home = homedir2();
|
|
1476
|
-
const dirs = new Set([
|
|
1515
|
+
const dirs = new Set([join3(home, ".claude", "sessions")]);
|
|
1477
1516
|
if (process13.env.CLAUDE_CONFIG_DIR !== undefined)
|
|
1478
|
-
dirs.add(
|
|
1517
|
+
dirs.add(join3(process13.env.CLAUDE_CONFIG_DIR, "sessions"));
|
|
1479
1518
|
try {
|
|
1480
|
-
for await (const dir of ACCOUNT_DIRS.scan({ cwd:
|
|
1519
|
+
for await (const dir of ACCOUNT_DIRS.scan({ cwd: join3(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
|
|
1481
1520
|
dirs.add(dir);
|
|
1482
1521
|
} catch {}
|
|
1483
1522
|
return [...dirs];
|
|
@@ -1533,9 +1572,25 @@ async function currentSession(sessions) {
|
|
|
1533
1572
|
}
|
|
1534
1573
|
return;
|
|
1535
1574
|
}
|
|
1536
|
-
//
|
|
1537
|
-
|
|
1538
|
-
|
|
1575
|
+
// ../kit/src/user-config.ts
|
|
1576
|
+
import { existsSync } from "fs";
|
|
1577
|
+
import { homedir as homedir3 } from "os";
|
|
1578
|
+
import { join as join4 } from "path";
|
|
1579
|
+
import process14 from "process";
|
|
1580
|
+
function configBase(where = {}) {
|
|
1581
|
+
const xdg = where.xdg ?? (where.home === undefined ? process14.env.XDG_CONFIG_HOME : undefined);
|
|
1582
|
+
return xdg !== undefined && xdg !== "" ? xdg : join4(where.home ?? homedir3(), ".config");
|
|
1583
|
+
}
|
|
1584
|
+
function userConfigPath(bin, where = {}) {
|
|
1585
|
+
return join4(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
1586
|
+
}
|
|
1587
|
+
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
1588
|
+
const current = userConfigPath(bin, where);
|
|
1589
|
+
if (existsSync(current))
|
|
1590
|
+
return current;
|
|
1591
|
+
const base = configBase(where);
|
|
1592
|
+
return legacy.map((parts) => join4(base, ...parts)).find((path) => existsSync(path)) ?? current;
|
|
1593
|
+
}
|
|
1539
1594
|
// src/args.ts
|
|
1540
1595
|
var repoOption = {
|
|
1541
1596
|
repo: { type: "string", short: "r", description: "owner/name of the repository, instead of the one origin points at" }
|
|
@@ -1622,8 +1677,10 @@ function setBoxes(body, picks, done) {
|
|
|
1622
1677
|
if (pick.trim() === "")
|
|
1623
1678
|
throw new Error("an empty box pick matches every box");
|
|
1624
1679
|
const guarded = NUMBERED_PICK.exec(pick);
|
|
1625
|
-
const
|
|
1626
|
-
|
|
1680
|
+
const byText = (text) => all.filter((box) => box.text.toLowerCase().includes(text.trim().toLowerCase()));
|
|
1681
|
+
let matches = guarded === null && !WHOLE_PICK.test(pick) ? byText(pick) : all.filter((box) => box.number === Number(guarded?.[1] ?? pick) && (guarded === null || box.text.toLowerCase().startsWith((guarded[2] ?? "").trim().toLowerCase())));
|
|
1682
|
+
if (guarded !== null && matches.length === 0)
|
|
1683
|
+
matches = byText(pick);
|
|
1627
1684
|
if (matches.length === 0)
|
|
1628
1685
|
throw new Error(`no box matches ${pick}`);
|
|
1629
1686
|
if (matches.length > 1)
|
|
@@ -2052,7 +2109,7 @@ async function board(args) {
|
|
|
2052
2109
|
const issues = query === undefined ? open : open.filter((issue) => query.test(issue.title));
|
|
2053
2110
|
const rows = (await boardRows(issues, sessions, values.repo)).filter((row) => state === undefined || row.standing.state === state);
|
|
2054
2111
|
if (values.json === true) {
|
|
2055
|
-
printJson(boardJson(rows));
|
|
2112
|
+
printJson(boardJson(rows.slice(0, limit)));
|
|
2056
2113
|
return 0;
|
|
2057
2114
|
}
|
|
2058
2115
|
console.log(rows.length === 0 && (query !== undefined || state !== undefined) ? "no open issue matches" : renderBoard(rows, Date.now(), limit));
|
|
@@ -2162,7 +2219,7 @@ async function drop(args) {
|
|
|
2162
2219
|
}
|
|
2163
2220
|
|
|
2164
2221
|
// src/commands/ci.ts
|
|
2165
|
-
import
|
|
2222
|
+
import process16 from "process";
|
|
2166
2223
|
|
|
2167
2224
|
// src/git.ts
|
|
2168
2225
|
async function tagsAt(commit) {
|
|
@@ -2170,7 +2227,7 @@ async function tagsAt(commit) {
|
|
|
2170
2227
|
`).filter(Boolean);
|
|
2171
2228
|
}
|
|
2172
2229
|
async function commitsNaming(issue, ref) {
|
|
2173
|
-
const out = await git(["log", ref, "--reverse", "--extended-regexp", `--grep
|
|
2230
|
+
const out = await git(["log", ref, "--reverse", "--extended-regexp", `--grep=(^|[^[:alnum:]_./-])#${issue}([^0-9]|$)`, "--format=%H %s"]);
|
|
2174
2231
|
return out.split(`
|
|
2175
2232
|
`).filter(Boolean).map((line) => {
|
|
2176
2233
|
const space = line.indexOf(" ");
|
|
@@ -2324,29 +2381,42 @@ async function stallReason(runs, repo) {
|
|
|
2324
2381
|
}
|
|
2325
2382
|
return online.some((runner) => runner.status === "active") ? undefined : { reason: "no runner is working on anything: is it up?", certain: false };
|
|
2326
2383
|
}
|
|
2327
|
-
async function
|
|
2328
|
-
const
|
|
2384
|
+
async function failedJobsOf(run, repo) {
|
|
2385
|
+
const failed = [];
|
|
2329
2386
|
for (const job of await jobsOf(run.id, repo)) {
|
|
2330
2387
|
if (job.status === "failure")
|
|
2331
|
-
|
|
2332
|
-
${excerpt(await jobLog(job.id, repo))}`);
|
|
2388
|
+
failed.push({ name: job.name, run: run.id, workflow: run.workflow_id, excerpt: excerpt(await jobLog(job.id, repo)) });
|
|
2333
2389
|
}
|
|
2334
|
-
return
|
|
2390
|
+
return failed;
|
|
2391
|
+
}
|
|
2392
|
+
function failureText(failed) {
|
|
2393
|
+
return failed.map((job) => `job ${job.name} of ${job.workflow} failed:
|
|
2394
|
+
${job.excerpt}`).join(`
|
|
2335
2395
|
|
|
2336
2396
|
`);
|
|
2337
2397
|
}
|
|
2398
|
+
function runJson(run) {
|
|
2399
|
+
return { id: run.id, workflow: run.workflow_id, status: run.status, ref: run.prettyref, sha: run.commit_sha, url: run.html_url };
|
|
2400
|
+
}
|
|
2401
|
+
function ciJson(runs, failedJobs) {
|
|
2402
|
+
const link = runs.find((run) => run.status === "failure") ?? runs[0];
|
|
2403
|
+
return { status: runs.length === 0 ? "none" : overall(runs), runs: runs.map(runJson), failedJobs, url: link?.html_url ?? null };
|
|
2404
|
+
}
|
|
2338
2405
|
|
|
2339
2406
|
// src/commands/ci.ts
|
|
2340
2407
|
var usage2 = `ft ci [ref]
|
|
2341
2408
|
|
|
2342
2409
|
Waits for the push runs covering a commit on the branch, by default origin's tip, and prints what each failed job's log says.
|
|
2343
2410
|
A push's run tests every commit since the previous push, so a commit whose own run was cancelled, or whose --job was skipped, is covered by the next commit's runs.
|
|
2411
|
+
--json prints {status, runs, failedJobs, url} on stdout, the progress going to stderr; --quiet prints only the announcement, the failures and the result.
|
|
2344
2412
|
Exits 0 when they pass, 1 when one fails, 2 on a timeout, a stalled queue or a commit not on the branch.`;
|
|
2345
2413
|
var options = {
|
|
2346
2414
|
branch: { type: "string", short: "b", description: "branch the commit is on, by default the one origin/HEAD names" },
|
|
2347
2415
|
workflow: { type: "string", short: "w", description: "only this workflow file, e.g. test.yml; by default every workflow a push starts" },
|
|
2348
2416
|
job: { type: "string", short: "j", description: "a job whose skipping means the run left its work to a newer push" },
|
|
2349
|
-
timeout: { type: "string", short: "t", description: "how long before giving up (30m), a bare number in minutes" }
|
|
2417
|
+
timeout: { type: "string", short: "t", description: "how long before giving up (30m), a bare number in minutes" },
|
|
2418
|
+
json: jsonOption("status, runs, failedJobs with their log excerpts and url"),
|
|
2419
|
+
quiet: { type: "boolean", short: "q", description: "no live progress or retry warnings: the announcement, the failures and the result" }
|
|
2350
2420
|
};
|
|
2351
2421
|
var NO_RUN = 3 * 60000;
|
|
2352
2422
|
var STALLED = 3 * 60000;
|
|
@@ -2404,20 +2474,23 @@ async function ci2(args) {
|
|
|
2404
2474
|
}
|
|
2405
2475
|
return;
|
|
2406
2476
|
}
|
|
2407
|
-
const
|
|
2477
|
+
const json = values.json === true;
|
|
2478
|
+
const { dim } = paint(process16.stderr);
|
|
2408
2479
|
const runs = await waitForCi({
|
|
2409
2480
|
tool: "ft ci",
|
|
2410
2481
|
short,
|
|
2411
2482
|
giveUpMs: giveUp,
|
|
2412
2483
|
noneMs: NO_RUN,
|
|
2413
2484
|
stalledMs: STALLED,
|
|
2485
|
+
quiet: values.quiet === true,
|
|
2414
2486
|
noneMessage: `no run covers ${short} yet: its own was cancelled by a later push or never started, so the next push's will`,
|
|
2415
2487
|
covering,
|
|
2416
2488
|
finished: (found) => found.every((run) => FINISHED.has(run.status)),
|
|
2417
2489
|
key: (found) => found.map((run) => run.id).join(","),
|
|
2418
2490
|
announce: (found) => {
|
|
2491
|
+
const say = json ? console.error : console.log;
|
|
2419
2492
|
for (const run of found)
|
|
2420
|
-
|
|
2493
|
+
say(`following ${run.workflow_id} run ${run.id} on ${run.commit_sha.slice(0, 7)}${run.commit_sha === sha ? "" : `, which covers ${short}`}: ${run.html_url}`);
|
|
2421
2494
|
},
|
|
2422
2495
|
links: (found) => found.map((run) => run.html_url).join(" "),
|
|
2423
2496
|
settle: async (found) => settled(await refreshed(found)),
|
|
@@ -2427,10 +2500,21 @@ async function ci2(args) {
|
|
|
2427
2500
|
},
|
|
2428
2501
|
lines: (spinner, found, started) => [
|
|
2429
2502
|
`${spinner} CI on ${short} ${dim(formatElapsed(Date.now() - started))}`,
|
|
2430
|
-
...(found ?? []).map((run) => ` ${badge(run.status,
|
|
2503
|
+
...(found ?? []).map((run) => ` ${badge(run.status, process16.stderr)} ${run.workflow_id} ${dim(`run ${run.id}`)}`)
|
|
2431
2504
|
]
|
|
2432
2505
|
});
|
|
2433
2506
|
const status = overall(runs);
|
|
2507
|
+
const failed = [];
|
|
2508
|
+
if (status === "failure") {
|
|
2509
|
+
for (const run of runs) {
|
|
2510
|
+
if (run.status === "failure")
|
|
2511
|
+
failed.push(...await failedJobsOf(run));
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
if (json) {
|
|
2515
|
+
printJson(ciJson(runs, failed));
|
|
2516
|
+
return status === "failure" ? 1 : 0;
|
|
2517
|
+
}
|
|
2434
2518
|
if (status !== "failure") {
|
|
2435
2519
|
console.log(`CI ${status === "success" ? "passed" : "skipped its tests, a release tag's workflow testing them"} on ${short}`);
|
|
2436
2520
|
return 0;
|
|
@@ -2438,7 +2522,7 @@ async function ci2(args) {
|
|
|
2438
2522
|
for (const run of runs) {
|
|
2439
2523
|
if (run.status === "failure")
|
|
2440
2524
|
console.error(`
|
|
2441
|
-
${
|
|
2525
|
+
${failureText(failed.filter((job) => job.run === run.id))}
|
|
2442
2526
|
|
|
2443
2527
|
run ${run.id} failed${run.commit_sha === sha ? "" : `, testing every commit from ${short} to ${run.commit_sha.slice(0, 7)}`}: ${run.html_url}`);
|
|
2444
2528
|
}
|
|
@@ -2446,7 +2530,7 @@ run ${run.id} failed${run.commit_sha === sha ? "" : `, testing every commit from
|
|
|
2446
2530
|
}
|
|
2447
2531
|
|
|
2448
2532
|
// src/commands/digest.ts
|
|
2449
|
-
import
|
|
2533
|
+
import process17 from "process";
|
|
2450
2534
|
var RUNS_SCANNED = 50;
|
|
2451
2535
|
var TITLE_WIDTH2 = 70;
|
|
2452
2536
|
var SHOWN = 8;
|
|
@@ -2496,7 +2580,7 @@ async function quietly(read) {
|
|
|
2496
2580
|
}
|
|
2497
2581
|
}
|
|
2498
2582
|
async function staleTodos() {
|
|
2499
|
-
const bin = Bun.which("todo-scan", { PATH:
|
|
2583
|
+
const bin = Bun.which("todo-scan", { PATH: process17.env.PATH ?? "" });
|
|
2500
2584
|
if (bin === null)
|
|
2501
2585
|
return [];
|
|
2502
2586
|
let found;
|
|
@@ -2899,7 +2983,7 @@ ${editUsage}`);
|
|
|
2899
2983
|
if (milestone !== undefined)
|
|
2900
2984
|
change.milestone = milestone;
|
|
2901
2985
|
const grows = text !== undefined && values.append === true || added.length > 0;
|
|
2902
|
-
if (text !== undefined &&
|
|
2986
|
+
if (text !== undefined && values.append !== true)
|
|
2903
2987
|
change.body = text;
|
|
2904
2988
|
if (Object.keys(change).length > 0)
|
|
2905
2989
|
await editIssue(number, change, values.repo);
|
|
@@ -3039,6 +3123,7 @@ Exits 0 when it printed the logs, 1 when Forgejo cannot be read, 2 on a usage er
|
|
|
3039
3123
|
var options3 = {
|
|
3040
3124
|
job: { type: "string", short: "j", description: "only this job, by name or id" },
|
|
3041
3125
|
full: { type: "boolean", short: "f", description: "the whole log, timestamps stripped" },
|
|
3126
|
+
json: jsonOption("status, runs, failedJobs, url and the picked jobs with their log excerpts"),
|
|
3042
3127
|
...repoOption
|
|
3043
3128
|
};
|
|
3044
3129
|
function pickJobs(jobs, wanted) {
|
|
@@ -3057,13 +3142,23 @@ async function logs2(args) {
|
|
|
3057
3142
|
const picked = pickJobs(jobs, values.job);
|
|
3058
3143
|
if (picked.length === 0)
|
|
3059
3144
|
fail(`run ${run.id} has no job ${values.job ?? ""}: ${jobs.map((job) => job.name).join(", ")}`, 2, runHint(`ft logs ${run.id}`, "read every failed job"));
|
|
3145
|
+
const text = async (job) => {
|
|
3146
|
+
const log = await jobLog(job.id, values.repo);
|
|
3147
|
+
return values.full === true ? logLines(log).join(`
|
|
3148
|
+
`) : excerpt(log);
|
|
3149
|
+
};
|
|
3150
|
+
if (values.json === true) {
|
|
3151
|
+
const shown = [];
|
|
3152
|
+
for (const job of picked)
|
|
3153
|
+
shown.push({ name: job.name, id: job.id, status: job.status, excerpt: await text(job) });
|
|
3154
|
+
printJson({ ...ciJson([run], shown.filter((job) => job.status === "failure").map((job) => ({ name: job.name, run: run.id, workflow: run.workflow_id, excerpt: job.excerpt }))), jobs: shown });
|
|
3155
|
+
return 0;
|
|
3156
|
+
}
|
|
3060
3157
|
console.log(`${run.workflow_id} run ${run.id} on ${run.prettyref} (${run.commit_sha.slice(0, 7)}): ${badge(run.status, process.stdout)}, ${run.html_url}`);
|
|
3061
3158
|
for (const job of picked) {
|
|
3062
|
-
const log = await jobLog(job.id, values.repo);
|
|
3063
3159
|
console.log(`
|
|
3064
3160
|
job ${job.name}: ${badge(job.status, process.stdout)}
|
|
3065
|
-
${
|
|
3066
|
-
`) : excerpt(log)}`);
|
|
3161
|
+
${await text(job)}`);
|
|
3067
3162
|
}
|
|
3068
3163
|
return 0;
|
|
3069
3164
|
}
|
|
@@ -3094,7 +3189,7 @@ async function milestones(args) {
|
|
|
3094
3189
|
const limit = limitOf(values, LIST_LIMIT);
|
|
3095
3190
|
const found = await listMilestones(state, values.repo);
|
|
3096
3191
|
if (values.json === true) {
|
|
3097
|
-
printJson(found.map((each) => ({ id: each.id, title: each.title, state: each.state, description: each.description, open: each.open_issues, closed: each.closed_issues, due: dueDate(each) || null })));
|
|
3192
|
+
printJson(found.slice(0, limit).map((each) => ({ id: each.id, title: each.title, state: each.state, description: each.description, open: each.open_issues, closed: each.closed_issues, due: dueDate(each) || null })));
|
|
3098
3193
|
return 0;
|
|
3099
3194
|
}
|
|
3100
3195
|
if (found.length === 0) {
|
|
@@ -3328,30 +3423,39 @@ function report(plan, added, skipped) {
|
|
|
3328
3423
|
}
|
|
3329
3424
|
|
|
3330
3425
|
// src/commands/release.ts
|
|
3331
|
-
import { basename as basename3, join as
|
|
3426
|
+
import { basename as basename3, join as join8 } from "path";
|
|
3427
|
+
import process19 from "process";
|
|
3332
3428
|
var {$: $2 } = globalThis.Bun;
|
|
3333
3429
|
|
|
3334
3430
|
// src/commands/watch.ts
|
|
3335
3431
|
var usage5 = `ft watch [--after <id>]
|
|
3336
3432
|
|
|
3337
3433
|
Waits for runs to finish: those newer than run <id>, or else the ones in progress now.
|
|
3434
|
+
Prints nothing but failures and each run's final status with --quiet, and a JSON result with --json.
|
|
3338
3435
|
Exits 0 when every one passed or was skipped, 1 when one failed or was cancelled, 2 on a timeout or a stalled queue.`;
|
|
3339
3436
|
var options5 = {
|
|
3340
3437
|
after: { type: "string", short: "a", description: "watch the runs newer than this run id, as `ft runs --json` gives it" },
|
|
3341
3438
|
timeout: { type: "string", short: "t", description: "how long before giving up (15m), a bare number in minutes" },
|
|
3439
|
+
json: jsonOption("status, runs, failedJobs with their log excerpts and url; the progress goes to stderr"),
|
|
3440
|
+
quiet: { type: "boolean", short: "q", description: "print only the failures and each run's final status" },
|
|
3342
3441
|
...repoOption
|
|
3343
3442
|
};
|
|
3344
3443
|
var timing = { poll: 1e4 };
|
|
3345
3444
|
var LIMIT = 20;
|
|
3346
3445
|
var STALLED2 = 3 * 60000;
|
|
3347
3446
|
async function watchRuns(pick, timeout, repo, idle, out = process.stdout) {
|
|
3447
|
+
return (await followRuns(pick, timeout, repo, idle, out)).code;
|
|
3448
|
+
}
|
|
3449
|
+
async function followRuns(pick, timeout, repo, idle, out = process.stdout, mode = {}) {
|
|
3450
|
+
const { json = false, quiet = false } = mode;
|
|
3348
3451
|
const started = Date.now();
|
|
3349
3452
|
const latest = new Map;
|
|
3350
3453
|
const seen = new Map;
|
|
3351
3454
|
const line = (run) => `${run.workflow_id} run ${run.id} on ${run.prettyref}: ${badge(run.status, out)}${elapsed(run, seen.get(run.id) ?? Date.now())}`;
|
|
3352
|
-
const region = takesControlCodes(out) ? liveRegion(() => [...latest.values()].map(line), out) : undefined;
|
|
3455
|
+
const region = takesControlCodes(out) && !quiet ? liveRegion(() => [...latest.values()].map(line), out) : undefined;
|
|
3353
3456
|
const followed = new Set;
|
|
3354
3457
|
const failed = new Set;
|
|
3458
|
+
const failedJobs = [];
|
|
3355
3459
|
let moving = started;
|
|
3356
3460
|
async function poll() {
|
|
3357
3461
|
const newest = await recentRuns(LIMIT, repo);
|
|
@@ -3362,7 +3466,7 @@ async function watchRuns(pick, timeout, repo, idle, out = process.stdout) {
|
|
|
3362
3466
|
for (const run of runs) {
|
|
3363
3467
|
if (!seen.has(run.id))
|
|
3364
3468
|
seen.set(run.id, Date.now());
|
|
3365
|
-
if (region === undefined && latest.get(run.id)?.status !== run.status)
|
|
3469
|
+
if (region === undefined && !quiet && latest.get(run.id)?.status !== run.status)
|
|
3366
3470
|
out.write(`${line(run)}
|
|
3367
3471
|
`);
|
|
3368
3472
|
latest.set(run.id, run);
|
|
@@ -3370,15 +3474,20 @@ async function watchRuns(pick, timeout, repo, idle, out = process.stdout) {
|
|
|
3370
3474
|
region?.redraw();
|
|
3371
3475
|
if (runs.length === 0) {
|
|
3372
3476
|
if (idle !== undefined && Date.now() - started > idle) {
|
|
3373
|
-
|
|
3477
|
+
if (!json)
|
|
3478
|
+
out.write(`no run started, so nothing was waited for
|
|
3479
|
+
`);
|
|
3374
3480
|
return 0;
|
|
3375
3481
|
}
|
|
3376
3482
|
return;
|
|
3377
3483
|
}
|
|
3378
3484
|
for (const run of runs) {
|
|
3379
3485
|
if (run.status === "failure" && !failed.has(run.id)) {
|
|
3380
|
-
|
|
3381
|
-
|
|
3486
|
+
const jobs = await failedJobsOf(run, repo);
|
|
3487
|
+
failedJobs.push(...jobs);
|
|
3488
|
+
if (!json)
|
|
3489
|
+
console.error(`
|
|
3490
|
+
${failureText(jobs)}
|
|
3382
3491
|
|
|
3383
3492
|
${run.html_url}`);
|
|
3384
3493
|
failed.add(run.id);
|
|
@@ -3410,15 +3519,16 @@ ${run.html_url}`);
|
|
|
3410
3519
|
const message = error instanceof Error ? error.message : String(error);
|
|
3411
3520
|
if (isPermanentFailure(error))
|
|
3412
3521
|
fail(message);
|
|
3413
|
-
|
|
3522
|
+
if (!quiet)
|
|
3523
|
+
console.warn(`ft watch: ${message}, polling again`);
|
|
3414
3524
|
}
|
|
3415
3525
|
}
|
|
3416
3526
|
}
|
|
3417
3527
|
try {
|
|
3418
|
-
return await settle();
|
|
3528
|
+
return { code: await settle(), runs: [...latest.values()], failedJobs };
|
|
3419
3529
|
} finally {
|
|
3420
|
-
|
|
3421
|
-
|
|
3530
|
+
region?.stop();
|
|
3531
|
+
if (region !== undefined || quiet) {
|
|
3422
3532
|
for (const run of latest.values())
|
|
3423
3533
|
out.write(`${line(run)}
|
|
3424
3534
|
`);
|
|
@@ -3435,16 +3545,27 @@ async function watch(args) {
|
|
|
3435
3545
|
const parsed = parse(args, usage5, options5);
|
|
3436
3546
|
const { values } = parsed;
|
|
3437
3547
|
const timeout = duration(values.timeout, "timeout", 15 * 60000, "m");
|
|
3548
|
+
const json = values.json === true;
|
|
3549
|
+
const mode = { json, quiet: values.quiet === true };
|
|
3550
|
+
async function follow(pick) {
|
|
3551
|
+
const followed = await followRuns(pick, timeout, values.repo, undefined, json ? process.stderr : process.stdout, mode);
|
|
3552
|
+
if (json)
|
|
3553
|
+
printJson(ciJson(followed.runs, followed.failedJobs));
|
|
3554
|
+
return followed.code;
|
|
3555
|
+
}
|
|
3438
3556
|
if (values.after !== undefined) {
|
|
3439
3557
|
const after = wholeNumber(values.after, "after", 0, 0);
|
|
3440
|
-
return
|
|
3558
|
+
return follow((runs) => runs.filter((run) => run.id > after));
|
|
3441
3559
|
}
|
|
3442
3560
|
const active = new Set((await recentRuns(LIMIT, values.repo)).filter((run) => !FINISHED.has(run.status)).map((run) => run.id));
|
|
3443
3561
|
if (active.size === 0) {
|
|
3444
|
-
|
|
3562
|
+
if (json)
|
|
3563
|
+
printJson(ciJson([], []));
|
|
3564
|
+
else
|
|
3565
|
+
console.log("no run in progress");
|
|
3445
3566
|
return 0;
|
|
3446
3567
|
}
|
|
3447
|
-
return
|
|
3568
|
+
return follow((runs) => runs.filter((run) => active.has(run.id)));
|
|
3448
3569
|
}
|
|
3449
3570
|
|
|
3450
3571
|
// src/commands/release-checks.ts
|
|
@@ -3459,7 +3580,8 @@ async function alreadyPassed(sha) {
|
|
|
3459
3580
|
return false;
|
|
3460
3581
|
}
|
|
3461
3582
|
}
|
|
3462
|
-
async function testsPass(sha, branch, timeout) {
|
|
3583
|
+
async function testsPass(sha, branch, timeout, json = false) {
|
|
3584
|
+
const say = json ? console.error : console.log;
|
|
3463
3585
|
if (!await gitOk(["merge-base", "--is-ancestor", sha, `origin/${branch}`])) {
|
|
3464
3586
|
const held = holdSignals();
|
|
3465
3587
|
let push;
|
|
@@ -3473,20 +3595,21 @@ async function testsPass(sha, branch, timeout) {
|
|
|
3473
3595
|
if (push.code !== 0)
|
|
3474
3596
|
fail(`origin refused the push of ${sha.slice(0, 7)}, so nothing was bumped:
|
|
3475
3597
|
${push.stderr.trim()}`, 1);
|
|
3476
|
-
|
|
3598
|
+
say(`pushed ${branch} at ${sha.slice(0, 7)}, waiting for its runs before the bump`);
|
|
3477
3599
|
} else if (await alreadyPassed(sha)) {
|
|
3478
3600
|
return true;
|
|
3479
3601
|
} else {
|
|
3480
|
-
|
|
3602
|
+
say(`${branch} at ${sha.slice(0, 7)} is on origin, waiting for its runs before the bump`);
|
|
3481
3603
|
}
|
|
3482
|
-
return await watchRuns((runs) => newestPerWorkflow(runs.filter((run) => run.commit_sha === sha)), timeout, undefined, NO_RUN2) === 0;
|
|
3604
|
+
return await watchRuns((runs) => newestPerWorkflow(runs.filter((run) => run.commit_sha === sha)), timeout, undefined, NO_RUN2, json ? process.stderr : process.stdout) === 0;
|
|
3483
3605
|
}
|
|
3484
3606
|
|
|
3485
|
-
// src/commands/release-
|
|
3486
|
-
import {
|
|
3487
|
-
import
|
|
3607
|
+
// src/commands/release-many.ts
|
|
3608
|
+
import { readdir } from "fs/promises";
|
|
3609
|
+
import { join as join5 } from "path";
|
|
3488
3610
|
|
|
3489
3611
|
// src/commands/release-version.ts
|
|
3612
|
+
var LEVELS = new Set(["patch", "minor", "major", "prepatch", "preminor", "premajor", "prerelease"]);
|
|
3490
3613
|
var VERSION = /^\d+\.\d+\.\d+(?:-[\w.]+)?$/;
|
|
3491
3614
|
var PARTS = /^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/;
|
|
3492
3615
|
var LAST_NUMBER = /\d+$/;
|
|
@@ -3521,12 +3644,36 @@ function nextVersion(current, level) {
|
|
|
3521
3644
|
}
|
|
3522
3645
|
}
|
|
3523
3646
|
|
|
3647
|
+
// src/commands/release-many.ts
|
|
3648
|
+
function parseTargets(spec, level) {
|
|
3649
|
+
return spec.split(",").filter((part) => part !== "").map((part) => {
|
|
3650
|
+
const [folder = "", own] = part.split(":");
|
|
3651
|
+
const chosen = own ?? level;
|
|
3652
|
+
if (folder === "" || !LEVELS.has(chosen) && !VERSION.test(chosen))
|
|
3653
|
+
fail(`${part} is no folder[:level] in --package`);
|
|
3654
|
+
return { folder, level: chosen };
|
|
3655
|
+
});
|
|
3656
|
+
}
|
|
3657
|
+
async function publishable() {
|
|
3658
|
+
const root = join5(await git(["rev-parse", "--show-toplevel"]), "packages");
|
|
3659
|
+
const folders = (await readdir(root, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name).toSorted();
|
|
3660
|
+
const found = [];
|
|
3661
|
+
for (const folder of folders) {
|
|
3662
|
+
const file = Bun.file(join5(root, folder, "package.json"));
|
|
3663
|
+
if (await file.exists() && (await file.json()).private !== true)
|
|
3664
|
+
found.push(folder);
|
|
3665
|
+
}
|
|
3666
|
+
return found;
|
|
3667
|
+
}
|
|
3668
|
+
|
|
3524
3669
|
// src/commands/release-plan.ts
|
|
3670
|
+
import { basename as basename2, join as join6, relative } from "path";
|
|
3671
|
+
import process18 from "process";
|
|
3525
3672
|
async function printPlan({ level, dir, prefix, branch, base, timeout, registry }) {
|
|
3526
|
-
const file = Bun.file(
|
|
3673
|
+
const file = Bun.file(join6(dir ?? ".", "package.json"));
|
|
3527
3674
|
const pkg = await file.exists() ? await file.json() : undefined;
|
|
3528
|
-
const name = pkg?.name ?? basename2(dir ??
|
|
3529
|
-
const where = dir === undefined ? "" : ` in ${relative(
|
|
3675
|
+
const name = pkg?.name ?? basename2(dir ?? process18.cwd());
|
|
3676
|
+
const where = dir === undefined ? "" : ` in ${relative(process18.cwd(), dir) || "."}`;
|
|
3530
3677
|
const sha = base.slice(0, 7);
|
|
3531
3678
|
let version;
|
|
3532
3679
|
let bump;
|
|
@@ -3539,7 +3686,7 @@ async function printPlan({ level, dir, prefix, branch, base, timeout, registry }
|
|
|
3539
3686
|
console.log(`would release ${name} ${version}, tagged ${tag}`);
|
|
3540
3687
|
} else {
|
|
3541
3688
|
if (pkg?.version === undefined)
|
|
3542
|
-
fail(`no version in ${
|
|
3689
|
+
fail(`no version in ${join6(dir ?? ".", "package.json")}`);
|
|
3543
3690
|
version = nextVersion(pkg.version, level);
|
|
3544
3691
|
bump = dir === undefined ? `bun pm version ${level}, which commits and tags ${prefix}${version}` : `bun pm version ${level} --no-git-tag-version${where}, then commit it with bun.lock refreshed and tag ${prefix}${version}`;
|
|
3545
3692
|
console.log(`would release ${name} ${pkg.version} -> ${version}, tagged ${prefix}${version}`);
|
|
@@ -3559,31 +3706,30 @@ async function printPlan({ level, dir, prefix, branch, base, timeout, registry }
|
|
|
3559
3706
|
}
|
|
3560
3707
|
|
|
3561
3708
|
// src/commands/release-steps.ts
|
|
3562
|
-
import { join as
|
|
3709
|
+
import { join as join7, relative as relative2, resolve } from "path";
|
|
3563
3710
|
var {$ } = globalThis.Bun;
|
|
3564
|
-
var
|
|
3565
|
-
var REGISTRY_POLL = 5000;
|
|
3711
|
+
var registryWait = { tries: 12, poll: 5000 };
|
|
3566
3712
|
var REGISTRY_INFO_MS = 30000;
|
|
3567
3713
|
async function packageDir(value) {
|
|
3568
|
-
for (const dir of [resolve(value),
|
|
3569
|
-
if (await Bun.file(
|
|
3714
|
+
for (const dir of [resolve(value), join7(await git(["rev-parse", "--show-toplevel"]), "packages", value)]) {
|
|
3715
|
+
if (await Bun.file(join7(dir, "package.json")).exists())
|
|
3570
3716
|
return dir;
|
|
3571
3717
|
}
|
|
3572
3718
|
fail(`no package.json in ${value} nor in packages/${value}`);
|
|
3573
3719
|
}
|
|
3574
3720
|
async function commitPackageBump(dir, prefix) {
|
|
3575
|
-
const { version } = await Bun.file(
|
|
3721
|
+
const { version } = await Bun.file(join7(dir, "package.json")).json();
|
|
3576
3722
|
const root = await git(["rev-parse", "--show-toplevel"]);
|
|
3577
3723
|
const tag = `${prefix}${version}`;
|
|
3578
3724
|
const lock = await $`bun install --lockfile-only`.cwd(root).quiet().nothrow();
|
|
3579
3725
|
if (lock.exitCode !== 0)
|
|
3580
3726
|
fail(`bun install --lockfile-only after the bump: ${lock.stderr.toString().trim()}`);
|
|
3581
|
-
await git(["add",
|
|
3727
|
+
await git(["add", join7(dir, "package.json"), join7(root, "bun.lock")]);
|
|
3582
3728
|
await git(["commit", "-q", "-m", tag]);
|
|
3583
3729
|
await git(["tag", "-a", tag, "-m", tag]);
|
|
3584
3730
|
}
|
|
3585
3731
|
async function waitForRegistry(name, version) {
|
|
3586
|
-
for (let attempt = 0;attempt <
|
|
3732
|
+
for (let attempt = 0;attempt < registryWait.tries; attempt++) {
|
|
3587
3733
|
let served;
|
|
3588
3734
|
try {
|
|
3589
3735
|
served = (await runTool("bun info", ["bun", "info", name, "version", "--no-cache"], { timeoutMs: REGISTRY_INFO_MS })).stdout.trim().split(`
|
|
@@ -3594,62 +3740,83 @@ async function waitForRegistry(name, version) {
|
|
|
3594
3740
|
}
|
|
3595
3741
|
if (served === version)
|
|
3596
3742
|
return true;
|
|
3597
|
-
await Bun.sleep(
|
|
3743
|
+
await Bun.sleep(registryWait.poll);
|
|
3598
3744
|
}
|
|
3599
3745
|
return false;
|
|
3600
3746
|
}
|
|
3601
|
-
async function rollBack(preBump, tagsBefore) {
|
|
3747
|
+
async function rollBack(preBump, tagsBefore, dir) {
|
|
3602
3748
|
try {
|
|
3603
3749
|
for (const name of await tagsAt("HEAD")) {
|
|
3604
3750
|
if (!tagsBefore.has(name))
|
|
3605
3751
|
await git(["tag", "-d", name]);
|
|
3606
3752
|
}
|
|
3607
3753
|
await git(["reset", "--keep", preBump]);
|
|
3754
|
+
if (dir !== undefined) {
|
|
3755
|
+
const root = await git(["rev-parse", "--show-toplevel"]);
|
|
3756
|
+
const paths = [join7(dir, "package.json"), join7(root, "bun.lock")].map((path) => relative2(root, path));
|
|
3757
|
+
const tracked = (await git(["ls-tree", "-r", "--full-tree", "--name-only", preBump, "--", ...paths])).split(`
|
|
3758
|
+
`).filter((path) => path !== "");
|
|
3759
|
+
if (tracked.length > 0)
|
|
3760
|
+
await git(["restore", `--source=${preBump}`, "--staged", "--worktree", "--", ...tracked.map((path) => join7(root, path))]);
|
|
3761
|
+
}
|
|
3608
3762
|
} catch (error) {
|
|
3609
3763
|
warn(`could not undo the bump, back to ${preBump.slice(0, 7)} by hand`, error instanceof Error ? error.message : String(error));
|
|
3610
3764
|
}
|
|
3611
3765
|
}
|
|
3612
|
-
async function settleMilestone(version, tag) {
|
|
3766
|
+
async function settleMilestone(version, tag, say = console.log) {
|
|
3613
3767
|
try {
|
|
3614
3768
|
const names = new Set([version, `v${version}`, tag]);
|
|
3615
3769
|
const found = (await listMilestones("open")).find((each) => names.has(each.title));
|
|
3616
3770
|
if (found === undefined)
|
|
3617
3771
|
return;
|
|
3618
3772
|
const [done, left] = await Promise.all([closedIssues(found.id), openIssues(undefined, undefined, found.id)]);
|
|
3619
|
-
|
|
3773
|
+
say(`milestone ${found.title}: ${done.length} closed issue${done.length === 1 ? "" : "s"}${done.length === 0 ? "" : `
|
|
3620
3774
|
${done.map((issue) => ` #${issue.number} ${issue.title}`).join(`
|
|
3621
3775
|
`)}`}`);
|
|
3622
3776
|
if (left.length > 0)
|
|
3623
3777
|
warn(`${left.length} issue${left.length === 1 ? " is" : "s are"} still open in it`, left.map((issue) => `#${issue.number}`).join(" "));
|
|
3624
3778
|
await closeMilestone(found.id);
|
|
3625
|
-
|
|
3779
|
+
say(`closed milestone ${found.title}`);
|
|
3626
3780
|
} catch (error) {
|
|
3627
3781
|
warn(`released, but the milestone ${version} could not be settled`, error instanceof Error ? error.message : String(error));
|
|
3628
3782
|
}
|
|
3629
3783
|
}
|
|
3630
3784
|
|
|
3631
3785
|
// src/commands/release.ts
|
|
3632
|
-
var
|
|
3786
|
+
var SEVERAL = /[,:]/;
|
|
3633
3787
|
var usage6 = `ft release <patch|minor|major|x.y.z>
|
|
3788
|
+
ft release <level> -p <a,b:minor,...>
|
|
3789
|
+
ft release <level> --all
|
|
3634
3790
|
ft release --tagged
|
|
3635
3791
|
|
|
3636
3792
|
Cuts a release from the default branch: first the commit it sits on is pushed and its runs waited for, so failing tests stop it before anything is bumped or tagged. Then \`bun pm version\` commits and tags the bump, one atomic push sends the branch and its tag, and it waits for the runs the push started and for the registry to serve the version.
|
|
3637
3793
|
--tagged releases a version commit already tagged at HEAD instead, for repos bumping with their own script; the runs waited for first are then those of the commit below it.
|
|
3638
3794
|
--package releases one workspace package of a monorepo on its own, tagged \`<folder>-v<version>\` (\`ft release patch -p ft\` tags packages/ft as ft-v0.3.0).
|
|
3795
|
+
--package takes several folders separated by commas, each optionally with its own level after a colon (\`-p ft:minor,db\` bumps ft by minor and db by the level given); --all takes every published package of the workspace. They are released one after the other and the run stops at the first one that fails, naming the ones not released.
|
|
3639
3796
|
A refused or interrupted push drops the bump commit and its tag, so a retry starts clean; with --tagged the commit and tag are yours and stay.
|
|
3640
3797
|
Once released, an open milestone titled like the version (\`1.2.0\`, \`v1.2.0\` or the tag) has its closed issues listed and is closed; a failure there only warns.
|
|
3641
3798
|
--dry-run checks the same and prints the plan: the version bump, the tag, the pushes and the runs and registry it would wait for, changing nothing.
|
|
3799
|
+
--json prints {released, tag, package, version, status, runs, failedJobs, url} on stdout and the progress on stderr, an array of them with --package a,b or --all; it does not take --dry-run.
|
|
3642
3800
|
Exits 0 once released or planned, 1 when a run fails, origin refuses a push or the registry never serves the version, 2 on a timeout, a stalled queue, a refusal before anything ran (another branch, uncommitted changes, origin ahead) or a usage error.`;
|
|
3643
3801
|
var options6 = {
|
|
3644
3802
|
tagged: { type: "boolean", description: "push the version commit and tag already at HEAD instead of bumping" },
|
|
3645
|
-
package: { type: "string", short: "p", description: "workspace folder to release, a path or a name under packages
|
|
3803
|
+
package: { type: "string", short: "p", description: "workspace folder to release, a path or a name under packages/, several separated by commas" },
|
|
3804
|
+
all: { type: "boolean", description: "release every published package of the workspace, one after the other" },
|
|
3646
3805
|
"no-registry": { type: "boolean", description: "do not wait for the registry to serve the new version" },
|
|
3647
3806
|
"dry-run": { type: "boolean", description: "print what the release would do, changing nothing" },
|
|
3648
|
-
timeout: { type: "string", short: "t", description: "how long to wait for the runs (15m), a bare number in minutes" }
|
|
3807
|
+
timeout: { type: "string", short: "t", description: "how long to wait for the runs (15m), a bare number in minutes" },
|
|
3808
|
+
json: jsonOption("what was released and how its runs ended")
|
|
3649
3809
|
};
|
|
3650
3810
|
async function release(args) {
|
|
3811
|
+
return cut(args);
|
|
3812
|
+
}
|
|
3813
|
+
async function cut(args, sink) {
|
|
3651
3814
|
const parsed = parse(args, usage6, options6);
|
|
3652
3815
|
const { values, positionals } = parsed;
|
|
3816
|
+
const json = values.json === true;
|
|
3817
|
+
const say = json ? console.error : console.log;
|
|
3818
|
+
if (json && values["dry-run"] === true)
|
|
3819
|
+
fail("--json does not take --dry-run");
|
|
3653
3820
|
const level = positionals[0];
|
|
3654
3821
|
const tagged = values.tagged === true;
|
|
3655
3822
|
if (tagged === (level !== undefined))
|
|
@@ -3658,6 +3825,36 @@ async function release(args) {
|
|
|
3658
3825
|
${usage6}`);
|
|
3659
3826
|
if (level !== undefined && !LEVELS.has(level) && !VERSION.test(level))
|
|
3660
3827
|
fail(`${level} is no level nor x.y.z version`);
|
|
3828
|
+
if (values.all === true || SEVERAL.test(values.package ?? "")) {
|
|
3829
|
+
if (tagged || level === undefined)
|
|
3830
|
+
fail("--all and several packages take a level, not --tagged");
|
|
3831
|
+
if (values.all === true && values.package !== undefined)
|
|
3832
|
+
fail("give --all or --package, not both");
|
|
3833
|
+
const targets = parseTargets(values.package ?? (await publishable()).join(","), level);
|
|
3834
|
+
const flags = [...json ? ["--json"] : [], ...values["dry-run"] === true ? ["--dry-run"] : [], ...values["no-registry"] === true ? ["--no-registry"] : [], ...values.timeout === undefined ? [] : ["--timeout", values.timeout]];
|
|
3835
|
+
const results = [];
|
|
3836
|
+
for (const [index, target] of targets.entries()) {
|
|
3837
|
+
say(`== ${target.level} ${target.folder} (${index + 1}/${targets.length})`);
|
|
3838
|
+
const stopped = () => console.error(`stopped at ${target.folder}, not released: ${targets.slice(index).map((each) => each.folder).join(", ")}`);
|
|
3839
|
+
try {
|
|
3840
|
+
const code = await cut([target.level, "--package", target.folder, ...flags], results);
|
|
3841
|
+
if (code === 0)
|
|
3842
|
+
continue;
|
|
3843
|
+
stopped();
|
|
3844
|
+
if (json)
|
|
3845
|
+
printJson(results);
|
|
3846
|
+
return code;
|
|
3847
|
+
} catch (error) {
|
|
3848
|
+
stopped();
|
|
3849
|
+
if (json)
|
|
3850
|
+
printJson(results);
|
|
3851
|
+
throw error;
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
if (json)
|
|
3855
|
+
printJson(results);
|
|
3856
|
+
return 0;
|
|
3857
|
+
}
|
|
3661
3858
|
const timeout = duration(values.timeout, "timeout", 15 * 60000, "m");
|
|
3662
3859
|
const dir = values.package === undefined ? undefined : await packageDir(values.package);
|
|
3663
3860
|
const prefix = dir === undefined ? "v" : `${basename3(dir)}-v`;
|
|
@@ -3673,7 +3870,7 @@ ${usage6}`);
|
|
|
3673
3870
|
const base = await git(["rev-parse", tagged ? "HEAD~1" : "HEAD"]);
|
|
3674
3871
|
if (values["dry-run"] === true)
|
|
3675
3872
|
return printPlan({ level, dir, prefix, branch, base, timeout, registry: values["no-registry"] !== true });
|
|
3676
|
-
if (!await testsPass(base, branch, timeout))
|
|
3873
|
+
if (!await testsPass(base, branch, timeout, json))
|
|
3677
3874
|
fail(`the runs on ${base.slice(0, 7)} failed, so nothing was bumped or tagged`, 1, runHint(`ft runs --sha ${base.slice(0, 7)}`, "list the runs, then ft logs <id> reads the failure"));
|
|
3678
3875
|
const preBump = await git(["rev-parse", "HEAD"]);
|
|
3679
3876
|
const tagsBefore = new Set(await tagsAt("HEAD"));
|
|
@@ -3701,7 +3898,7 @@ ${usage6}`);
|
|
|
3701
3898
|
fail(`interrupted by ${held.signal} before the push`, exitCodeOf(null, held.signal));
|
|
3702
3899
|
let push;
|
|
3703
3900
|
try {
|
|
3704
|
-
push = await runTool("git push", ["git", "push", "--atomic", "origin", `HEAD:refs/heads/${branch}`, tag], { timeoutMs: limits.pushMs, onStart: (child) => held.forward(child) });
|
|
3901
|
+
push = await runTool("git push", ["git", "push", "--atomic", "origin", `HEAD:refs/heads/${branch}`, `refs/tags/${tag}`], { timeoutMs: limits.pushMs, onStart: (child) => held.forward(child) });
|
|
3705
3902
|
} catch (error) {
|
|
3706
3903
|
isPushUnknown = true;
|
|
3707
3904
|
fail(`${error instanceof Error ? error.message : String(error)}, so ${tag} and its commit are kept: the push may have landed`, 2, `git ls-remote origin refs/tags/${tag} tells; if it is there, ft release --tagged waits for its runs`);
|
|
@@ -3715,42 +3912,58 @@ ${push.stderr.trim()}`, signal === undefined ? 1 : exitCodeOf(null, signal));
|
|
|
3715
3912
|
} finally {
|
|
3716
3913
|
held.release();
|
|
3717
3914
|
if (!pushed && !isPushUnknown && level !== undefined)
|
|
3718
|
-
await rollBack(preBump, tagsBefore);
|
|
3915
|
+
await rollBack(preBump, tagsBefore, dir);
|
|
3719
3916
|
}
|
|
3720
|
-
const
|
|
3721
|
-
if (late !== undefined)
|
|
3722
|
-
fail(`interrupted by ${late} after ${tag} was pushed: its runs are not waited for`, exitCodeOf(null, late));
|
|
3723
|
-
console.log(`pushed ${branch} and ${tag}, waiting for their runs`);
|
|
3724
|
-
const code = await watchRuns((runs) => runs.filter((run) => run.id > before && run.commit_sha === head), timeout, undefined, NO_RUN2);
|
|
3725
|
-
if (code !== 0)
|
|
3726
|
-
return code;
|
|
3727
|
-
const file = Bun.file(join5(dir ?? ".", "package.json"));
|
|
3917
|
+
const file = Bun.file(join8(dir ?? ".", "package.json"));
|
|
3728
3918
|
const pkg = await file.exists() ? await file.json() : undefined;
|
|
3729
3919
|
const version = tag.slice(prefix.length);
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3920
|
+
let followed = { code: 0, runs: [], failedJobs: [] };
|
|
3921
|
+
const outcome = (released) => {
|
|
3922
|
+
if (!json)
|
|
3923
|
+
return;
|
|
3924
|
+
const result = { released, tag, package: pkg?.name ?? null, version, ...ciJson(followed.runs, followed.failedJobs) };
|
|
3925
|
+
if (sink === undefined)
|
|
3926
|
+
printJson(result);
|
|
3927
|
+
else
|
|
3928
|
+
sink.push(result);
|
|
3929
|
+
};
|
|
3930
|
+
try {
|
|
3931
|
+
const late = signalOf();
|
|
3932
|
+
if (late !== undefined)
|
|
3933
|
+
fail(`interrupted by ${late} after ${tag} was pushed: its runs are not waited for`, exitCodeOf(null, late));
|
|
3934
|
+
say(`pushed ${branch} and ${tag}, waiting for their runs`);
|
|
3935
|
+
followed = await followRuns((runs) => runs.filter((run) => run.id > before && run.commit_sha === head), timeout, undefined, NO_RUN2, json ? process19.stderr : process19.stdout, { json });
|
|
3936
|
+
if (followed.code !== 0) {
|
|
3937
|
+
outcome(false);
|
|
3938
|
+
return followed.code;
|
|
3939
|
+
}
|
|
3940
|
+
if (values["no-registry"] === true || pkg?.name === undefined || pkg.private === true) {
|
|
3941
|
+
say(`released ${tag}`);
|
|
3942
|
+
await settleMilestone(version, tag, say);
|
|
3943
|
+
outcome(true);
|
|
3944
|
+
return 0;
|
|
3945
|
+
}
|
|
3946
|
+
if (!await waitForRegistry(pkg.name, version))
|
|
3947
|
+
fail(`the runs passed but the registry does not serve ${pkg.name}@${version}: read the publish job with \`ft logs\``, 1);
|
|
3948
|
+
say(`released ${pkg.name}@${version}`);
|
|
3949
|
+
await settleMilestone(version, tag, say);
|
|
3950
|
+
outcome(true);
|
|
3733
3951
|
return 0;
|
|
3952
|
+
} catch (error) {
|
|
3953
|
+
outcome(false);
|
|
3954
|
+
throw error;
|
|
3734
3955
|
}
|
|
3735
|
-
if (!await waitForRegistry(pkg.name, version))
|
|
3736
|
-
fail(`the runs passed but the registry does not serve ${pkg.name}@${version}: read the publish job with \`ft logs\``, 1);
|
|
3737
|
-
console.log(`released ${pkg.name}@${version}`);
|
|
3738
|
-
await settleMilestone(version, tag);
|
|
3739
|
-
return 0;
|
|
3740
3956
|
}
|
|
3741
3957
|
|
|
3742
3958
|
// src/commands/remote.ts
|
|
3743
3959
|
import { lookup } from "dns/promises";
|
|
3744
|
-
import { homedir as homedir4 } from "os";
|
|
3745
3960
|
var {$: $3 } = globalThis.Bun;
|
|
3746
3961
|
|
|
3747
3962
|
// src/config.ts
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
function settingsPath(home = homedir3()) {
|
|
3751
|
-
return join6(home, ".config", "ft", "config.json");
|
|
3963
|
+
function settingsPath(home) {
|
|
3964
|
+
return userConfigReadPath("ft", [["ft", "config.json"]], { home });
|
|
3752
3965
|
}
|
|
3753
|
-
async function loadSettings(home
|
|
3966
|
+
async function loadSettings(home) {
|
|
3754
3967
|
const path = settingsPath(home);
|
|
3755
3968
|
const file = Bun.file(path);
|
|
3756
3969
|
if (!await file.exists())
|
|
@@ -3811,14 +4024,20 @@ var usage7 = `ft remote [--fix]
|
|
|
3811
4024
|
|
|
3812
4025
|
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\`.
|
|
3813
4026
|
--fix switches every alias URL to \`git@<host>:<owner>/<repo>.git\` and proves it with \`git ls-remote\`.
|
|
3814
|
-
The host comes from --host, else \`remoteHost\` in ~/.config/ft
|
|
4027
|
+
The host comes from --host, else \`remoteHost\` in ~/.config/kaynooo-cli/ft.json; with neither, it checks nothing.
|
|
3815
4028
|
|
|
3816
4029
|
Exits 0 when origin names the Forgejo host (or was switched) or no host is set, 1 when it does not or a switch is still to run, 2 on a usage error.`;
|
|
3817
4030
|
var options7 = {
|
|
3818
|
-
host: { type: "string", description: "the Forgejo ssh host, instead of remoteHost in ~/.config/ft
|
|
4031
|
+
host: { type: "string", description: "the Forgejo ssh host, instead of remoteHost in ~/.config/kaynooo-cli/ft.json" },
|
|
3819
4032
|
fix: { type: "boolean", description: "rewrite the alias URLs" }
|
|
3820
4033
|
};
|
|
3821
4034
|
var HOSTNAME = /^hostname (.+)$/m;
|
|
4035
|
+
var limits2 = { lsRemoteMs: 30000 };
|
|
4036
|
+
async function proveOrigin() {
|
|
4037
|
+
const { code, stderr } = await runTool("git ls-remote", ["git", "ls-remote", "origin", "HEAD"], { timeoutMs: limits2.lsRemoteMs });
|
|
4038
|
+
if (code !== 0)
|
|
4039
|
+
throw new Error(stderr.trim());
|
|
4040
|
+
}
|
|
3822
4041
|
async function sshHostname(alias) {
|
|
3823
4042
|
return HOSTNAME.exec(await $3`ssh -G -- ${alias}`.quiet().nothrow().text())?.[1];
|
|
3824
4043
|
}
|
|
@@ -3840,7 +4059,7 @@ async function restoreOrigin(fetchUrl, pushUrls, changes) {
|
|
|
3840
4059
|
function originHost(url) {
|
|
3841
4060
|
return parseSshRemote(url)?.host ?? (URL.canParse(url) ? new URL(url).hostname : undefined);
|
|
3842
4061
|
}
|
|
3843
|
-
async function remote(args, home
|
|
4062
|
+
async function remote(args, home) {
|
|
3844
4063
|
const { values } = parse(args, usage7, options7);
|
|
3845
4064
|
const host = values.host ?? (await loadSettings(home)).remoteHost;
|
|
3846
4065
|
if (host === undefined) {
|
|
@@ -3887,7 +4106,7 @@ async function remote(args, home = homedir4()) {
|
|
|
3887
4106
|
await git(["remote", "set-url", "--push", "origin", to, from]);
|
|
3888
4107
|
}
|
|
3889
4108
|
try {
|
|
3890
|
-
await
|
|
4109
|
+
await proveOrigin();
|
|
3891
4110
|
} catch (error) {
|
|
3892
4111
|
await restoreOrigin(fetchUrl, pushUrls, changes);
|
|
3893
4112
|
return fail(`the switched origin does not answer, so the old URLs were put back: ${redactUrl(error instanceof Error ? error.message : String(error))}`, 1);
|
|
@@ -3942,35 +4161,34 @@ async function runs(args) {
|
|
|
3942
4161
|
}
|
|
3943
4162
|
|
|
3944
4163
|
// src/cli.ts
|
|
3945
|
-
|
|
4164
|
+
process20.exitCode = await runCli({
|
|
3946
4165
|
name: "ft",
|
|
3947
|
-
version,
|
|
3948
4166
|
about: "Forgejo tools over tea, run from a repository whose origin is on Forgejo",
|
|
3949
4167
|
replaces: "tea api calls piped through jq, and sleep loops waiting on CI",
|
|
3950
4168
|
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"]],
|
|
3951
4169
|
commands: {
|
|
3952
|
-
runs: { run: runs, summary: "recent runs with workflow, ref, duration and age" },
|
|
3953
|
-
ci: { run: ci2, summary: "wait for the runs covering a commit, printing what failed" },
|
|
3954
|
-
watch: { run: watch, summary: "wait for runs newer than an id, or those in progress" },
|
|
3955
|
-
logs: { run: logs2, summary: "what the failed jobs of a run say went wrong" },
|
|
3956
|
-
release: { run: release, summary: "bump, push branch and tag atomically, wait for runs and registry" },
|
|
3957
|
-
board: { run: board, summary: "open issues: available, taken by a live session, or claimed by one gone" },
|
|
3958
|
-
digest: { run: digest, summary: "repo state for a cold start: held and abandoned claims, red CI, unpushed commits, dirty files, stale TODOs" },
|
|
3959
|
-
take: { run: take, summary: "claim an issue for this Claude Code session" },
|
|
3960
|
-
drop: { run: drop, summary: "give back an issue this session took" },
|
|
3961
|
-
issue: { run: issue, summary: "an issue's claim, description and numbered boxes, -c comments" },
|
|
3962
|
-
new: { run: newIssue, summary: "create an issue from -t and a description file or stdin" },
|
|
3963
|
-
edit: { run: edit, summary: "replace an issue's title or description, from a file or stdin" },
|
|
3964
|
-
tick: { run: tick, summary: "tick checklist boxes of an issue, -m to comment too" },
|
|
3965
|
-
comment: { run: commentOn, summary: "comment on an issue, from stdin when no text is given" },
|
|
3966
|
-
fixed: { run: fixed, summary: 'comment "Fixed in <sha>" and close an issue' },
|
|
3967
|
-
close: { run: closeIssues, summary: "close issues without a fix, -m posting the reason" },
|
|
3968
|
-
reopen: { run: reopenIssues, summary: "reopen closed issues, -m posting the reason" },
|
|
3969
|
-
label: { run: label, summary: "add +name and remove -name labels of an issue" },
|
|
3970
|
-
plan,
|
|
3971
|
-
milestones: { run: milestones, summary: "milestones with their open and closed issues, progress and due date" },
|
|
3972
|
-
milestone: { run: milestone, summary: "show a milestone's issues like the board, `new` creates one, `close` closes it" },
|
|
3973
|
-
remote: { run: remote, summary: "check or fix an origin using an ssh alias tea cannot match" }
|
|
4170
|
+
runs: { run: runs, summary: "recent runs with workflow, ref, duration and age", group: "CI and release" },
|
|
4171
|
+
ci: { run: ci2, summary: "wait for the runs covering a commit, printing what failed", group: "CI and release" },
|
|
4172
|
+
watch: { run: watch, summary: "wait for runs newer than an id, or those in progress", group: "CI and release" },
|
|
4173
|
+
logs: { run: logs2, summary: "what the failed jobs of a run say went wrong", group: "CI and release" },
|
|
4174
|
+
release: { run: release, summary: "bump, push branch and tag atomically, wait for runs and registry", group: "CI and release" },
|
|
4175
|
+
board: { run: board, summary: "open issues: available, taken by a live session, or claimed by one gone", group: "Issues and claims" },
|
|
4176
|
+
digest: { run: digest, summary: "repo state for a cold start: held and abandoned claims, red CI, unpushed commits, dirty files, stale TODOs", group: "Issues and claims" },
|
|
4177
|
+
take: { run: take, summary: "claim an issue for this Claude Code session", group: "Issues and claims" },
|
|
4178
|
+
drop: { run: drop, summary: "give back an issue this session took", group: "Issues and claims" },
|
|
4179
|
+
issue: { run: issue, summary: "an issue's claim, description and numbered boxes, -c comments", group: "Issues and claims" },
|
|
4180
|
+
new: { run: newIssue, summary: "create an issue from -t and a description file or stdin", group: "Issues and claims" },
|
|
4181
|
+
edit: { run: edit, summary: "replace an issue's title or description, from a file or stdin", group: "Issues and claims" },
|
|
4182
|
+
tick: { run: tick, summary: "tick checklist boxes of an issue, -m to comment too", group: "Issues and claims" },
|
|
4183
|
+
comment: { run: commentOn, summary: "comment on an issue, from stdin when no text is given", group: "Issues and claims" },
|
|
4184
|
+
fixed: { run: fixed, summary: 'comment "Fixed in <sha>" and close an issue', group: "Issues and claims" },
|
|
4185
|
+
close: { run: closeIssues, summary: "close issues without a fix, -m posting the reason", group: "Issues and claims" },
|
|
4186
|
+
reopen: { run: reopenIssues, summary: "reopen closed issues, -m posting the reason", group: "Issues and claims" },
|
|
4187
|
+
label: { run: label, summary: "add +name and remove -name labels of an issue", group: "Issues and claims" },
|
|
4188
|
+
plan: { ...plan, group: "Repo" },
|
|
4189
|
+
milestones: { run: milestones, summary: "milestones with their open and closed issues, progress and due date", group: "Repo" },
|
|
4190
|
+
milestone: { run: milestone, summary: "show a milestone's issues like the board, `new` creates one, `close` closes it", group: "Repo" },
|
|
4191
|
+
remote: { run: remote, summary: "check or fix an origin using an ssh alias tea cannot match", group: "Repo" }
|
|
3974
4192
|
},
|
|
3975
4193
|
aliases: { show: "issue", view: "issue" }
|
|
3976
4194
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-forgejo",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.15.0",
|
|
5
5
|
"description": "ft: Forgejo CI runs, logs, releases and issue checklists from the terminal, through tea.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|