@kaynooo/cli-forgejo 0.12.0 → 0.13.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/dist/cli.js +656 -554
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process18 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/args.ts
|
|
8
|
-
import
|
|
8
|
+
import process6 from "process";
|
|
9
9
|
import { parseArgs } from "util";
|
|
10
10
|
|
|
11
11
|
// ../kit/src/format.ts
|
|
@@ -398,6 +398,55 @@ function printJson(value) {
|
|
|
398
398
|
console.log(JSON.stringify(value, undefined, 2));
|
|
399
399
|
}
|
|
400
400
|
|
|
401
|
+
// ../kit/src/help.ts
|
|
402
|
+
import process4 from "process";
|
|
403
|
+
var OPTIONAL = /\[[^\]]+\]/g;
|
|
404
|
+
var USAGE_PREFIX = /^usage:\s*/i;
|
|
405
|
+
var FULL_STOP = /\.$/;
|
|
406
|
+
function usageLine(usage, colors = paint(process4.stdout)) {
|
|
407
|
+
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
408
|
+
}
|
|
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(`
|
|
411
|
+
`);
|
|
412
|
+
}
|
|
413
|
+
function replacesRows(replaces, colors = paint(process4.stdout)) {
|
|
414
|
+
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
415
|
+
}
|
|
416
|
+
function wantsHelpJson(env = process4.env) {
|
|
417
|
+
return env.KIT_HELP === "json";
|
|
418
|
+
}
|
|
419
|
+
function description(usage, { examples = [], replaces } = {}) {
|
|
420
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
421
|
+
`);
|
|
422
|
+
const first = lines[0];
|
|
423
|
+
const colon = first.indexOf(": ");
|
|
424
|
+
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
425
|
+
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
426
|
+
return {
|
|
427
|
+
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
428
|
+
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
429
|
+
...replaces === undefined ? {} : { replaces },
|
|
430
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function exampleRows(examples, colors = paint(process4.stdout)) {
|
|
434
|
+
if (examples.length === 0)
|
|
435
|
+
return [];
|
|
436
|
+
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
437
|
+
}
|
|
438
|
+
function optionRows(options, colors = paint(process4.stdout)) {
|
|
439
|
+
const rows = Object.entries(options).map(([name, option]) => {
|
|
440
|
+
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
441
|
+
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
442
|
+
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
443
|
+
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
444
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
445
|
+
});
|
|
446
|
+
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
447
|
+
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
448
|
+
}
|
|
449
|
+
|
|
401
450
|
// ../kit/src/text.ts
|
|
402
451
|
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
403
452
|
function distance(a, b) {
|
|
@@ -417,8 +466,42 @@ function closest(name, names) {
|
|
|
417
466
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
418
467
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
419
468
|
}
|
|
469
|
+
// ../kit/src/input.ts
|
|
470
|
+
import process5 from "process";
|
|
471
|
+
var WHOLE = /^\d+$/;
|
|
472
|
+
function wholeNumber(value, name, fallback, min = 1) {
|
|
473
|
+
if (value === undefined)
|
|
474
|
+
return fallback;
|
|
475
|
+
const number = Number(value);
|
|
476
|
+
if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
|
|
477
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
478
|
+
return number;
|
|
479
|
+
}
|
|
480
|
+
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
481
|
+
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
482
|
+
function duration(value, name, fallback, unit = "s") {
|
|
483
|
+
if (value === undefined)
|
|
484
|
+
return fallback;
|
|
485
|
+
const match = DURATION.exec(value.trim());
|
|
486
|
+
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
487
|
+
if (ms < 1)
|
|
488
|
+
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
489
|
+
return ms;
|
|
490
|
+
}
|
|
491
|
+
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
492
|
+
if (path === "-") {
|
|
493
|
+
if (process5.stdin.isTTY)
|
|
494
|
+
fail(noStdin);
|
|
495
|
+
return Bun.stdin.text();
|
|
496
|
+
}
|
|
497
|
+
const file = Bun.file(path);
|
|
498
|
+
if (!await file.exists())
|
|
499
|
+
fail(`no file ${path}`);
|
|
500
|
+
return file.text();
|
|
501
|
+
}
|
|
420
502
|
|
|
421
503
|
// ../kit/src/args.ts
|
|
504
|
+
var DASHES = /^-+/;
|
|
422
505
|
function jsonOption(holds) {
|
|
423
506
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
424
507
|
}
|
|
@@ -462,58 +545,11 @@ class Completing {
|
|
|
462
545
|
}
|
|
463
546
|
}
|
|
464
547
|
var completion = { active: false };
|
|
465
|
-
var OPTIONAL = /\[[^\]]+\]/g;
|
|
466
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
467
|
-
var FULL_STOP = /\.$/;
|
|
468
|
-
var DASHES = /^-+/;
|
|
469
|
-
function usageLine(usage, colors = paint(process4.stdout)) {
|
|
470
|
-
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
471
|
-
}
|
|
472
|
-
function helpText(usage, options, colors = paint(process4.stdout), { examples = [], replaces } = {}) {
|
|
473
|
-
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
474
|
-
`);
|
|
475
|
-
}
|
|
476
|
-
function replacesRows(replaces, colors = paint(process4.stdout)) {
|
|
477
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
478
|
-
}
|
|
479
|
-
function wantsHelpJson(env = process4.env) {
|
|
480
|
-
return env.KIT_HELP === "json";
|
|
481
|
-
}
|
|
482
|
-
function description(usage, { examples = [], replaces } = {}) {
|
|
483
|
-
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
484
|
-
`);
|
|
485
|
-
const first = lines[0];
|
|
486
|
-
const colon = first.indexOf(": ");
|
|
487
|
-
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
488
|
-
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
489
|
-
return {
|
|
490
|
-
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
491
|
-
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
492
|
-
...replaces === undefined ? {} : { replaces },
|
|
493
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
function exampleRows(examples, colors = paint(process4.stdout)) {
|
|
497
|
-
if (examples.length === 0)
|
|
498
|
-
return [];
|
|
499
|
-
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
500
|
-
}
|
|
501
|
-
function optionRows(options, colors = paint(process4.stdout)) {
|
|
502
|
-
const rows = Object.entries(options).map(([name, option]) => {
|
|
503
|
-
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
504
|
-
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
505
|
-
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
506
|
-
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
507
|
-
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
508
|
-
});
|
|
509
|
-
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
510
|
-
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
511
|
-
}
|
|
512
548
|
var OUTPUT_OPTIONS = {
|
|
513
549
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
514
550
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
515
551
|
};
|
|
516
|
-
function applyOutput(color, plain, env =
|
|
552
|
+
function applyOutput(color, plain, env = process6.env) {
|
|
517
553
|
const when = plain === true ? "never" : color ?? "auto";
|
|
518
554
|
if (when === "auto")
|
|
519
555
|
return;
|
|
@@ -670,43 +706,12 @@ function nearestOption(message, options, allowNegative) {
|
|
|
670
706
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
671
707
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
672
708
|
}
|
|
673
|
-
var WHOLE = /^\d+$/;
|
|
674
|
-
function wholeNumber(value, name, fallback, min = 1) {
|
|
675
|
-
if (value === undefined)
|
|
676
|
-
return fallback;
|
|
677
|
-
const number = Number(value);
|
|
678
|
-
if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
|
|
679
|
-
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
680
|
-
return number;
|
|
681
|
-
}
|
|
682
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
683
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
684
|
-
function duration(value, name, fallback, unit = "s") {
|
|
685
|
-
if (value === undefined)
|
|
686
|
-
return fallback;
|
|
687
|
-
const match = DURATION.exec(value.trim());
|
|
688
|
-
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
689
|
-
if (ms < 1)
|
|
690
|
-
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
691
|
-
return ms;
|
|
692
|
-
}
|
|
693
|
-
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
694
|
-
if (path === "-") {
|
|
695
|
-
if (process4.stdin.isTTY)
|
|
696
|
-
fail(noStdin);
|
|
697
|
-
return Bun.stdin.text();
|
|
698
|
-
}
|
|
699
|
-
const file = Bun.file(path);
|
|
700
|
-
if (!await file.exists())
|
|
701
|
-
fail(`no file ${path}`);
|
|
702
|
-
return file.text();
|
|
703
|
-
}
|
|
704
709
|
// ../kit/src/progress.ts
|
|
705
|
-
import
|
|
710
|
+
import process8 from "process";
|
|
706
711
|
|
|
707
712
|
// ../kit/src/process.ts
|
|
708
713
|
import { constants } from "os";
|
|
709
|
-
import
|
|
714
|
+
import process7 from "process";
|
|
710
715
|
var KILL_GRACE_MS = 2000;
|
|
711
716
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
712
717
|
function exitCodeOf(code, signal) {
|
|
@@ -728,7 +733,7 @@ function holdSignals(cleanup) {
|
|
|
728
733
|
},
|
|
729
734
|
release: () => {
|
|
730
735
|
for (const signal of SIGNALS)
|
|
731
|
-
|
|
736
|
+
process7.off(signal, onSignal);
|
|
732
737
|
}
|
|
733
738
|
};
|
|
734
739
|
function onSignal(signal) {
|
|
@@ -741,10 +746,10 @@ function holdSignals(cleanup) {
|
|
|
741
746
|
return;
|
|
742
747
|
held.release();
|
|
743
748
|
cleanup(signal);
|
|
744
|
-
|
|
749
|
+
process7.kill(process7.pid, signal);
|
|
745
750
|
}
|
|
746
751
|
for (const signal of SIGNALS)
|
|
747
|
-
|
|
752
|
+
process7.on(signal, onSignal);
|
|
748
753
|
return held;
|
|
749
754
|
}
|
|
750
755
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -758,7 +763,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
758
763
|
return;
|
|
759
764
|
try {
|
|
760
765
|
if (grouped)
|
|
761
|
-
|
|
766
|
+
process7.kill(-proc.pid, killing);
|
|
762
767
|
else
|
|
763
768
|
proc.kill(killing);
|
|
764
769
|
} catch {}
|
|
@@ -837,7 +842,7 @@ var RESET_STYLE = `${ESC}[0m`;
|
|
|
837
842
|
var CTRL_C = 3;
|
|
838
843
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
839
844
|
var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
|
|
840
|
-
function liveRegion(render, stream =
|
|
845
|
+
function liveRegion(render, stream = process8.stderr, env = process8.env) {
|
|
841
846
|
if (!takesControlCodes(stream, env))
|
|
842
847
|
return { redraw: () => {
|
|
843
848
|
return;
|
|
@@ -878,11 +883,11 @@ function liveRegion(render, stream = process6.stderr, env = process6.env) {
|
|
|
878
883
|
clear();
|
|
879
884
|
restore();
|
|
880
885
|
release();
|
|
881
|
-
|
|
886
|
+
process8.off("exit", onExit);
|
|
882
887
|
signals.release();
|
|
883
888
|
}
|
|
884
889
|
timer.unref();
|
|
885
|
-
|
|
890
|
+
process8.on("exit", onExit);
|
|
886
891
|
return {
|
|
887
892
|
redraw: draw,
|
|
888
893
|
print: (text) => {
|
|
@@ -921,14 +926,14 @@ function cutToWidth(line, width) {
|
|
|
921
926
|
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
922
927
|
}
|
|
923
928
|
function swallowInput() {
|
|
924
|
-
const input =
|
|
929
|
+
const input = process8.stdin;
|
|
925
930
|
if (!input.isTTY)
|
|
926
931
|
return () => {
|
|
927
932
|
return;
|
|
928
933
|
};
|
|
929
934
|
const onData = (data) => {
|
|
930
935
|
if (data.includes(CTRL_C))
|
|
931
|
-
|
|
936
|
+
process8.kill(process8.pid, "SIGINT");
|
|
932
937
|
};
|
|
933
938
|
input.setRawMode(true);
|
|
934
939
|
input.on("data", onData);
|
|
@@ -944,7 +949,7 @@ function swallowInput() {
|
|
|
944
949
|
};
|
|
945
950
|
}
|
|
946
951
|
function interceptOutput(clear) {
|
|
947
|
-
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [
|
|
952
|
+
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process8.stdout, "write"], [process8.stderr, "write"]];
|
|
948
953
|
const wrapped = targets.map(([target, name]) => {
|
|
949
954
|
const original = Reflect.get(target, name);
|
|
950
955
|
const wrapper = (...args) => {
|
|
@@ -963,11 +968,11 @@ function interceptOutput(clear) {
|
|
|
963
968
|
}
|
|
964
969
|
|
|
965
970
|
// ../kit/src/tool.ts
|
|
966
|
-
import
|
|
971
|
+
import process9 from "process";
|
|
967
972
|
var PERMANENT = /\bHTTP (?:401|403|404)\b|unauthorized|forbidden|not found|couldn't be found|token is required/i;
|
|
968
973
|
function cwdGone() {
|
|
969
974
|
try {
|
|
970
|
-
|
|
975
|
+
process9.cwd();
|
|
971
976
|
return false;
|
|
972
977
|
} catch {
|
|
973
978
|
return true;
|
|
@@ -994,7 +999,7 @@ function isPermanentFailure(error) {
|
|
|
994
999
|
async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
995
1000
|
let ran;
|
|
996
1001
|
try {
|
|
997
|
-
ran = await runCommand(argv, { env:
|
|
1002
|
+
ran = await runCommand(argv, { env: process9.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
|
|
998
1003
|
} catch (error) {
|
|
999
1004
|
throw spawnFailure(label, error);
|
|
1000
1005
|
}
|
|
@@ -1073,7 +1078,59 @@ async function waitForCi(wait) {
|
|
|
1073
1078
|
}
|
|
1074
1079
|
}
|
|
1075
1080
|
// ../kit/src/cli.ts
|
|
1076
|
-
import
|
|
1081
|
+
import process11 from "process";
|
|
1082
|
+
|
|
1083
|
+
// ../kit/src/usage.ts
|
|
1084
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
1085
|
+
import { homedir } from "os";
|
|
1086
|
+
import { dirname, isAbsolute, join } from "path";
|
|
1087
|
+
import process10 from "process";
|
|
1088
|
+
|
|
1089
|
+
// ../kit/src/logs.ts
|
|
1090
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
1091
|
+
var CLI_FOLDER = "kaynooo-cli";
|
|
1092
|
+
|
|
1093
|
+
// ../kit/src/usage.ts
|
|
1094
|
+
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1095
|
+
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1096
|
+
var LONGEST_NAME = 40;
|
|
1097
|
+
var usageError;
|
|
1098
|
+
function noteUsageError(message) {
|
|
1099
|
+
usageError = message;
|
|
1100
|
+
}
|
|
1101
|
+
function stateHome(env = process10.env) {
|
|
1102
|
+
const dir = env.XDG_STATE_HOME;
|
|
1103
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
|
|
1104
|
+
}
|
|
1105
|
+
function usagePath(env = process10.env) {
|
|
1106
|
+
return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1107
|
+
}
|
|
1108
|
+
function usageRecorded(env = process10.env) {
|
|
1109
|
+
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1110
|
+
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1111
|
+
}
|
|
1112
|
+
function flagNames(argv) {
|
|
1113
|
+
const end = argv.indexOf("--");
|
|
1114
|
+
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1115
|
+
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1116
|
+
}
|
|
1117
|
+
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
1118
|
+
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1119
|
+
usageError = undefined;
|
|
1120
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1121
|
+
}
|
|
1122
|
+
function recordUsage(entry, env = process10.env) {
|
|
1123
|
+
if (!usageRecorded(env))
|
|
1124
|
+
return;
|
|
1125
|
+
try {
|
|
1126
|
+
const path = usagePath(env);
|
|
1127
|
+
mkdirSync(dirname(path), { recursive: true, mode: 448 });
|
|
1128
|
+
appendFileSync(path, `${JSON.stringify(entry)}
|
|
1129
|
+
`, { mode: 384 });
|
|
1130
|
+
} catch {}
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
// ../kit/src/cli.ts
|
|
1077
1134
|
var LEVEL_OPTIONS = {
|
|
1078
1135
|
...OUTPUT_OPTIONS,
|
|
1079
1136
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
@@ -1126,7 +1183,7 @@ async function expand(scope, words) {
|
|
|
1126
1183
|
}
|
|
1127
1184
|
return { ...scope, commands, lazy: [] };
|
|
1128
1185
|
}
|
|
1129
|
-
async function
|
|
1186
|
+
async function help2({ path, header, summary: lazySummary, commands, defaultCommand, examples, replaces }, stream) {
|
|
1130
1187
|
const colors = paint(stream);
|
|
1131
1188
|
const prefix = path.join(" ");
|
|
1132
1189
|
const summary = await resolveSummary(lazySummary);
|
|
@@ -1153,8 +1210,8 @@ async function help({ path, header, summary: lazySummary, commands, defaultComma
|
|
|
1153
1210
|
`);
|
|
1154
1211
|
}
|
|
1155
1212
|
function printError(prefix, message, hint, cause) {
|
|
1156
|
-
const colors = paint(
|
|
1157
|
-
const styled = takesControlCodes(
|
|
1213
|
+
const colors = paint(process11.stderr);
|
|
1214
|
+
const styled = takesControlCodes(process11.stderr);
|
|
1158
1215
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1159
1216
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1160
1217
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1164,8 +1221,8 @@ function runHint(command, effect) {
|
|
|
1164
1221
|
return `run \`${command}\`${effect === undefined ? "" : ` to ${effect}`}`;
|
|
1165
1222
|
}
|
|
1166
1223
|
function printHint(hint) {
|
|
1167
|
-
const colors = paint(
|
|
1168
|
-
console.error(` ${takesControlCodes(
|
|
1224
|
+
const colors = paint(process11.stderr);
|
|
1225
|
+
console.error(` ${takesControlCodes(process11.stderr) ? colors.yellow("hint") : "hint:"} ${hint}`);
|
|
1169
1226
|
}
|
|
1170
1227
|
function printJsonError(message, hint, cause) {
|
|
1171
1228
|
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
@@ -1180,6 +1237,8 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
1180
1237
|
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
1181
1238
|
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
1182
1239
|
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
1240
|
+
if (error instanceof UsageError)
|
|
1241
|
+
noteUsageError(error.message);
|
|
1183
1242
|
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
1184
1243
|
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
1185
1244
|
return error instanceof Exit ? error.code : 1;
|
|
@@ -1202,11 +1261,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1202
1261
|
}
|
|
1203
1262
|
}
|
|
1204
1263
|
if (name === undefined && level.path.length > 1) {
|
|
1205
|
-
console.error(await
|
|
1264
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process11.stderr));
|
|
1206
1265
|
return 2;
|
|
1207
1266
|
}
|
|
1208
1267
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1209
|
-
console.log(await
|
|
1268
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process11.stdout));
|
|
1210
1269
|
return 0;
|
|
1211
1270
|
}
|
|
1212
1271
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1322,14 +1381,35 @@ async function printCandidates(found) {
|
|
|
1322
1381
|
console.log(line);
|
|
1323
1382
|
return 0;
|
|
1324
1383
|
}
|
|
1325
|
-
async function runCli(cli, argv =
|
|
1384
|
+
async function runCli(cli, argv = process11.argv.slice(2)) {
|
|
1326
1385
|
if (argv[0] === COMPLETE)
|
|
1327
1386
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1328
|
-
|
|
1387
|
+
const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(cli.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: cli.version, redact: cli.redact });
|
|
1388
|
+
if (cli.usage !== false) {
|
|
1389
|
+
try {
|
|
1390
|
+
recordUsage(usageEntry(cli.name, commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv), argv, code));
|
|
1391
|
+
} catch {}
|
|
1392
|
+
}
|
|
1393
|
+
return code;
|
|
1394
|
+
}
|
|
1395
|
+
function commandPath(scope, argv) {
|
|
1396
|
+
const path = [];
|
|
1397
|
+
let level = scope;
|
|
1398
|
+
for (const word of argv.filter((each) => !each.startsWith("-"))) {
|
|
1399
|
+
const name = level.aliases !== undefined && Object.hasOwn(level.aliases, word) ? level.aliases[word] ?? word : word;
|
|
1400
|
+
const command = Object.hasOwn(level.commands, name) ? level.commands[name] : undefined;
|
|
1401
|
+
if (command === undefined)
|
|
1402
|
+
break;
|
|
1403
|
+
path.push(word);
|
|
1404
|
+
if (!("commands" in command))
|
|
1405
|
+
break;
|
|
1406
|
+
level = scopeOf(command.commands, command.extraCommands, command.aliases);
|
|
1407
|
+
}
|
|
1408
|
+
return path.length === 0 ? undefined : path.join(" ");
|
|
1329
1409
|
}
|
|
1330
1410
|
// ../kit/src/git.ts
|
|
1331
|
-
import { basename, dirname } from "path";
|
|
1332
|
-
import
|
|
1411
|
+
import { basename, dirname as dirname2 } from "path";
|
|
1412
|
+
import process12 from "process";
|
|
1333
1413
|
var ORIGIN_PREFIX = /^origin\//;
|
|
1334
1414
|
var GIT_NETWORK_MS = 60000;
|
|
1335
1415
|
async function git(args, timeoutMs) {
|
|
@@ -1359,7 +1439,7 @@ async function defaultBranch() {
|
|
|
1359
1439
|
async function leaveWorktree() {
|
|
1360
1440
|
const common = await git(["rev-parse", "--path-format=absolute", "--git-common-dir"]);
|
|
1361
1441
|
if (basename(common) === ".git")
|
|
1362
|
-
|
|
1442
|
+
process12.chdir(dirname2(common));
|
|
1363
1443
|
}
|
|
1364
1444
|
// ../kit/src/limit.ts
|
|
1365
1445
|
function limitOptions(fallback) {
|
|
@@ -1382,24 +1462,22 @@ function capped(rows, limit) {
|
|
|
1382
1462
|
const more = rows.length - limit;
|
|
1383
1463
|
return more > 0 ? { shown: rows.slice(0, limit), footer: moreFooter(more) } : { shown: [...rows], footer: undefined };
|
|
1384
1464
|
}
|
|
1385
|
-
// ../kit/src/logs.ts
|
|
1386
|
-
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
1387
1465
|
// ../kit/src/secrets.ts
|
|
1388
1466
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1389
1467
|
// ../kit/src/sessions.ts
|
|
1390
|
-
import { homedir } from "os";
|
|
1391
|
-
import { join } from "path";
|
|
1392
|
-
import
|
|
1468
|
+
import { homedir as homedir2 } from "os";
|
|
1469
|
+
import { join as join2 } from "path";
|
|
1470
|
+
import process13 from "process";
|
|
1393
1471
|
var {Glob } = globalThis.Bun;
|
|
1394
1472
|
var SESSION_FILES = new Glob("*.json");
|
|
1395
1473
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1396
1474
|
async function sessionDirs() {
|
|
1397
|
-
const home =
|
|
1398
|
-
const dirs = new Set([
|
|
1399
|
-
if (
|
|
1400
|
-
dirs.add(
|
|
1475
|
+
const home = homedir2();
|
|
1476
|
+
const dirs = new Set([join2(home, ".claude", "sessions")]);
|
|
1477
|
+
if (process13.env.CLAUDE_CONFIG_DIR !== undefined)
|
|
1478
|
+
dirs.add(join2(process13.env.CLAUDE_CONFIG_DIR, "sessions"));
|
|
1401
1479
|
try {
|
|
1402
|
-
for await (const dir of ACCOUNT_DIRS.scan({ cwd:
|
|
1480
|
+
for await (const dir of ACCOUNT_DIRS.scan({ cwd: join2(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
|
|
1403
1481
|
dirs.add(dir);
|
|
1404
1482
|
} catch {}
|
|
1405
1483
|
return [...dirs];
|
|
@@ -1443,7 +1521,7 @@ async function liveSessions() {
|
|
|
1443
1521
|
}
|
|
1444
1522
|
async function currentSession(sessions) {
|
|
1445
1523
|
const byPid = new Map(sessions.map((session) => [session.pid, session]));
|
|
1446
|
-
let pid =
|
|
1524
|
+
let pid = process13.ppid;
|
|
1447
1525
|
for (let depth = 0;depth < 32 && pid > 1; depth++) {
|
|
1448
1526
|
const session = byPid.get(pid);
|
|
1449
1527
|
if (session !== undefined)
|
|
@@ -1456,7 +1534,7 @@ async function currentSession(sessions) {
|
|
|
1456
1534
|
return;
|
|
1457
1535
|
}
|
|
1458
1536
|
// package.json
|
|
1459
|
-
var version = "0.
|
|
1537
|
+
var version = "0.13.0";
|
|
1460
1538
|
|
|
1461
1539
|
// src/args.ts
|
|
1462
1540
|
var repoOption = {
|
|
@@ -2084,7 +2162,7 @@ async function drop(args) {
|
|
|
2084
2162
|
}
|
|
2085
2163
|
|
|
2086
2164
|
// src/commands/ci.ts
|
|
2087
|
-
import
|
|
2165
|
+
import process15 from "process";
|
|
2088
2166
|
|
|
2089
2167
|
// src/git.ts
|
|
2090
2168
|
async function tagsAt(commit) {
|
|
@@ -2259,7 +2337,7 @@ ${excerpt(await jobLog(job.id, repo))}`);
|
|
|
2259
2337
|
}
|
|
2260
2338
|
|
|
2261
2339
|
// src/commands/ci.ts
|
|
2262
|
-
var
|
|
2340
|
+
var usage2 = `ft ci [ref]
|
|
2263
2341
|
|
|
2264
2342
|
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.
|
|
2265
2343
|
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.
|
|
@@ -2291,7 +2369,7 @@ function settled(latest) {
|
|
|
2291
2369
|
return latest !== undefined && latest.every((run) => FINISHED.has(run.status)) && judge(latest, false, false).kind === "runs" ? latest : undefined;
|
|
2292
2370
|
}
|
|
2293
2371
|
async function ci2(args) {
|
|
2294
|
-
const parsed = parse(args,
|
|
2372
|
+
const parsed = parse(args, usage2, options);
|
|
2295
2373
|
const { values, positionals } = parsed;
|
|
2296
2374
|
const branch = values.branch ?? await defaultBranch();
|
|
2297
2375
|
const giveUp = duration(values.timeout, "timeout", 30 * 60000, "m");
|
|
@@ -2326,7 +2404,7 @@ async function ci2(args) {
|
|
|
2326
2404
|
}
|
|
2327
2405
|
return;
|
|
2328
2406
|
}
|
|
2329
|
-
const { dim } = paint(
|
|
2407
|
+
const { dim } = paint(process15.stderr);
|
|
2330
2408
|
const runs = await waitForCi({
|
|
2331
2409
|
tool: "ft ci",
|
|
2332
2410
|
short,
|
|
@@ -2349,7 +2427,7 @@ async function ci2(args) {
|
|
|
2349
2427
|
},
|
|
2350
2428
|
lines: (spinner, found, started) => [
|
|
2351
2429
|
`${spinner} CI on ${short} ${dim(formatElapsed(Date.now() - started))}`,
|
|
2352
|
-
...(found ?? []).map((run) => ` ${badge(run.status,
|
|
2430
|
+
...(found ?? []).map((run) => ` ${badge(run.status, process15.stderr)} ${run.workflow_id} ${dim(`run ${run.id}`)}`)
|
|
2353
2431
|
]
|
|
2354
2432
|
});
|
|
2355
2433
|
const status = overall(runs);
|
|
@@ -2368,7 +2446,7 @@ run ${run.id} failed${run.commit_sha === sha ? "" : `, testing every commit from
|
|
|
2368
2446
|
}
|
|
2369
2447
|
|
|
2370
2448
|
// src/commands/digest.ts
|
|
2371
|
-
import
|
|
2449
|
+
import process16 from "process";
|
|
2372
2450
|
var RUNS_SCANNED = 50;
|
|
2373
2451
|
var TITLE_WIDTH2 = 70;
|
|
2374
2452
|
var SHOWN = 8;
|
|
@@ -2418,7 +2496,7 @@ async function quietly(read) {
|
|
|
2418
2496
|
}
|
|
2419
2497
|
}
|
|
2420
2498
|
async function staleTodos() {
|
|
2421
|
-
const bin = Bun.which("todo-scan", { PATH:
|
|
2499
|
+
const bin = Bun.which("todo-scan", { PATH: process16.env.PATH ?? "" });
|
|
2422
2500
|
if (bin === null)
|
|
2423
2501
|
return [];
|
|
2424
2502
|
let found;
|
|
@@ -2463,7 +2541,7 @@ ${lines.join(`
|
|
|
2463
2541
|
|
|
2464
2542
|
`);
|
|
2465
2543
|
}
|
|
2466
|
-
var
|
|
2544
|
+
var usage3 = `ft digest
|
|
2467
2545
|
|
|
2468
2546
|
Summarises the repository for a session starting cold: the issues this session holds with their boxes left, the claims no live session here answers to, red or running CI on the default branch, unpushed commits, dirty files and TODO comments naming a closed issue.
|
|
2469
2547
|
A section with nothing in it is left out, and the stale TODO comments need todo-scan on the PATH.
|
|
@@ -2474,7 +2552,7 @@ var options2 = {
|
|
|
2474
2552
|
...repoOption
|
|
2475
2553
|
};
|
|
2476
2554
|
async function digest(args) {
|
|
2477
|
-
const parsed = parse(args,
|
|
2555
|
+
const parsed = parse(args, usage3, options2);
|
|
2478
2556
|
const { values } = parsed;
|
|
2479
2557
|
const [issues, sessions, branch, runs] = await Promise.all([openIssues(undefined, values.repo), liveSessions(), defaultBranch(), recentRuns(RUNS_SCANNED, values.repo)]);
|
|
2480
2558
|
const comments = await commentsOfAll(issues, values.repo);
|
|
@@ -2490,54 +2568,226 @@ async function digest(args) {
|
|
|
2490
2568
|
return 0;
|
|
2491
2569
|
}
|
|
2492
2570
|
|
|
2493
|
-
// src/commands/
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
const
|
|
2499
|
-
if (
|
|
2500
|
-
fail(`
|
|
2501
|
-
}
|
|
2502
|
-
var stateOptions = {
|
|
2503
|
-
message: { type: "string", short: "m", description: "a comment posted first, saying why" },
|
|
2504
|
-
...repoOption
|
|
2505
|
-
};
|
|
2506
|
-
async function setState(args, usage, wanted) {
|
|
2507
|
-
const parsed = parse(args, usage, stateOptions);
|
|
2508
|
-
const { values, positionals } = parsed;
|
|
2509
|
-
for (const number of issueNumbers(positionals, usage)) {
|
|
2510
|
-
if ((await getIssue(number, values.repo)).state === wanted) {
|
|
2511
|
-
console.log(`#${number} is already ${wanted}`);
|
|
2512
|
-
continue;
|
|
2513
|
-
}
|
|
2514
|
-
if (values.message !== undefined && values.message.trim() !== "")
|
|
2515
|
-
await comment(number, values.message.trim(), values.repo);
|
|
2516
|
-
if (wanted === "closed")
|
|
2517
|
-
await close(number, values.repo);
|
|
2518
|
-
else
|
|
2519
|
-
await reopen(number, values.repo);
|
|
2520
|
-
console.log(`${wanted === "closed" ? "closed" : "reopened"} #${number}`);
|
|
2521
|
-
}
|
|
2522
|
-
return 0;
|
|
2523
|
-
}
|
|
2524
|
-
var closeUsage = `ft close <n>... [-m <reason>]
|
|
2525
|
-
|
|
2526
|
-
Closes issues without a fix, a duplicate or one dropped, posting the -m reason first. \`ft fixed\` closes one a commit fixed.
|
|
2571
|
+
// src/commands/issue-target.ts
|
|
2572
|
+
var ISSUE_REFERENCE = /^#?\d+$/;
|
|
2573
|
+
async function chooseTarget(positionals, held, usage) {
|
|
2574
|
+
if (positionals[0] !== undefined && ISSUE_REFERENCE.test(positionals[0]))
|
|
2575
|
+
return { number: issueNumber(positionals[0], usage), rest: positionals.slice(1), defaulted: false };
|
|
2576
|
+
const [only, ...others] = await held();
|
|
2577
|
+
if (only === undefined || others.length > 0)
|
|
2578
|
+
fail(`an issue number is needed, this session holds ${only === undefined ? "none" : "several"}
|
|
2527
2579
|
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
return setState(args, closeUsage, "closed");
|
|
2580
|
+
${usage}`);
|
|
2581
|
+
return { number: only, rest: positionals, defaulted: true };
|
|
2531
2582
|
}
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
async function reopenIssues(args) {
|
|
2538
|
-
return setState(args, reopenUsage, "open");
|
|
2583
|
+
async function targetIssue(positionals, repo, usage) {
|
|
2584
|
+
const { number, rest, defaulted } = await chooseTarget(positionals, async () => heldIssues(repo), usage);
|
|
2585
|
+
if (defaulted)
|
|
2586
|
+
warn(`using #${number}, the issue this session holds`);
|
|
2587
|
+
return { number, rest };
|
|
2539
2588
|
}
|
|
2540
|
-
var
|
|
2589
|
+
var noteOptions = {
|
|
2590
|
+
message: { type: "string", short: "m", description: "comment this text on the issue" },
|
|
2591
|
+
file: { type: "string", short: "F", description: "comment the text of this file, - for stdin" }
|
|
2592
|
+
};
|
|
2593
|
+
async function noteText(values) {
|
|
2594
|
+
if (values.message !== undefined && values.file !== undefined)
|
|
2595
|
+
fail("give the comment once, as text or with -F");
|
|
2596
|
+
const text = values.file === undefined ? values.message : await readInput(values.file);
|
|
2597
|
+
return text?.trim() === "" ? undefined : text?.trim();
|
|
2598
|
+
}
|
|
2599
|
+
var NOT_FOUND = /not exist|not found|couldn't be found/i;
|
|
2600
|
+
async function isClosed(number, repo) {
|
|
2601
|
+
try {
|
|
2602
|
+
return (await getIssue(number, repo)).state === "closed";
|
|
2603
|
+
} catch (error) {
|
|
2604
|
+
if (error instanceof Error && NOT_FOUND.test(error.message))
|
|
2605
|
+
return false;
|
|
2606
|
+
throw error;
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
async function closedReferences(body, repo) {
|
|
2610
|
+
const listed = [...new Set(referencedBoxes(body).filter(({ box }) => !box.done).map(({ issue }) => issue))];
|
|
2611
|
+
const states = await Promise.all(listed.map(async (issue) => isClosed(issue, repo)));
|
|
2612
|
+
return new Set(listed.filter((_, at) => states[at] === true));
|
|
2613
|
+
}
|
|
2614
|
+
|
|
2615
|
+
// src/commands/issue-progress.ts
|
|
2616
|
+
var tickUsage = `ft tick [<n>] <box>...
|
|
2617
|
+
|
|
2618
|
+
Ticks checklist boxes of issue <n>, each given by its number from \`ft issue\` or by text matching exactly one box, then posts the -m or -F comment.
|
|
2619
|
+
With --closed, ticks instead every box opening with \`#<issue>\` whose issue is closed, as a release plan lists them.
|
|
2620
|
+
|
|
2621
|
+
Without <n> (a first argument that is not a number) it takes the one open issue this session holds (\`ft take\`), and exits 2 when it holds none or several, saying which issue it used. A first argument that is a number is always the issue, so boxes named by number need it.
|
|
2622
|
+
|
|
2623
|
+
Exits 0 when it ticked the boxes, 1 when Forgejo refuses, 2 on a usage error or a box matching none or several.`;
|
|
2624
|
+
var tickOptions = {
|
|
2625
|
+
undo: { type: "boolean", short: "u", description: "untick them instead" },
|
|
2626
|
+
closed: { type: "boolean", description: "tick the boxes listing a closed issue, no box to name" },
|
|
2627
|
+
...noteOptions,
|
|
2628
|
+
...repoOption
|
|
2629
|
+
};
|
|
2630
|
+
function tickedOrFail(number, run) {
|
|
2631
|
+
try {
|
|
2632
|
+
return run();
|
|
2633
|
+
} catch (error) {
|
|
2634
|
+
fail(`#${number}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
async function tick(args) {
|
|
2638
|
+
const parsed = parse(args, tickUsage, tickOptions);
|
|
2639
|
+
const { values, positionals } = parsed;
|
|
2640
|
+
const { number, rest: picks } = await targetIssue(positionals, values.repo, tickUsage);
|
|
2641
|
+
if (values.closed === true && (picks.length > 0 || values.undo === true))
|
|
2642
|
+
fail(`--closed takes no boxes and no --undo
|
|
2643
|
+
|
|
2644
|
+
${tickUsage}`);
|
|
2645
|
+
if (picks.length === 0 && values.closed !== true)
|
|
2646
|
+
fail(`name the boxes to tick
|
|
2647
|
+
|
|
2648
|
+
${tickUsage}`);
|
|
2649
|
+
const note = await noteText(values);
|
|
2650
|
+
const found = await getIssue(number, values.repo);
|
|
2651
|
+
const done = values.undo !== true;
|
|
2652
|
+
const closed = values.closed === true ? await closedReferences(found.body, values.repo) : undefined;
|
|
2653
|
+
const apply = (body) => closed === undefined ? setBoxes(body, picks, done) : tickReferences(body, (issue) => closed.has(issue));
|
|
2654
|
+
let result = tickedOrFail(number, () => apply(found.body));
|
|
2655
|
+
if (result.changed.length > 0) {
|
|
2656
|
+
await editBody(number, (body) => {
|
|
2657
|
+
result = tickedOrFail(number, () => apply(body));
|
|
2658
|
+
return result.body;
|
|
2659
|
+
}, values.repo);
|
|
2660
|
+
}
|
|
2661
|
+
for (const box of result.changed)
|
|
2662
|
+
console.log(`${done ? "ticked" : "unticked"} ${box.number}: ${box.text}`);
|
|
2663
|
+
const left = boxes(result.body).filter((box) => !box.done).length;
|
|
2664
|
+
console.log(`#${number}: ${result.changed.length === 0 ? "nothing to change, " : ""}${left} box${left === 1 ? "" : "es"} left`);
|
|
2665
|
+
if (note !== undefined) {
|
|
2666
|
+
await comment(number, note, values.repo);
|
|
2667
|
+
console.log(`commented on #${number}`);
|
|
2668
|
+
}
|
|
2669
|
+
return 0;
|
|
2670
|
+
}
|
|
2671
|
+
var fixedUsage = `ft fixed [<n>] [commit]...
|
|
2672
|
+
|
|
2673
|
+
Comments "Fixed in <sha>: <message>" on issue <n> and closes it, naming each commit given as "Fixed in <a>, <b> and <c>".
|
|
2674
|
+
Without a commit it takes those on origin's default branch whose message names #<n>, and says which, or HEAD when none does.
|
|
2675
|
+
Without <n> it takes the one open issue this session holds (\`ft take\`). The message defaults to the subject of the first commit. Every open issue listing \`- [ ] #<n>\` in its checklist gets that line ticked. An issue with boxes left is refused, as a partly done issue stays open, unless --tick ticks them first.
|
|
2676
|
+
|
|
2677
|
+
Exits 0 when it closed the issue, 1 when the issue is already closed, has boxes left or Forgejo refuses, 2 on a usage error.`;
|
|
2678
|
+
var fixedOptions = {
|
|
2679
|
+
message: { type: "string", short: "m", description: 'the line after "Fixed in <sha>:"' },
|
|
2680
|
+
tick: { type: "boolean", description: "tick the boxes left before closing" },
|
|
2681
|
+
force: { type: "boolean", description: "close even with boxes left" },
|
|
2682
|
+
...repoOption
|
|
2683
|
+
};
|
|
2684
|
+
function joinShas(shas) {
|
|
2685
|
+
const last = shas.at(-1) ?? "";
|
|
2686
|
+
return shas.length < 2 ? last : `${shas.slice(0, -1).join(", ")} and ${last}`;
|
|
2687
|
+
}
|
|
2688
|
+
async function fixingCommits(number, given) {
|
|
2689
|
+
if (given.length > 0) {
|
|
2690
|
+
const named = [];
|
|
2691
|
+
for (const ref of given) {
|
|
2692
|
+
const sha = await resolveCommit(ref);
|
|
2693
|
+
named.push({ sha, subject: await git(["log", "-1", "--format=%s", sha]) });
|
|
2694
|
+
}
|
|
2695
|
+
return named;
|
|
2696
|
+
}
|
|
2697
|
+
const ref = `origin/${await defaultBranch()}`;
|
|
2698
|
+
const found = await commitsNaming(number, ref);
|
|
2699
|
+
if (found.length > 0) {
|
|
2700
|
+
console.log(`commits on ${ref} naming #${number}:
|
|
2701
|
+
${found.map((each) => ` ${each.sha.slice(0, 7)} ${each.subject}`).join(`
|
|
2702
|
+
`)}`);
|
|
2703
|
+
return found;
|
|
2704
|
+
}
|
|
2705
|
+
const sha = await resolveCommit("HEAD");
|
|
2706
|
+
console.log(`no commit on ${ref} names #${number}, using HEAD`);
|
|
2707
|
+
return [{ sha, subject: await git(["log", "-1", "--format=%s", sha]) }];
|
|
2708
|
+
}
|
|
2709
|
+
async function tickListings(closed, repo) {
|
|
2710
|
+
for (const listing of await openIssues(undefined, repo)) {
|
|
2711
|
+
if (!referencedBoxes(listing.body).some(({ box, issue }) => issue === closed && !box.done))
|
|
2712
|
+
continue;
|
|
2713
|
+
if (await editBody(listing.number, (body) => tickReferences(body, (issue) => issue === closed).body, repo))
|
|
2714
|
+
console.log(`ticked #${closed} in #${listing.number}`);
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
async function fixed(args) {
|
|
2718
|
+
const parsed = parse(args, fixedUsage, fixedOptions);
|
|
2719
|
+
const { values, positionals } = parsed;
|
|
2720
|
+
const { number, rest } = await targetIssue(positionals, values.repo, fixedUsage);
|
|
2721
|
+
const commits = await fixingCommits(number, rest);
|
|
2722
|
+
const found = await getIssue(number, values.repo);
|
|
2723
|
+
if (found.state === "closed")
|
|
2724
|
+
fail(`#${number} is already closed`, 1, runHint(`ft reopen ${number}`, "reopen it"));
|
|
2725
|
+
const left = boxes(found.body).filter((box) => !box.done);
|
|
2726
|
+
if (left.length > 0 && values.tick === true) {
|
|
2727
|
+
await editBody(number, (body) => setBoxes(body, boxes(body).filter((box) => !box.done).map((box) => String(box.number)), true).body, values.repo);
|
|
2728
|
+
console.log(`ticked ${left.length} box${left.length === 1 ? "" : "es"} of #${number}`);
|
|
2729
|
+
} else if (left.length > 0 && values.force !== true) {
|
|
2730
|
+
fail(`#${number} has ${left.length} boxes left:
|
|
2731
|
+
${left.map((box) => `${String(box.number).padStart(3)} [ ] ${box.text}`).join(`
|
|
2732
|
+
`)}`, 1, `${runHint(`ft fixed ${number} --tick`, "tick them and close")}, or ${runHint(`ft fixed ${number} --force`, "close with them left")}`);
|
|
2733
|
+
}
|
|
2734
|
+
const shas = joinShas(commits.map((each) => each.sha.slice(0, 7)));
|
|
2735
|
+
const line = `Fixed in ${shas}: ${values.message ?? commits[0]?.subject ?? ""}`;
|
|
2736
|
+
if ((await commentsOf(number, values.repo)).at(-1)?.body.trim() !== line.trim())
|
|
2737
|
+
await comment(number, line, values.repo);
|
|
2738
|
+
await close(number, values.repo);
|
|
2739
|
+
console.log(`closed #${number}: fixed in ${shas}`);
|
|
2740
|
+
await tickListings(number, values.repo);
|
|
2741
|
+
return 0;
|
|
2742
|
+
}
|
|
2743
|
+
// src/commands/triage.ts
|
|
2744
|
+
async function checkLabels(names, repo) {
|
|
2745
|
+
if (names.length === 0)
|
|
2746
|
+
return;
|
|
2747
|
+
const known = await repoLabels(repo);
|
|
2748
|
+
const missing = names.filter((name) => !known.includes(name));
|
|
2749
|
+
if (missing.length > 0)
|
|
2750
|
+
fail(`no label ${missing.join(", ")} in this repository, ${known.length === 0 ? "which has none" : `it has: ${known.join(", ")}`}`);
|
|
2751
|
+
}
|
|
2752
|
+
var stateOptions = {
|
|
2753
|
+
message: { type: "string", short: "m", description: "a comment posted first, saying why" },
|
|
2754
|
+
...repoOption
|
|
2755
|
+
};
|
|
2756
|
+
async function setState(args, usage, wanted) {
|
|
2757
|
+
const parsed = parse(args, usage, stateOptions);
|
|
2758
|
+
const { values, positionals } = parsed;
|
|
2759
|
+
for (const number of issueNumbers(positionals, usage)) {
|
|
2760
|
+
if ((await getIssue(number, values.repo)).state === wanted) {
|
|
2761
|
+
console.log(`#${number} is already ${wanted}`);
|
|
2762
|
+
continue;
|
|
2763
|
+
}
|
|
2764
|
+
if (values.message !== undefined && values.message.trim() !== "")
|
|
2765
|
+
await comment(number, values.message.trim(), values.repo);
|
|
2766
|
+
if (wanted === "closed")
|
|
2767
|
+
await close(number, values.repo);
|
|
2768
|
+
else
|
|
2769
|
+
await reopen(number, values.repo);
|
|
2770
|
+
console.log(`${wanted === "closed" ? "closed" : "reopened"} #${number}`);
|
|
2771
|
+
}
|
|
2772
|
+
return 0;
|
|
2773
|
+
}
|
|
2774
|
+
var closeUsage = `ft close <n>... [-m <reason>]
|
|
2775
|
+
|
|
2776
|
+
Closes issues without a fix, a duplicate or one dropped, posting the -m reason first. \`ft fixed\` closes one a commit fixed.
|
|
2777
|
+
|
|
2778
|
+
Exits 0 when every issue is closed, 1 when Forgejo refuses, 2 on a usage error.`;
|
|
2779
|
+
async function closeIssues(args) {
|
|
2780
|
+
return setState(args, closeUsage, "closed");
|
|
2781
|
+
}
|
|
2782
|
+
var reopenUsage = `ft reopen <n>... [-m <reason>]
|
|
2783
|
+
|
|
2784
|
+
Reopens closed issues, posting the -m reason first.
|
|
2785
|
+
|
|
2786
|
+
Exits 0 when every issue is open, 1 when Forgejo refuses, 2 on a usage error.`;
|
|
2787
|
+
async function reopenIssues(args) {
|
|
2788
|
+
return setState(args, reopenUsage, "open");
|
|
2789
|
+
}
|
|
2790
|
+
var LABEL_FLAGS = new Set(["-h", "--help"]);
|
|
2541
2791
|
var REPO_FLAGS = new Set(["-r", "--repo"]);
|
|
2542
2792
|
function labelChanges(args) {
|
|
2543
2793
|
const rest = [];
|
|
@@ -2582,129 +2832,7 @@ ${labelUsage}`);
|
|
|
2582
2832
|
return 0;
|
|
2583
2833
|
}
|
|
2584
2834
|
|
|
2585
|
-
// src/commands/issue.ts
|
|
2586
|
-
var issueUsage = `ft issue [<n>...]
|
|
2587
|
-
|
|
2588
|
-
Prints each issue: its title, state, boxes left and claim, then its description with each checklist box numbered as \`ft tick\` takes it.
|
|
2589
|
-
With --body, prints only the raw description, to edit and give back to \`ft edit -F\`.
|
|
2590
|
-
With no number, prints the open issues this session holds (\`ft take\`), and exits 2 when it holds none.
|
|
2591
|
-
|
|
2592
|
-
Exits 0 when it printed them, 1 when an issue cannot be read, 2 on a usage error.`;
|
|
2593
|
-
var issueOptions = {
|
|
2594
|
-
todo: { type: "boolean", short: "t", description: "only the header and the boxes left to tick" },
|
|
2595
|
-
comments: { type: "boolean", short: "c", description: "add the comments, each with its author and age" },
|
|
2596
|
-
body: { type: "boolean", short: "b", description: "only the raw description, without numbered boxes" },
|
|
2597
|
-
json: jsonOption("number, title, state, url, labels, claim, boxes, body and comments, an array for several issues"),
|
|
2598
|
-
...repoOption
|
|
2599
|
-
};
|
|
2600
|
-
function renderIssue(found, comments, view, now = Date.now()) {
|
|
2601
|
-
const claim = latestClaim(comments, view.author);
|
|
2602
|
-
const list = boxes(found.body);
|
|
2603
|
-
const left = list.filter((box) => !box.done);
|
|
2604
|
-
const facts = [found.state];
|
|
2605
|
-
if (list.length > 0)
|
|
2606
|
-
facts.push(`${left.length} of ${list.length} boxes left`);
|
|
2607
|
-
if (claim !== undefined)
|
|
2608
|
-
facts.push(`taken by ${claim.holder} ${formatAge(claim.at, now)}`);
|
|
2609
|
-
const header = `#${found.number} ${found.title} (${facts.join(", ")})`;
|
|
2610
|
-
if (view.todo)
|
|
2611
|
-
return [header, ...left.map((box) => `${String(box.number).padStart(3)} [ ] ${box.text}`)].join(`
|
|
2612
|
-
`);
|
|
2613
|
-
const parts = [`${header}
|
|
2614
|
-
${found.html_url}`];
|
|
2615
|
-
const body = numberedBody(found.body);
|
|
2616
|
-
if (body !== "")
|
|
2617
|
-
parts.push(body);
|
|
2618
|
-
if (view.comments) {
|
|
2619
|
-
for (const each of comments)
|
|
2620
|
-
parts.push(`--- ${each.user.login}, ${formatAge(each.created_at, now)}
|
|
2621
|
-
${each.body.replaceAll(`\r
|
|
2622
|
-
`, `
|
|
2623
|
-
`).trim()}`);
|
|
2624
|
-
}
|
|
2625
|
-
return parts.join(`
|
|
2626
|
-
|
|
2627
|
-
`);
|
|
2628
|
-
}
|
|
2629
|
-
function issueJson(found, comments, author) {
|
|
2630
|
-
return {
|
|
2631
|
-
number: found.number,
|
|
2632
|
-
title: found.title,
|
|
2633
|
-
state: found.state,
|
|
2634
|
-
url: found.html_url,
|
|
2635
|
-
labels: found.labels.map((label) => label.name),
|
|
2636
|
-
claim: latestClaim(comments, author) ?? null,
|
|
2637
|
-
boxes: boxes(found.body).map(({ number, done, text }) => ({ number, done, text })),
|
|
2638
|
-
body: found.body,
|
|
2639
|
-
comments: comments.map((each) => ({ author: each.user.login, at: each.created_at, body: each.body }))
|
|
2640
|
-
};
|
|
2641
|
-
}
|
|
2642
|
-
async function issue(args) {
|
|
2643
|
-
const parsed = parse(args, issueUsage, issueOptions);
|
|
2644
|
-
const { values, positionals } = parsed;
|
|
2645
|
-
const held = positionals.length === 0 ? await heldIssues(values.repo) : [];
|
|
2646
|
-
const numbers = held.length === 0 ? issueNumbers(positionals, issueUsage) : held;
|
|
2647
|
-
if (values.body === true) {
|
|
2648
|
-
const bodies = await Promise.all(numbers.map(async (number) => (await getIssue(number, values.repo)).body.replaceAll(`\r
|
|
2649
|
-
`, `
|
|
2650
|
-
`)));
|
|
2651
|
-
console.log(bodies.join(`
|
|
2652
|
-
|
|
2653
|
-
`));
|
|
2654
|
-
return 0;
|
|
2655
|
-
}
|
|
2656
|
-
const read = await Promise.all(numbers.map(async (number) => Promise.all([getIssue(number, values.repo), commentsOf(number, values.repo)])));
|
|
2657
|
-
const author = await sessionAuthor();
|
|
2658
|
-
if (values.json === true) {
|
|
2659
|
-
const json = read.map(([found, comments]) => issueJson(found, comments, author));
|
|
2660
|
-
printJson(json.length === 1 ? json[0] : json);
|
|
2661
|
-
return 0;
|
|
2662
|
-
}
|
|
2663
|
-
const view = { todo: values.todo === true, comments: values.comments === true, author };
|
|
2664
|
-
console.log(read.map(([found, comments]) => renderIssue(found, comments, view)).join(view.todo ? `
|
|
2665
|
-
|
|
2666
|
-
` : `
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
`));
|
|
2670
|
-
return 0;
|
|
2671
|
-
}
|
|
2672
|
-
var ISSUE_REFERENCE = /^#?\d+$/;
|
|
2673
|
-
async function targetIssue(positionals, repo, usage) {
|
|
2674
|
-
if (positionals[0] !== undefined && ISSUE_REFERENCE.test(positionals[0]))
|
|
2675
|
-
return { number: issueNumber(positionals[0], usage), rest: positionals.slice(1) };
|
|
2676
|
-
const [only, ...others] = await heldIssues(repo);
|
|
2677
|
-
if (only === undefined || others.length > 0)
|
|
2678
|
-
fail(`${only === undefined ? "an issue number is needed, this session holds none" : "an issue number is needed, this session holds several"}
|
|
2679
|
-
|
|
2680
|
-
${usage}`);
|
|
2681
|
-
return { number: only, rest: positionals };
|
|
2682
|
-
}
|
|
2683
|
-
var noteOptions = {
|
|
2684
|
-
message: { type: "string", short: "m", description: "comment this text on the issue" },
|
|
2685
|
-
file: { type: "string", short: "F", description: "comment the text of this file, - for stdin" }
|
|
2686
|
-
};
|
|
2687
|
-
async function noteText(values) {
|
|
2688
|
-
if (values.message !== undefined && values.file !== undefined)
|
|
2689
|
-
fail("give the comment once, as text or with -F");
|
|
2690
|
-
const text = values.file === undefined ? values.message : await readInput(values.file);
|
|
2691
|
-
return text?.trim() === "" ? undefined : text?.trim();
|
|
2692
|
-
}
|
|
2693
|
-
var NOT_FOUND = /not exist|not found|couldn't be found/i;
|
|
2694
|
-
async function isClosed(number, repo) {
|
|
2695
|
-
try {
|
|
2696
|
-
return (await getIssue(number, repo)).state === "closed";
|
|
2697
|
-
} catch (error) {
|
|
2698
|
-
if (error instanceof Error && NOT_FOUND.test(error.message))
|
|
2699
|
-
return false;
|
|
2700
|
-
throw error;
|
|
2701
|
-
}
|
|
2702
|
-
}
|
|
2703
|
-
async function closedReferences(body, repo) {
|
|
2704
|
-
const listed = [...new Set(referencedBoxes(body).filter(({ box }) => !box.done).map(({ issue }) => issue))];
|
|
2705
|
-
const states = await Promise.all(listed.map(async (issue) => isClosed(issue, repo)));
|
|
2706
|
-
return new Set(listed.filter((_, at) => states[at] === true));
|
|
2707
|
-
}
|
|
2835
|
+
// src/commands/issue-write.ts
|
|
2708
2836
|
var newUsage = `ft new -t <title> [-F <file>] [-L a,b] [-m <milestone>]
|
|
2709
2837
|
|
|
2710
2838
|
Creates an issue and prints its number and url. The description is read from -F <file>, or from stdin with -F -, and is empty without it. A label or milestone the repository lacks is refused before anything is created.
|
|
@@ -2788,65 +2916,10 @@ ${text}` : body;
|
|
|
2788
2916
|
console.log(`edited #${number}`);
|
|
2789
2917
|
return 0;
|
|
2790
2918
|
}
|
|
2791
|
-
var tickUsage = `ft tick [<n>] <box>...
|
|
2792
|
-
|
|
2793
|
-
Ticks checklist boxes of issue <n>, each given by its number from \`ft issue\` or by text matching exactly one box, then posts the -m or -F comment.
|
|
2794
|
-
With --closed, ticks instead every box opening with \`#<issue>\` whose issue is closed, as a release plan lists them.
|
|
2795
|
-
|
|
2796
|
-
Without <n> (a first argument that is not a number) it takes the one open issue this session holds (\`ft take\`), and exits 2 when it holds none or several.
|
|
2797
|
-
|
|
2798
|
-
Exits 0 when it ticked the boxes, 1 when Forgejo refuses, 2 on a usage error or a box matching none or several.`;
|
|
2799
|
-
var tickOptions = {
|
|
2800
|
-
undo: { type: "boolean", short: "u", description: "untick them instead" },
|
|
2801
|
-
closed: { type: "boolean", description: "tick the boxes listing a closed issue, no box to name" },
|
|
2802
|
-
...noteOptions,
|
|
2803
|
-
...repoOption
|
|
2804
|
-
};
|
|
2805
|
-
function tickedOrFail(number, run) {
|
|
2806
|
-
try {
|
|
2807
|
-
return run();
|
|
2808
|
-
} catch (error) {
|
|
2809
|
-
fail(`#${number}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2810
|
-
}
|
|
2811
|
-
}
|
|
2812
|
-
async function tick(args) {
|
|
2813
|
-
const parsed = parse(args, tickUsage, tickOptions);
|
|
2814
|
-
const { values, positionals } = parsed;
|
|
2815
|
-
const { number, rest: picks } = await targetIssue(positionals, values.repo, tickUsage);
|
|
2816
|
-
if (values.closed === true && (picks.length > 0 || values.undo === true))
|
|
2817
|
-
fail(`--closed takes no boxes and no --undo
|
|
2818
|
-
|
|
2819
|
-
${tickUsage}`);
|
|
2820
|
-
if (picks.length === 0 && values.closed !== true)
|
|
2821
|
-
fail(`name the boxes to tick
|
|
2822
|
-
|
|
2823
|
-
${tickUsage}`);
|
|
2824
|
-
const note = await noteText(values);
|
|
2825
|
-
const found = await getIssue(number, values.repo);
|
|
2826
|
-
const done = values.undo !== true;
|
|
2827
|
-
const closed = values.closed === true ? await closedReferences(found.body, values.repo) : undefined;
|
|
2828
|
-
const apply = (body) => closed === undefined ? setBoxes(body, picks, done) : tickReferences(body, (issue) => closed.has(issue));
|
|
2829
|
-
let result = tickedOrFail(number, () => apply(found.body));
|
|
2830
|
-
if (result.changed.length > 0) {
|
|
2831
|
-
await editBody(number, (body) => {
|
|
2832
|
-
result = tickedOrFail(number, () => apply(body));
|
|
2833
|
-
return result.body;
|
|
2834
|
-
}, values.repo);
|
|
2835
|
-
}
|
|
2836
|
-
for (const box of result.changed)
|
|
2837
|
-
console.log(`${done ? "ticked" : "unticked"} ${box.number}: ${box.text}`);
|
|
2838
|
-
const left = boxes(result.body).filter((box) => !box.done).length;
|
|
2839
|
-
console.log(`#${number}: ${result.changed.length === 0 ? "nothing to change, " : ""}${left} box${left === 1 ? "" : "es"} left`);
|
|
2840
|
-
if (note !== undefined) {
|
|
2841
|
-
await comment(number, note, values.repo);
|
|
2842
|
-
console.log(`commented on #${number}`);
|
|
2843
|
-
}
|
|
2844
|
-
return 0;
|
|
2845
|
-
}
|
|
2846
2919
|
var commentUsage = `ft comment [<n>] [text]
|
|
2847
2920
|
|
|
2848
2921
|
Posts a comment on issue <n>: the text given, -F <file>, or stdin when neither is, so a heredoc needs no escaping.
|
|
2849
|
-
Without <n> (a first argument that is not a number) it takes the one open issue this session holds (\`ft take\`), and exits 2 when it holds none or several.
|
|
2922
|
+
Without <n> (a first argument that is not a number) it takes the one open issue this session holds (\`ft take\`), and exits 2 when it holds none or several, saying which issue it used. A first argument that is a number is always the issue, so boxes named by number need it.
|
|
2850
2923
|
|
|
2851
2924
|
Exits 0 when it posted the comment, 1 when Forgejo refuses, 2 on a usage error.`;
|
|
2852
2925
|
var commentOptions = {
|
|
@@ -2867,81 +2940,97 @@ ${commentUsage}`);
|
|
|
2867
2940
|
console.log(`commented on #${number}`);
|
|
2868
2941
|
return 0;
|
|
2869
2942
|
}
|
|
2870
|
-
var fixedUsage = `ft fixed [<n>] [commit]...
|
|
2871
2943
|
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
Without <n> it takes the one open issue this session holds (\`ft take\`). The message defaults to the subject of the first commit. Every open issue listing \`- [ ] #<n>\` in its checklist gets that line ticked. An issue with boxes left is refused, as a partly done issue stays open, unless --tick ticks them first.
|
|
2944
|
+
// src/commands/issue.ts
|
|
2945
|
+
var issueUsage = `ft issue [<n>...]
|
|
2875
2946
|
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2947
|
+
Prints each issue: its title, state, boxes left and claim, then its description with each checklist box numbered as \`ft tick\` takes it.
|
|
2948
|
+
With --body, prints only the raw description, to edit and give back to \`ft edit -F\`.
|
|
2949
|
+
With no number, prints the open issues this session holds (\`ft take\`), and exits 2 when it holds none.
|
|
2950
|
+
|
|
2951
|
+
Exits 0 when it printed them, 1 when an issue cannot be read, 2 on a usage error.`;
|
|
2952
|
+
var issueOptions = {
|
|
2953
|
+
todo: { type: "boolean", short: "t", description: "only the header and the boxes left to tick" },
|
|
2954
|
+
comments: { type: "boolean", short: "c", description: "add the comments, each with its author and age" },
|
|
2955
|
+
body: { type: "boolean", short: "b", description: "only the raw description, without numbered boxes" },
|
|
2956
|
+
json: jsonOption("number, title, state, url, labels, claim, boxes, body and comments, an array for several issues"),
|
|
2881
2957
|
...repoOption
|
|
2882
2958
|
};
|
|
2883
|
-
function
|
|
2884
|
-
const
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
if (
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
return
|
|
2895
|
-
|
|
2896
|
-
const
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2959
|
+
function renderIssue(found, comments, view, now = Date.now()) {
|
|
2960
|
+
const claim = latestClaim(comments, view.author);
|
|
2961
|
+
const list = boxes(found.body);
|
|
2962
|
+
const left = list.filter((box) => !box.done);
|
|
2963
|
+
const facts = [found.state];
|
|
2964
|
+
if (list.length > 0)
|
|
2965
|
+
facts.push(`${left.length} of ${list.length} boxes left`);
|
|
2966
|
+
if (claim !== undefined)
|
|
2967
|
+
facts.push(`taken by ${claim.holder} ${formatAge(claim.at, now)}`);
|
|
2968
|
+
const header = `#${found.number} ${found.title} (${facts.join(", ")})`;
|
|
2969
|
+
if (view.todo)
|
|
2970
|
+
return [header, ...left.map((box) => `${String(box.number).padStart(3)} [ ] ${box.text}`)].join(`
|
|
2971
|
+
`);
|
|
2972
|
+
const parts = [`${header}
|
|
2973
|
+
${found.html_url}`];
|
|
2974
|
+
const body = numberedBody(found.body);
|
|
2975
|
+
if (body !== "")
|
|
2976
|
+
parts.push(body);
|
|
2977
|
+
if (view.comments) {
|
|
2978
|
+
for (const each of comments)
|
|
2979
|
+
parts.push(`--- ${each.user.login}, ${formatAge(each.created_at, now)}
|
|
2980
|
+
${each.body.replaceAll(`\r
|
|
2981
|
+
`, `
|
|
2982
|
+
`).trim()}`);
|
|
2903
2983
|
}
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2984
|
+
return parts.join(`
|
|
2985
|
+
|
|
2986
|
+
`);
|
|
2907
2987
|
}
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2988
|
+
function issueJson(found, comments, author) {
|
|
2989
|
+
return {
|
|
2990
|
+
number: found.number,
|
|
2991
|
+
title: found.title,
|
|
2992
|
+
state: found.state,
|
|
2993
|
+
url: found.html_url,
|
|
2994
|
+
labels: found.labels.map((label) => label.name),
|
|
2995
|
+
claim: latestClaim(comments, author) ?? null,
|
|
2996
|
+
boxes: boxes(found.body).map(({ number, done, text }) => ({ number, done, text })),
|
|
2997
|
+
body: found.body,
|
|
2998
|
+
comments: comments.map((each) => ({ author: each.user.login, at: each.created_at, body: each.body }))
|
|
2999
|
+
};
|
|
3000
|
+
}
|
|
3001
|
+
async function issue(args) {
|
|
3002
|
+
const parsed = parse(args, issueUsage, issueOptions);
|
|
3003
|
+
const { values, positionals } = parsed;
|
|
3004
|
+
const held = positionals.length === 0 ? await heldIssues(values.repo) : [];
|
|
3005
|
+
const numbers = held.length === 0 ? issueNumbers(positionals, issueUsage) : held;
|
|
3006
|
+
if (values.body === true) {
|
|
3007
|
+
const bodies = await Promise.all(numbers.map(async (number) => (await getIssue(number, values.repo)).body.replaceAll(`\r
|
|
3008
|
+
`, `
|
|
3009
|
+
`)));
|
|
3010
|
+
console.log(bodies.join(`
|
|
3011
|
+
|
|
3012
|
+
`));
|
|
3013
|
+
return 0;
|
|
2914
3014
|
}
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
const found = await getIssue(number, values.repo);
|
|
2922
|
-
if (found.state === "closed")
|
|
2923
|
-
fail(`#${number} is already closed`, 1, runHint(`ft reopen ${number}`, "reopen it"));
|
|
2924
|
-
const left = boxes(found.body).filter((box) => !box.done);
|
|
2925
|
-
if (left.length > 0 && values.tick === true) {
|
|
2926
|
-
await editBody(number, (body) => setBoxes(body, boxes(body).filter((box) => !box.done).map((box) => String(box.number)), true).body, values.repo);
|
|
2927
|
-
console.log(`ticked ${left.length} box${left.length === 1 ? "" : "es"} of #${number}`);
|
|
2928
|
-
} else if (left.length > 0 && values.force !== true) {
|
|
2929
|
-
fail(`#${number} has ${left.length} boxes left:
|
|
2930
|
-
${left.map((box) => `${String(box.number).padStart(3)} [ ] ${box.text}`).join(`
|
|
2931
|
-
`)}`, 1, `${runHint(`ft fixed ${number} --tick`, "tick them and close")}, or ${runHint(`ft fixed ${number} --force`, "close with them left")}`);
|
|
3015
|
+
const read = await Promise.all(numbers.map(async (number) => Promise.all([getIssue(number, values.repo), commentsOf(number, values.repo)])));
|
|
3016
|
+
const author = await sessionAuthor();
|
|
3017
|
+
if (values.json === true) {
|
|
3018
|
+
const json = read.map(([found, comments]) => issueJson(found, comments, author));
|
|
3019
|
+
printJson(json.length === 1 ? json[0] : json);
|
|
3020
|
+
return 0;
|
|
2932
3021
|
}
|
|
2933
|
-
const
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
3022
|
+
const view = { todo: values.todo === true, comments: values.comments === true, author };
|
|
3023
|
+
console.log(read.map(([found, comments]) => renderIssue(found, comments, view)).join(view.todo ? `
|
|
3024
|
+
|
|
3025
|
+
` : `
|
|
3026
|
+
|
|
3027
|
+
|
|
3028
|
+
`));
|
|
2940
3029
|
return 0;
|
|
2941
3030
|
}
|
|
2942
3031
|
|
|
2943
3032
|
// src/commands/logs.ts
|
|
2944
|
-
var
|
|
3033
|
+
var usage4 = `ft logs <run id>
|
|
2945
3034
|
|
|
2946
3035
|
Prints what the failed jobs of a run say went wrong: each failed bun test's output and the end of each failed step.
|
|
2947
3036
|
With no failed job it prints every job's last lines; --full prints whole logs.
|
|
@@ -2959,7 +3048,7 @@ function pickJobs(jobs, wanted) {
|
|
|
2959
3048
|
return failed.length > 0 ? failed : jobs;
|
|
2960
3049
|
}
|
|
2961
3050
|
async function logs2(args) {
|
|
2962
|
-
const parsed = parse(args,
|
|
3051
|
+
const parsed = parse(args, usage4, options3);
|
|
2963
3052
|
const { values, positionals } = parsed;
|
|
2964
3053
|
if (positionals[0] === undefined)
|
|
2965
3054
|
fail("a run id is needed", 2, runHint("ft runs", "list them"));
|
|
@@ -3239,12 +3328,11 @@ function report(plan, added, skipped) {
|
|
|
3239
3328
|
}
|
|
3240
3329
|
|
|
3241
3330
|
// src/commands/release.ts
|
|
3242
|
-
import { basename as
|
|
3243
|
-
|
|
3244
|
-
var {$ } = globalThis.Bun;
|
|
3331
|
+
import { basename as basename3, join as join5 } from "path";
|
|
3332
|
+
var {$: $2 } = globalThis.Bun;
|
|
3245
3333
|
|
|
3246
3334
|
// src/commands/watch.ts
|
|
3247
|
-
var
|
|
3335
|
+
var usage5 = `ft watch [--after <id>]
|
|
3248
3336
|
|
|
3249
3337
|
Waits for runs to finish: those newer than run <id>, or else the ones in progress now.
|
|
3250
3338
|
Exits 0 when every one passed or was skipped, 1 when one failed or was cancelled, 2 on a timeout or a stalled queue.`;
|
|
@@ -3344,7 +3432,7 @@ function elapsed(run, seen) {
|
|
|
3344
3432
|
return seconds > 0 ? ` for ${formatSeconds(seconds)}` : "";
|
|
3345
3433
|
}
|
|
3346
3434
|
async function watch(args) {
|
|
3347
|
-
const parsed = parse(args,
|
|
3435
|
+
const parsed = parse(args, usage5, options5);
|
|
3348
3436
|
const { values } = parsed;
|
|
3349
3437
|
const timeout = duration(values.timeout, "timeout", 15 * 60000, "m");
|
|
3350
3438
|
if (values.after !== undefined) {
|
|
@@ -3359,34 +3447,49 @@ async function watch(args) {
|
|
|
3359
3447
|
return watchRuns((runs) => runs.filter((run) => active.has(run.id)), timeout, values.repo);
|
|
3360
3448
|
}
|
|
3361
3449
|
|
|
3362
|
-
// src/commands/release.ts
|
|
3363
|
-
var
|
|
3364
|
-
|
|
3450
|
+
// src/commands/release-checks.ts
|
|
3451
|
+
var limits = { pushMs: 5 * 60000 };
|
|
3452
|
+
var NO_RUN2 = 3 * 60000;
|
|
3453
|
+
var RUNS_LOOKED_AT = 20;
|
|
3454
|
+
async function alreadyPassed(sha) {
|
|
3455
|
+
try {
|
|
3456
|
+
const own = newestPerWorkflow((await recentRuns(RUNS_LOOKED_AT)).filter((run) => run.commit_sha === sha));
|
|
3457
|
+
return own.length > 0 && own.every((run) => FINISHED.has(run.status)) && ["success", "skipped"].includes(overall(own));
|
|
3458
|
+
} catch {
|
|
3459
|
+
return false;
|
|
3460
|
+
}
|
|
3461
|
+
}
|
|
3462
|
+
async function testsPass(sha, branch, timeout) {
|
|
3463
|
+
if (!await gitOk(["merge-base", "--is-ancestor", sha, `origin/${branch}`])) {
|
|
3464
|
+
const held = holdSignals();
|
|
3465
|
+
let push;
|
|
3466
|
+
try {
|
|
3467
|
+
push = await runTool("git push", ["git", "push", "origin", `${sha}:refs/heads/${branch}`], { timeoutMs: limits.pushMs, onStart: (child) => held.forward(child) });
|
|
3468
|
+
} finally {
|
|
3469
|
+
held.release();
|
|
3470
|
+
}
|
|
3471
|
+
if (held.signal !== undefined)
|
|
3472
|
+
fail(`interrupted by ${held.signal} while pushing ${sha.slice(0, 7)}, so nothing was bumped`, exitCodeOf(null, held.signal));
|
|
3473
|
+
if (push.code !== 0)
|
|
3474
|
+
fail(`origin refused the push of ${sha.slice(0, 7)}, so nothing was bumped:
|
|
3475
|
+
${push.stderr.trim()}`, 1);
|
|
3476
|
+
console.log(`pushed ${branch} at ${sha.slice(0, 7)}, waiting for its runs before the bump`);
|
|
3477
|
+
} else if (await alreadyPassed(sha)) {
|
|
3478
|
+
return true;
|
|
3479
|
+
} else {
|
|
3480
|
+
console.log(`${branch} at ${sha.slice(0, 7)} is on origin, waiting for its runs before the bump`);
|
|
3481
|
+
}
|
|
3482
|
+
return await watchRuns((runs) => newestPerWorkflow(runs.filter((run) => run.commit_sha === sha)), timeout, undefined, NO_RUN2) === 0;
|
|
3483
|
+
}
|
|
3365
3484
|
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
--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.
|
|
3372
|
-
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.`;
|
|
3373
|
-
var options6 = {
|
|
3374
|
-
tagged: { type: "boolean", description: "push the version commit and tag already at HEAD instead of bumping" },
|
|
3375
|
-
package: { type: "string", short: "p", description: "workspace folder to release, a path or a name under packages/" },
|
|
3376
|
-
"no-registry": { type: "boolean", description: "do not wait for the registry to serve the new version" },
|
|
3377
|
-
"dry-run": { type: "boolean", description: "print what the release would do, changing nothing" },
|
|
3378
|
-
timeout: { type: "string", short: "t", description: "how long to wait for the runs (15m), a bare number in minutes" }
|
|
3379
|
-
};
|
|
3380
|
-
var LEVELS = new Set(["patch", "minor", "major", "prepatch", "preminor", "premajor", "prerelease"]);
|
|
3485
|
+
// src/commands/release-plan.ts
|
|
3486
|
+
import { basename as basename2, join as join3, relative } from "path";
|
|
3487
|
+
import process17 from "process";
|
|
3488
|
+
|
|
3489
|
+
// src/commands/release-version.ts
|
|
3381
3490
|
var VERSION = /^\d+\.\d+\.\d+(?:-[\w.]+)?$/;
|
|
3382
3491
|
var PARTS = /^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/;
|
|
3383
3492
|
var LAST_NUMBER = /\d+$/;
|
|
3384
|
-
var REGISTRY_TRIES = 12;
|
|
3385
|
-
var REGISTRY_POLL = 5000;
|
|
3386
|
-
var limits = { pushMs: 5 * 60000 };
|
|
3387
|
-
var REGISTRY_INFO_MS = 30000;
|
|
3388
|
-
var NO_RUN2 = 3 * 60000;
|
|
3389
|
-
var RUNS_LOOKED_AT = 20;
|
|
3390
3493
|
function taggedVersion(tag, prefix) {
|
|
3391
3494
|
const version = tag.slice(prefix.length);
|
|
3392
3495
|
return tag.startsWith(prefix) && VERSION.test(version) ? version : undefined;
|
|
@@ -3417,75 +3520,13 @@ function nextVersion(current, level) {
|
|
|
3417
3520
|
}
|
|
3418
3521
|
}
|
|
3419
3522
|
}
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
if (await Bun.file(join2(dir, "package.json")).exists())
|
|
3423
|
-
return dir;
|
|
3424
|
-
}
|
|
3425
|
-
fail(`no package.json in ${value} nor in packages/${value}`);
|
|
3426
|
-
}
|
|
3427
|
-
async function commitPackageBump(dir, prefix) {
|
|
3428
|
-
const { version } = await Bun.file(join2(dir, "package.json")).json();
|
|
3429
|
-
const root = await git(["rev-parse", "--show-toplevel"]);
|
|
3430
|
-
const tag = `${prefix}${version}`;
|
|
3431
|
-
const lock = await $`bun install --lockfile-only`.cwd(root).quiet().nothrow();
|
|
3432
|
-
if (lock.exitCode !== 0)
|
|
3433
|
-
fail(`bun install --lockfile-only after the bump: ${lock.stderr.toString().trim()}`);
|
|
3434
|
-
await git(["add", join2(dir, "package.json"), join2(root, "bun.lock")]);
|
|
3435
|
-
await git(["commit", "-q", "-m", tag]);
|
|
3436
|
-
await git(["tag", "-a", tag, "-m", tag]);
|
|
3437
|
-
}
|
|
3438
|
-
async function waitForRegistry(name, version) {
|
|
3439
|
-
for (let attempt = 0;attempt < REGISTRY_TRIES; attempt++) {
|
|
3440
|
-
let served;
|
|
3441
|
-
try {
|
|
3442
|
-
served = (await runTool("bun info", ["bun", "info", name, "version", "--no-cache"], { timeoutMs: REGISTRY_INFO_MS })).stdout.trim().split(`
|
|
3443
|
-
`).at(-1);
|
|
3444
|
-
} catch (error) {
|
|
3445
|
-
if (isPermanentFailure(error))
|
|
3446
|
-
throw error;
|
|
3447
|
-
}
|
|
3448
|
-
if (served === version)
|
|
3449
|
-
return true;
|
|
3450
|
-
await Bun.sleep(REGISTRY_POLL);
|
|
3451
|
-
}
|
|
3452
|
-
return false;
|
|
3453
|
-
}
|
|
3454
|
-
async function alreadyPassed(sha) {
|
|
3455
|
-
try {
|
|
3456
|
-
const own = newestPerWorkflow((await recentRuns(RUNS_LOOKED_AT)).filter((run) => run.commit_sha === sha));
|
|
3457
|
-
return own.length > 0 && own.every((run) => FINISHED.has(run.status)) && ["success", "skipped"].includes(overall(own));
|
|
3458
|
-
} catch {
|
|
3459
|
-
return false;
|
|
3460
|
-
}
|
|
3461
|
-
}
|
|
3462
|
-
async function testsPass(sha, branch, timeout) {
|
|
3463
|
-
if (!await gitOk(["merge-base", "--is-ancestor", sha, `origin/${branch}`])) {
|
|
3464
|
-
const held = holdSignals();
|
|
3465
|
-
let push;
|
|
3466
|
-
try {
|
|
3467
|
-
push = await runTool("git push", ["git", "push", "origin", `${sha}:refs/heads/${branch}`], { timeoutMs: limits.pushMs, onStart: (child) => held.forward(child) });
|
|
3468
|
-
} finally {
|
|
3469
|
-
held.release();
|
|
3470
|
-
}
|
|
3471
|
-
if (held.signal !== undefined)
|
|
3472
|
-
fail(`interrupted by ${held.signal} while pushing ${sha.slice(0, 7)}, so nothing was bumped`, exitCodeOf(null, held.signal));
|
|
3473
|
-
if (push.code !== 0)
|
|
3474
|
-
fail(`origin refused the push of ${sha.slice(0, 7)}, so nothing was bumped:
|
|
3475
|
-
${push.stderr.trim()}`, 1);
|
|
3476
|
-
console.log(`pushed ${branch} at ${sha.slice(0, 7)}, waiting for its runs before the bump`);
|
|
3477
|
-
} else if (await alreadyPassed(sha)) {
|
|
3478
|
-
return true;
|
|
3479
|
-
} else {
|
|
3480
|
-
console.log(`${branch} at ${sha.slice(0, 7)} is on origin, waiting for its runs before the bump`);
|
|
3481
|
-
}
|
|
3482
|
-
return await watchRuns((runs) => newestPerWorkflow(runs.filter((run) => run.commit_sha === sha)), timeout, undefined, NO_RUN2) === 0;
|
|
3483
|
-
}
|
|
3523
|
+
|
|
3524
|
+
// src/commands/release-plan.ts
|
|
3484
3525
|
async function printPlan({ level, dir, prefix, branch, base, timeout, registry }) {
|
|
3485
|
-
const file = Bun.file(
|
|
3526
|
+
const file = Bun.file(join3(dir ?? ".", "package.json"));
|
|
3486
3527
|
const pkg = await file.exists() ? await file.json() : undefined;
|
|
3487
|
-
const name = pkg?.name ?? basename2(dir ??
|
|
3488
|
-
const where = dir === undefined ? "" : ` in ${relative(
|
|
3528
|
+
const name = pkg?.name ?? basename2(dir ?? process17.cwd());
|
|
3529
|
+
const where = dir === undefined ? "" : ` in ${relative(process17.cwd(), dir) || "."}`;
|
|
3489
3530
|
const sha = base.slice(0, 7);
|
|
3490
3531
|
let version;
|
|
3491
3532
|
let bump;
|
|
@@ -3498,7 +3539,7 @@ async function printPlan({ level, dir, prefix, branch, base, timeout, registry }
|
|
|
3498
3539
|
console.log(`would release ${name} ${version}, tagged ${tag}`);
|
|
3499
3540
|
} else {
|
|
3500
3541
|
if (pkg?.version === undefined)
|
|
3501
|
-
fail(`no version in ${
|
|
3542
|
+
fail(`no version in ${join3(dir ?? ".", "package.json")}`);
|
|
3502
3543
|
version = nextVersion(pkg.version, level);
|
|
3503
3544
|
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}`;
|
|
3504
3545
|
console.log(`would release ${name} ${pkg.version} -> ${version}, tagged ${prefix}${version}`);
|
|
@@ -3516,6 +3557,47 @@ async function printPlan({ level, dir, prefix, branch, base, timeout, registry }
|
|
|
3516
3557
|
console.log("dry run: nothing was pushed, committed or tagged");
|
|
3517
3558
|
return 0;
|
|
3518
3559
|
}
|
|
3560
|
+
|
|
3561
|
+
// src/commands/release-steps.ts
|
|
3562
|
+
import { join as join4, resolve } from "path";
|
|
3563
|
+
var {$ } = globalThis.Bun;
|
|
3564
|
+
var REGISTRY_TRIES = 12;
|
|
3565
|
+
var REGISTRY_POLL = 5000;
|
|
3566
|
+
var REGISTRY_INFO_MS = 30000;
|
|
3567
|
+
async function packageDir(value) {
|
|
3568
|
+
for (const dir of [resolve(value), join4(await git(["rev-parse", "--show-toplevel"]), "packages", value)]) {
|
|
3569
|
+
if (await Bun.file(join4(dir, "package.json")).exists())
|
|
3570
|
+
return dir;
|
|
3571
|
+
}
|
|
3572
|
+
fail(`no package.json in ${value} nor in packages/${value}`);
|
|
3573
|
+
}
|
|
3574
|
+
async function commitPackageBump(dir, prefix) {
|
|
3575
|
+
const { version } = await Bun.file(join4(dir, "package.json")).json();
|
|
3576
|
+
const root = await git(["rev-parse", "--show-toplevel"]);
|
|
3577
|
+
const tag = `${prefix}${version}`;
|
|
3578
|
+
const lock = await $`bun install --lockfile-only`.cwd(root).quiet().nothrow();
|
|
3579
|
+
if (lock.exitCode !== 0)
|
|
3580
|
+
fail(`bun install --lockfile-only after the bump: ${lock.stderr.toString().trim()}`);
|
|
3581
|
+
await git(["add", join4(dir, "package.json"), join4(root, "bun.lock")]);
|
|
3582
|
+
await git(["commit", "-q", "-m", tag]);
|
|
3583
|
+
await git(["tag", "-a", tag, "-m", tag]);
|
|
3584
|
+
}
|
|
3585
|
+
async function waitForRegistry(name, version) {
|
|
3586
|
+
for (let attempt = 0;attempt < REGISTRY_TRIES; attempt++) {
|
|
3587
|
+
let served;
|
|
3588
|
+
try {
|
|
3589
|
+
served = (await runTool("bun info", ["bun", "info", name, "version", "--no-cache"], { timeoutMs: REGISTRY_INFO_MS })).stdout.trim().split(`
|
|
3590
|
+
`).at(-1);
|
|
3591
|
+
} catch (error) {
|
|
3592
|
+
if (isPermanentFailure(error))
|
|
3593
|
+
throw error;
|
|
3594
|
+
}
|
|
3595
|
+
if (served === version)
|
|
3596
|
+
return true;
|
|
3597
|
+
await Bun.sleep(REGISTRY_POLL);
|
|
3598
|
+
}
|
|
3599
|
+
return false;
|
|
3600
|
+
}
|
|
3519
3601
|
async function rollBack(preBump, tagsBefore) {
|
|
3520
3602
|
try {
|
|
3521
3603
|
for (const name of await tagsAt("HEAD")) {
|
|
@@ -3527,20 +3609,58 @@ async function rollBack(preBump, tagsBefore) {
|
|
|
3527
3609
|
warn(`could not undo the bump, back to ${preBump.slice(0, 7)} by hand`, error instanceof Error ? error.message : String(error));
|
|
3528
3610
|
}
|
|
3529
3611
|
}
|
|
3612
|
+
async function settleMilestone(version, tag) {
|
|
3613
|
+
try {
|
|
3614
|
+
const names = new Set([version, `v${version}`, tag]);
|
|
3615
|
+
const found = (await listMilestones("open")).find((each) => names.has(each.title));
|
|
3616
|
+
if (found === undefined)
|
|
3617
|
+
return;
|
|
3618
|
+
const [done, left] = await Promise.all([closedIssues(found.id), openIssues(undefined, undefined, found.id)]);
|
|
3619
|
+
console.log(`milestone ${found.title}: ${done.length} closed issue${done.length === 1 ? "" : "s"}${done.length === 0 ? "" : `
|
|
3620
|
+
${done.map((issue) => ` #${issue.number} ${issue.title}`).join(`
|
|
3621
|
+
`)}`}`);
|
|
3622
|
+
if (left.length > 0)
|
|
3623
|
+
warn(`${left.length} issue${left.length === 1 ? " is" : "s are"} still open in it`, left.map((issue) => `#${issue.number}`).join(" "));
|
|
3624
|
+
await closeMilestone(found.id);
|
|
3625
|
+
console.log(`closed milestone ${found.title}`);
|
|
3626
|
+
} catch (error) {
|
|
3627
|
+
warn(`released, but the milestone ${version} could not be settled`, error instanceof Error ? error.message : String(error));
|
|
3628
|
+
}
|
|
3629
|
+
}
|
|
3630
|
+
|
|
3631
|
+
// src/commands/release.ts
|
|
3632
|
+
var LEVELS = new Set(["patch", "minor", "major", "prepatch", "preminor", "premajor", "prerelease"]);
|
|
3633
|
+
var usage6 = `ft release <patch|minor|major|x.y.z>
|
|
3634
|
+
ft release --tagged
|
|
3635
|
+
|
|
3636
|
+
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
|
+
--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
|
+
--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).
|
|
3639
|
+
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
|
+
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
|
+
--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.
|
|
3642
|
+
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
|
+
var options6 = {
|
|
3644
|
+
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/" },
|
|
3646
|
+
"no-registry": { type: "boolean", description: "do not wait for the registry to serve the new version" },
|
|
3647
|
+
"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" }
|
|
3649
|
+
};
|
|
3530
3650
|
async function release(args) {
|
|
3531
|
-
const parsed = parse(args,
|
|
3651
|
+
const parsed = parse(args, usage6, options6);
|
|
3532
3652
|
const { values, positionals } = parsed;
|
|
3533
3653
|
const level = positionals[0];
|
|
3534
3654
|
const tagged = values.tagged === true;
|
|
3535
3655
|
if (tagged === (level !== undefined))
|
|
3536
3656
|
fail(`give a level or --tagged
|
|
3537
3657
|
|
|
3538
|
-
${
|
|
3658
|
+
${usage6}`);
|
|
3539
3659
|
if (level !== undefined && !LEVELS.has(level) && !VERSION.test(level))
|
|
3540
3660
|
fail(`${level} is no level nor x.y.z version`);
|
|
3541
3661
|
const timeout = duration(values.timeout, "timeout", 15 * 60000, "m");
|
|
3542
3662
|
const dir = values.package === undefined ? undefined : await packageDir(values.package);
|
|
3543
|
-
const prefix = dir === undefined ? "v" : `${
|
|
3663
|
+
const prefix = dir === undefined ? "v" : `${basename3(dir)}-v`;
|
|
3544
3664
|
const branch = await defaultBranch();
|
|
3545
3665
|
const current = await git(["branch", "--show-current"]);
|
|
3546
3666
|
if (current !== branch)
|
|
@@ -3548,7 +3668,7 @@ ${usage5}`);
|
|
|
3548
3668
|
if (await git(["status", "--porcelain"]) !== "")
|
|
3549
3669
|
fail("the tree has uncommitted changes", 2, runHint("gst", "see them, then commit them with gc"));
|
|
3550
3670
|
await fetchBranch(branch);
|
|
3551
|
-
if ((await
|
|
3671
|
+
if ((await $2`git merge-base --is-ancestor ${`origin/${branch}`} HEAD`.quiet().nothrow()).exitCode !== 0)
|
|
3552
3672
|
fail(`origin/${branch} has commits HEAD lacks`, 2, runHint(`git pull --rebase origin ${branch}`));
|
|
3553
3673
|
const base = await git(["rev-parse", tagged ? "HEAD~1" : "HEAD"]);
|
|
3554
3674
|
if (values["dry-run"] === true)
|
|
@@ -3566,7 +3686,7 @@ ${usage5}`);
|
|
|
3566
3686
|
let isPushUnknown = false;
|
|
3567
3687
|
try {
|
|
3568
3688
|
if (level !== undefined) {
|
|
3569
|
-
const bump = dir === undefined ? await
|
|
3689
|
+
const bump = dir === undefined ? await $2`bun pm version ${level}`.quiet().nothrow() : await $2`bun pm version ${level} --no-git-tag-version`.cwd(dir).quiet().nothrow();
|
|
3570
3690
|
if (bump.exitCode !== 0)
|
|
3571
3691
|
fail(`bun pm version ${level}: ${bump.stderr.toString().trim() || bump.stdout.toString().trim()}`);
|
|
3572
3692
|
if (dir !== undefined)
|
|
@@ -3604,7 +3724,7 @@ ${push.stderr.trim()}`, signal === undefined ? 1 : exitCodeOf(null, signal));
|
|
|
3604
3724
|
const code = await watchRuns((runs) => runs.filter((run) => run.id > before && run.commit_sha === head), timeout, undefined, NO_RUN2);
|
|
3605
3725
|
if (code !== 0)
|
|
3606
3726
|
return code;
|
|
3607
|
-
const file = Bun.file(
|
|
3727
|
+
const file = Bun.file(join5(dir ?? ".", "package.json"));
|
|
3608
3728
|
const pkg = await file.exists() ? await file.json() : undefined;
|
|
3609
3729
|
const version = tag.slice(prefix.length);
|
|
3610
3730
|
if (values["no-registry"] === true || pkg?.name === undefined || pkg.private === true) {
|
|
@@ -3618,37 +3738,19 @@ ${push.stderr.trim()}`, signal === undefined ? 1 : exitCodeOf(null, signal));
|
|
|
3618
3738
|
await settleMilestone(version, tag);
|
|
3619
3739
|
return 0;
|
|
3620
3740
|
}
|
|
3621
|
-
async function settleMilestone(version, tag) {
|
|
3622
|
-
try {
|
|
3623
|
-
const names = new Set([version, `v${version}`, tag]);
|
|
3624
|
-
const found = (await listMilestones("open")).find((each) => names.has(each.title));
|
|
3625
|
-
if (found === undefined)
|
|
3626
|
-
return;
|
|
3627
|
-
const [done, left] = await Promise.all([closedIssues(found.id), openIssues(undefined, undefined, found.id)]);
|
|
3628
|
-
console.log(`milestone ${found.title}: ${done.length} closed issue${done.length === 1 ? "" : "s"}${done.length === 0 ? "" : `
|
|
3629
|
-
${done.map((issue) => ` #${issue.number} ${issue.title}`).join(`
|
|
3630
|
-
`)}`}`);
|
|
3631
|
-
if (left.length > 0)
|
|
3632
|
-
warn(`${left.length} issue${left.length === 1 ? " is" : "s are"} still open in it`, left.map((issue) => `#${issue.number}`).join(" "));
|
|
3633
|
-
await closeMilestone(found.id);
|
|
3634
|
-
console.log(`closed milestone ${found.title}`);
|
|
3635
|
-
} catch (error) {
|
|
3636
|
-
warn(`released, but the milestone ${version} could not be settled`, error instanceof Error ? error.message : String(error));
|
|
3637
|
-
}
|
|
3638
|
-
}
|
|
3639
3741
|
|
|
3640
3742
|
// src/commands/remote.ts
|
|
3641
3743
|
import { lookup } from "dns/promises";
|
|
3642
|
-
import { homedir as
|
|
3643
|
-
var {$: $
|
|
3744
|
+
import { homedir as homedir4 } from "os";
|
|
3745
|
+
var {$: $3 } = globalThis.Bun;
|
|
3644
3746
|
|
|
3645
3747
|
// src/config.ts
|
|
3646
|
-
import { homedir as
|
|
3647
|
-
import { join as
|
|
3648
|
-
function settingsPath(home =
|
|
3649
|
-
return
|
|
3748
|
+
import { homedir as homedir3 } from "os";
|
|
3749
|
+
import { join as join6 } from "path";
|
|
3750
|
+
function settingsPath(home = homedir3()) {
|
|
3751
|
+
return join6(home, ".config", "ft", "config.json");
|
|
3650
3752
|
}
|
|
3651
|
-
async function loadSettings(home =
|
|
3753
|
+
async function loadSettings(home = homedir3()) {
|
|
3652
3754
|
const path = settingsPath(home);
|
|
3653
3755
|
const file = Bun.file(path);
|
|
3654
3756
|
if (!await file.exists())
|
|
@@ -3705,7 +3807,7 @@ async function reachesHost(hostname, host, hostAddresses, addressesOf) {
|
|
|
3705
3807
|
}
|
|
3706
3808
|
|
|
3707
3809
|
// src/commands/remote.ts
|
|
3708
|
-
var
|
|
3810
|
+
var usage7 = `ft remote [--fix]
|
|
3709
3811
|
|
|
3710
3812
|
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\`.
|
|
3711
3813
|
--fix switches every alias URL to \`git@<host>:<owner>/<repo>.git\` and proves it with \`git ls-remote\`.
|
|
@@ -3718,7 +3820,7 @@ var options7 = {
|
|
|
3718
3820
|
};
|
|
3719
3821
|
var HOSTNAME = /^hostname (.+)$/m;
|
|
3720
3822
|
async function sshHostname(alias) {
|
|
3721
|
-
return HOSTNAME.exec(await $
|
|
3823
|
+
return HOSTNAME.exec(await $3`ssh -G -- ${alias}`.quiet().nothrow().text())?.[1];
|
|
3722
3824
|
}
|
|
3723
3825
|
async function addresses(name) {
|
|
3724
3826
|
try {
|
|
@@ -3738,15 +3840,15 @@ async function restoreOrigin(fetchUrl, pushUrls, changes) {
|
|
|
3738
3840
|
function originHost(url) {
|
|
3739
3841
|
return parseSshRemote(url)?.host ?? (URL.canParse(url) ? new URL(url).hostname : undefined);
|
|
3740
3842
|
}
|
|
3741
|
-
async function remote(args, home =
|
|
3742
|
-
const { values } = parse(args,
|
|
3843
|
+
async function remote(args, home = homedir4()) {
|
|
3844
|
+
const { values } = parse(args, usage7, options7);
|
|
3743
3845
|
const host = values.host ?? (await loadSettings(home)).remoteHost;
|
|
3744
3846
|
if (host === undefined) {
|
|
3745
3847
|
note(`no Forgejo host to check origin against: pass --host, or set "remoteHost" in ${settingsPath(home)}`);
|
|
3746
3848
|
return 0;
|
|
3747
3849
|
}
|
|
3748
3850
|
const fetchUrl = await git(["remote", "get-url", "origin"]);
|
|
3749
|
-
const pushUrls = (await $
|
|
3851
|
+
const pushUrls = (await $3`git config --get-all remote.origin.pushurl`.quiet().nothrow().text()).split(`
|
|
3750
3852
|
`).filter(Boolean);
|
|
3751
3853
|
const hostAddresses = new Set(await addresses(host));
|
|
3752
3854
|
const hostnames = new Map;
|
|
@@ -3795,7 +3897,7 @@ async function remote(args, home = homedir3()) {
|
|
|
3795
3897
|
}
|
|
3796
3898
|
|
|
3797
3899
|
// src/commands/runs.ts
|
|
3798
|
-
var
|
|
3900
|
+
var usage8 = `ft runs [--sha <ref>]
|
|
3799
3901
|
|
|
3800
3902
|
Lists recent runs with what tea's own listing leaves empty: workflow, ref, duration and age, ten by default with the count of the rest (--full for all of them; --json is never cut unless --limit is given).
|
|
3801
3903
|
|
|
@@ -3814,7 +3916,7 @@ async function onCommit(sha, repo) {
|
|
|
3814
3916
|
return { runs: found, total: found.length };
|
|
3815
3917
|
}
|
|
3816
3918
|
async function runs(args) {
|
|
3817
|
-
const parsed = parse(args,
|
|
3919
|
+
const parsed = parse(args, usage8, options8);
|
|
3818
3920
|
const { values } = parsed;
|
|
3819
3921
|
const limit = limitOf(values, DEFAULT_LIMIT);
|
|
3820
3922
|
const { runs: found, total } = values.sha === undefined ? await runsListing(limit, values.repo, values.workflow) : await onCommit(values.sha, values.repo);
|
|
@@ -3840,7 +3942,7 @@ async function runs(args) {
|
|
|
3840
3942
|
}
|
|
3841
3943
|
|
|
3842
3944
|
// src/cli.ts
|
|
3843
|
-
|
|
3945
|
+
process18.exitCode = await runCli({
|
|
3844
3946
|
name: "ft",
|
|
3845
3947
|
version,
|
|
3846
3948
|
about: "Forgejo tools over tea, run from a repository whose origin is on Forgejo",
|