@kaynooo/cli-forgejo 0.17.0 → 0.19.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 +79 -12
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -549,6 +549,11 @@ function badge(word, stream, env = process6.env) {
|
|
|
549
549
|
const { theme } = activeTheme();
|
|
550
550
|
return tinted(paint(stream, env), theme.colors[status], env)(`${theme.glyphs[status]} ${word}`);
|
|
551
551
|
}
|
|
552
|
+
function link(text, url, stream, env = process6.env) {
|
|
553
|
+
if (takesControlCodes(stream, env))
|
|
554
|
+
return `\x1B]8;;${url}\x1B\\${text}\x1B]8;;\x1B\\`;
|
|
555
|
+
return text === url ? text : `${text} (${url})`;
|
|
556
|
+
}
|
|
552
557
|
|
|
553
558
|
// ../kit/src/format.ts
|
|
554
559
|
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
@@ -751,6 +756,9 @@ var DASHES = /^-+/;
|
|
|
751
756
|
function jsonOption(holds) {
|
|
752
757
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
753
758
|
}
|
|
759
|
+
function copyOption(what) {
|
|
760
|
+
return { type: "boolean", description: `also copy ${what} to the clipboard` };
|
|
761
|
+
}
|
|
754
762
|
|
|
755
763
|
class Exit extends Error {
|
|
756
764
|
code;
|
|
@@ -969,9 +977,12 @@ import process12 from "process";
|
|
|
969
977
|
|
|
970
978
|
// ../kit/src/process.ts
|
|
971
979
|
import { constants } from "os";
|
|
980
|
+
import { resolve as resolve3 } from "path";
|
|
972
981
|
import process11 from "process";
|
|
973
982
|
var KILL_GRACE_MS = 2000;
|
|
974
983
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
984
|
+
var SCHEME = /^[a-z][\w+.-]+:/i;
|
|
985
|
+
var OPENERS = { darwin: ["open"], win32: ["cmd", "/c", "start", ""] };
|
|
975
986
|
function exitCodeOf(code, signal) {
|
|
976
987
|
if (code !== null)
|
|
977
988
|
return code;
|
|
@@ -1010,6 +1021,32 @@ function holdSignals(cleanup) {
|
|
|
1010
1021
|
process11.on(signal, onSignal);
|
|
1011
1022
|
return held;
|
|
1012
1023
|
}
|
|
1024
|
+
function openUrl(target, env = process11.env, platform = process11.platform) {
|
|
1025
|
+
const opener = env.BROWSER === undefined || env.BROWSER === "" ? OPENERS[platform] ?? ["xdg-open"] : [env.BROWSER];
|
|
1026
|
+
try {
|
|
1027
|
+
Bun.spawn([...opener, SCHEME.test(target) ? target : resolve3(target)], { env, stdio: ["ignore", "ignore", "ignore"] }).unref();
|
|
1028
|
+
return true;
|
|
1029
|
+
} catch {
|
|
1030
|
+
return false;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
var CLIPBOARDS = [["wl-copy"], ["xclip", "-selection", "clipboard"], ["xsel", "--clipboard", "--input"], ["pbcopy"], ["clip.exe"]];
|
|
1034
|
+
async function copyText(text, which = Bun.which) {
|
|
1035
|
+
for (const [command, ...args] of CLIPBOARDS) {
|
|
1036
|
+
const found = which(command);
|
|
1037
|
+
if (found !== null && await pipeInto([found, ...args], text))
|
|
1038
|
+
return true;
|
|
1039
|
+
}
|
|
1040
|
+
return false;
|
|
1041
|
+
}
|
|
1042
|
+
async function pipeInto(argv, text) {
|
|
1043
|
+
try {
|
|
1044
|
+
const copy = Bun.spawn(argv, { stdin: new Blob([text]), stdout: "ignore", stderr: "ignore" });
|
|
1045
|
+
return await copy.exited === 0;
|
|
1046
|
+
} catch {
|
|
1047
|
+
return false;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1013
1050
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
1014
1051
|
const chunks = [];
|
|
1015
1052
|
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
@@ -1110,25 +1147,28 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
1110
1147
|
} };
|
|
1111
1148
|
const write = stream.write.bind(stream);
|
|
1112
1149
|
let frame = 0;
|
|
1113
|
-
let drawn =
|
|
1150
|
+
let drawn = [];
|
|
1151
|
+
const columns = () => stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns;
|
|
1152
|
+
const rowsDrawn = () => drawn.reduce((sum, width) => sum + Math.max(1, Math.ceil(width / columns())), 0);
|
|
1114
1153
|
const clear = () => {
|
|
1115
|
-
if (drawn > 0)
|
|
1116
|
-
write(`${CLEAR_LINE}${LINE_UP.repeat(
|
|
1117
|
-
drawn =
|
|
1154
|
+
if (drawn.length > 0)
|
|
1155
|
+
write(`${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}`);
|
|
1156
|
+
drawn = [];
|
|
1118
1157
|
};
|
|
1119
1158
|
const draw = () => {
|
|
1120
|
-
const width = (
|
|
1159
|
+
const width = columns() - 1;
|
|
1121
1160
|
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
1122
1161
|
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
1123
1162
|
if (lines.length === 0) {
|
|
1124
1163
|
clear();
|
|
1125
1164
|
return;
|
|
1126
1165
|
}
|
|
1127
|
-
write(`${drawn > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(
|
|
1166
|
+
write(`${drawn.length > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}` : CLEAR_LINE}${lines.join(`
|
|
1128
1167
|
`)}`);
|
|
1129
|
-
drawn = lines.
|
|
1168
|
+
drawn = lines.map((line) => Bun.stringWidth(line));
|
|
1130
1169
|
};
|
|
1131
1170
|
const timer = setInterval(draw, FRAME_MS);
|
|
1171
|
+
stream.on?.("resize", draw);
|
|
1132
1172
|
const restore = interceptOutput(clear);
|
|
1133
1173
|
const release = swallowInput();
|
|
1134
1174
|
const onExit = () => {
|
|
@@ -1138,6 +1178,7 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
1138
1178
|
const signals = holdSignals(stop);
|
|
1139
1179
|
function stop() {
|
|
1140
1180
|
clearInterval(timer);
|
|
1181
|
+
stream.off?.("resize", draw);
|
|
1141
1182
|
clear();
|
|
1142
1183
|
restore();
|
|
1143
1184
|
release();
|
|
@@ -1828,6 +1869,9 @@ async function currentSession(sessions) {
|
|
|
1828
1869
|
var repoOption = {
|
|
1829
1870
|
repo: { type: "string", short: "r", description: "owner/name of the repository, instead of the one origin points at" }
|
|
1830
1871
|
};
|
|
1872
|
+
var openOption = {
|
|
1873
|
+
open: { type: "boolean", short: "o", description: "also open the page in the browser (BROWSER, else the system opener)" }
|
|
1874
|
+
};
|
|
1831
1875
|
var ISSUE_HASH = /^#/;
|
|
1832
1876
|
function issueNumber(value, usage) {
|
|
1833
1877
|
if (value === undefined)
|
|
@@ -2323,6 +2367,10 @@ var STATES = new Set(["available", "taken", "away"]);
|
|
|
2323
2367
|
function dimmed(text) {
|
|
2324
2368
|
return text === "" ? "" : paint(process.stdout).dim(text);
|
|
2325
2369
|
}
|
|
2370
|
+
function issueNumber2(issue) {
|
|
2371
|
+
const number = role("id", process.stdout)(`#${issue.number}`);
|
|
2372
|
+
return takesControlCodes(process.stdout) ? link(number, issue.html_url, process.stdout) : number;
|
|
2373
|
+
}
|
|
2326
2374
|
function boxesLeft(issue) {
|
|
2327
2375
|
const list = boxes(issue.body);
|
|
2328
2376
|
return list.length === 0 ? "" : `${list.filter((box) => !box.done).length}/${list.length} left`;
|
|
@@ -2330,7 +2378,7 @@ function boxesLeft(issue) {
|
|
|
2330
2378
|
function claimRow(issue, row, now) {
|
|
2331
2379
|
const holder = row.state === "taken" && row.session.name !== row.claim.holder ? `${row.claim.holder} via ${row.session.name}` : row.claim.holder;
|
|
2332
2380
|
const status = row.state === "taken" ? ` (${row.session.status})` : "";
|
|
2333
|
-
return [
|
|
2381
|
+
return [issueNumber2(issue), `${holder}${status}`, paint(process.stdout).dim(formatAge(row.claim.at, now)), boxesLeft(issue), truncate(issue.title, TITLE_WIDTH)];
|
|
2334
2382
|
}
|
|
2335
2383
|
function noteLine(comments, now) {
|
|
2336
2384
|
const note = latestNote(comments);
|
|
@@ -2349,7 +2397,7 @@ function renderBoard(rows, now = Date.now(), limit = Number.POSITIVE_INFINITY) {
|
|
|
2349
2397
|
const taken = claimed("taken");
|
|
2350
2398
|
const away = claimed("away");
|
|
2351
2399
|
const sections = [
|
|
2352
|
-
{ heading: "available", count: available.length, ...within(available, limit, ({ issue }) => [
|
|
2400
|
+
{ heading: "available", count: available.length, ...within(available, limit, ({ issue }) => [issueNumber2(issue), truncate(issue.title, TITLE_WIDTH), dimmed(issue.labels.map((label) => label.name).join(", "))]) },
|
|
2353
2401
|
{ heading: "taken", count: taken.length, ...within(taken, limit, ({ issue, row }) => claimRow(issue, row, now)) },
|
|
2354
2402
|
{ heading: "claimed, no live session here", count: away.length, ...within(away, limit, ({ issue, row }) => claimRow(issue, row, now), (line, index) => [line, ...noteLine(away[index]?.comments ?? [], now)]) }
|
|
2355
2403
|
].filter((section) => section.count > 0);
|
|
@@ -3386,7 +3434,7 @@ ${commentUsage}`);
|
|
|
3386
3434
|
// src/commands/issue.ts
|
|
3387
3435
|
var issueUsage = `ft issue [<n>...]
|
|
3388
3436
|
|
|
3389
|
-
Prints each issue: its title, state, boxes left and claim, then its description with each checklist box numbered as \`ft tick\` takes it.
|
|
3437
|
+
Prints each issue: its title, state, boxes left and claim, then its description with each checklist box numbered as \`ft tick\` takes it. --open also opens each in the browser.
|
|
3390
3438
|
With --body, prints only the raw description, to edit and give back to \`ft edit -F\`.
|
|
3391
3439
|
With no number, prints the open issues this session holds (\`ft take\`), and exits 2 when it holds none.
|
|
3392
3440
|
|
|
@@ -3396,6 +3444,8 @@ var issueOptions = {
|
|
|
3396
3444
|
comments: { type: "boolean", short: "c", description: "add the comments, each with its author and age" },
|
|
3397
3445
|
body: { type: "boolean", short: "b", description: "only the raw description, without numbered boxes" },
|
|
3398
3446
|
json: jsonOption("number, title, state, url, labels, claim, boxes, body and comments, an array for several issues"),
|
|
3447
|
+
copy: copyOption("the description --body prints"),
|
|
3448
|
+
...openOption,
|
|
3399
3449
|
...repoOption
|
|
3400
3450
|
};
|
|
3401
3451
|
function renderIssue(found, comments, view, now = Date.now()) {
|
|
@@ -3445,6 +3495,10 @@ async function issue(args) {
|
|
|
3445
3495
|
const { values, positionals } = parsed;
|
|
3446
3496
|
const held = positionals.length === 0 ? await heldIssues(values.repo) : [];
|
|
3447
3497
|
const numbers = held.length === 0 ? issueNumbers(positionals, issueUsage) : held;
|
|
3498
|
+
if (values.body === true && values.open === true)
|
|
3499
|
+
badUsage("--open does not go with --body");
|
|
3500
|
+
if (values.copy === true && values.body !== true)
|
|
3501
|
+
badUsage("--copy goes with --body");
|
|
3448
3502
|
if (values.body === true) {
|
|
3449
3503
|
const bodies = await Promise.all(numbers.map(async (number) => (await getIssue(number, values.repo)).body.replaceAll(`\r
|
|
3450
3504
|
`, `
|
|
@@ -3452,10 +3506,18 @@ async function issue(args) {
|
|
|
3452
3506
|
console.log(bodies.join(`
|
|
3453
3507
|
|
|
3454
3508
|
`));
|
|
3509
|
+
if (values.copy === true && !await copyText(bodies.join(`
|
|
3510
|
+
|
|
3511
|
+
`)))
|
|
3512
|
+
console.error("warning: no clipboard tool found (wl-copy, xclip, xsel, pbcopy)");
|
|
3455
3513
|
return 0;
|
|
3456
3514
|
}
|
|
3457
3515
|
const read = await Promise.all(numbers.map(async (number) => Promise.all([getIssue(number, values.repo), commentsOf(number, values.repo)])));
|
|
3458
3516
|
const author = await sessionAuthor();
|
|
3517
|
+
if (values.open === true) {
|
|
3518
|
+
for (const [found] of read)
|
|
3519
|
+
openUrl(found.html_url);
|
|
3520
|
+
}
|
|
3459
3521
|
if (values.json === true) {
|
|
3460
3522
|
const json = read.map(([found, comments]) => issueJson(found, comments, author));
|
|
3461
3523
|
printJson(json.length === 1 ? json[0] : json);
|
|
@@ -4064,12 +4126,12 @@ async function printPlan({ level, dir, prefix, branch, base, timeout, registry }
|
|
|
4064
4126
|
}
|
|
4065
4127
|
|
|
4066
4128
|
// src/commands/release-steps.ts
|
|
4067
|
-
import { join as join10, relative as relative2, resolve as
|
|
4129
|
+
import { join as join10, relative as relative2, resolve as resolve4 } from "path";
|
|
4068
4130
|
var {$ } = globalThis.Bun;
|
|
4069
4131
|
var registryWait = { tries: 12, poll: 5000 };
|
|
4070
4132
|
var REGISTRY_INFO_MS = 30000;
|
|
4071
4133
|
async function packageDir(value) {
|
|
4072
|
-
for (const dir of [
|
|
4134
|
+
for (const dir of [resolve4(value), join10(await git(["rev-parse", "--show-toplevel"]), "packages", value)]) {
|
|
4073
4135
|
if (await Bun.file(join10(dir, "package.json")).exists())
|
|
4074
4136
|
return dir;
|
|
4075
4137
|
}
|
|
@@ -4444,6 +4506,8 @@ var usage8 = `ft runs [--sha <ref>]
|
|
|
4444
4506
|
|
|
4445
4507
|
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).
|
|
4446
4508
|
|
|
4509
|
+
--open also opens the newest run listed in the browser.
|
|
4510
|
+
|
|
4447
4511
|
Exits 0 when it listed them, 1 when Forgejo or git cannot be read, 2 on a usage error.`;
|
|
4448
4512
|
var DEFAULT_LIMIT = 10;
|
|
4449
4513
|
var options8 = {
|
|
@@ -4451,6 +4515,7 @@ var options8 = {
|
|
|
4451
4515
|
sha: { type: "string", short: "s", description: "only the runs of this commit" },
|
|
4452
4516
|
workflow: { type: "string", short: "w", description: "only this workflow file, e.g. test.yml" },
|
|
4453
4517
|
json: jsonOption(),
|
|
4518
|
+
...openOption,
|
|
4454
4519
|
...repoOption
|
|
4455
4520
|
};
|
|
4456
4521
|
var TITLE_WIDTH4 = 70;
|
|
@@ -4466,6 +4531,8 @@ async function runs(args) {
|
|
|
4466
4531
|
const matching = found.filter((run) => values.workflow === undefined || run.workflow_id === values.workflow);
|
|
4467
4532
|
const list = matching.slice(0, limit);
|
|
4468
4533
|
const more = values.sha === undefined ? total - list.length : matching.length - list.length;
|
|
4534
|
+
if (values.open === true && list[0] !== undefined)
|
|
4535
|
+
openUrl(list[0].html_url);
|
|
4469
4536
|
if (values.json === true) {
|
|
4470
4537
|
printJson(list.map((run) => ({ id: run.id, number: run.index_in_repo, status: run.status, workflow: run.workflow_id, ref: run.prettyref, event: run.event, sha: run.commit_sha, seconds: runSeconds(run), started: run.started, title: run.title, url: run.html_url })));
|
|
4471
4538
|
return 0;
|
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.19.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",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"ft": "$npm_execpath src/cli.ts"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@kaynooo/cli-kit": "0.
|
|
31
|
+
"@kaynooo/cli-kit": "0.24.0"
|
|
32
32
|
}
|
|
33
33
|
}
|