@kaynooo/cli-forgejo 0.18.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 +57 -3
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -756,6 +756,9 @@ var DASHES = /^-+/;
|
|
|
756
756
|
function jsonOption(holds) {
|
|
757
757
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
758
758
|
}
|
|
759
|
+
function copyOption(what) {
|
|
760
|
+
return { type: "boolean", description: `also copy ${what} to the clipboard` };
|
|
761
|
+
}
|
|
759
762
|
|
|
760
763
|
class Exit extends Error {
|
|
761
764
|
code;
|
|
@@ -974,9 +977,12 @@ import process12 from "process";
|
|
|
974
977
|
|
|
975
978
|
// ../kit/src/process.ts
|
|
976
979
|
import { constants } from "os";
|
|
980
|
+
import { resolve as resolve3 } from "path";
|
|
977
981
|
import process11 from "process";
|
|
978
982
|
var KILL_GRACE_MS = 2000;
|
|
979
983
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
984
|
+
var SCHEME = /^[a-z][\w+.-]+:/i;
|
|
985
|
+
var OPENERS = { darwin: ["open"], win32: ["cmd", "/c", "start", ""] };
|
|
980
986
|
function exitCodeOf(code, signal) {
|
|
981
987
|
if (code !== null)
|
|
982
988
|
return code;
|
|
@@ -1015,6 +1021,32 @@ function holdSignals(cleanup) {
|
|
|
1015
1021
|
process11.on(signal, onSignal);
|
|
1016
1022
|
return held;
|
|
1017
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
|
+
}
|
|
1018
1050
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
1019
1051
|
const chunks = [];
|
|
1020
1052
|
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
@@ -1837,6 +1869,9 @@ async function currentSession(sessions) {
|
|
|
1837
1869
|
var repoOption = {
|
|
1838
1870
|
repo: { type: "string", short: "r", description: "owner/name of the repository, instead of the one origin points at" }
|
|
1839
1871
|
};
|
|
1872
|
+
var openOption = {
|
|
1873
|
+
open: { type: "boolean", short: "o", description: "also open the page in the browser (BROWSER, else the system opener)" }
|
|
1874
|
+
};
|
|
1840
1875
|
var ISSUE_HASH = /^#/;
|
|
1841
1876
|
function issueNumber(value, usage) {
|
|
1842
1877
|
if (value === undefined)
|
|
@@ -3399,7 +3434,7 @@ ${commentUsage}`);
|
|
|
3399
3434
|
// src/commands/issue.ts
|
|
3400
3435
|
var issueUsage = `ft issue [<n>...]
|
|
3401
3436
|
|
|
3402
|
-
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.
|
|
3403
3438
|
With --body, prints only the raw description, to edit and give back to \`ft edit -F\`.
|
|
3404
3439
|
With no number, prints the open issues this session holds (\`ft take\`), and exits 2 when it holds none.
|
|
3405
3440
|
|
|
@@ -3409,6 +3444,8 @@ var issueOptions = {
|
|
|
3409
3444
|
comments: { type: "boolean", short: "c", description: "add the comments, each with its author and age" },
|
|
3410
3445
|
body: { type: "boolean", short: "b", description: "only the raw description, without numbered boxes" },
|
|
3411
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,
|
|
3412
3449
|
...repoOption
|
|
3413
3450
|
};
|
|
3414
3451
|
function renderIssue(found, comments, view, now = Date.now()) {
|
|
@@ -3458,6 +3495,10 @@ async function issue(args) {
|
|
|
3458
3495
|
const { values, positionals } = parsed;
|
|
3459
3496
|
const held = positionals.length === 0 ? await heldIssues(values.repo) : [];
|
|
3460
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");
|
|
3461
3502
|
if (values.body === true) {
|
|
3462
3503
|
const bodies = await Promise.all(numbers.map(async (number) => (await getIssue(number, values.repo)).body.replaceAll(`\r
|
|
3463
3504
|
`, `
|
|
@@ -3465,10 +3506,18 @@ async function issue(args) {
|
|
|
3465
3506
|
console.log(bodies.join(`
|
|
3466
3507
|
|
|
3467
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)");
|
|
3468
3513
|
return 0;
|
|
3469
3514
|
}
|
|
3470
3515
|
const read = await Promise.all(numbers.map(async (number) => Promise.all([getIssue(number, values.repo), commentsOf(number, values.repo)])));
|
|
3471
3516
|
const author = await sessionAuthor();
|
|
3517
|
+
if (values.open === true) {
|
|
3518
|
+
for (const [found] of read)
|
|
3519
|
+
openUrl(found.html_url);
|
|
3520
|
+
}
|
|
3472
3521
|
if (values.json === true) {
|
|
3473
3522
|
const json = read.map(([found, comments]) => issueJson(found, comments, author));
|
|
3474
3523
|
printJson(json.length === 1 ? json[0] : json);
|
|
@@ -4077,12 +4126,12 @@ async function printPlan({ level, dir, prefix, branch, base, timeout, registry }
|
|
|
4077
4126
|
}
|
|
4078
4127
|
|
|
4079
4128
|
// src/commands/release-steps.ts
|
|
4080
|
-
import { join as join10, relative as relative2, resolve as
|
|
4129
|
+
import { join as join10, relative as relative2, resolve as resolve4 } from "path";
|
|
4081
4130
|
var {$ } = globalThis.Bun;
|
|
4082
4131
|
var registryWait = { tries: 12, poll: 5000 };
|
|
4083
4132
|
var REGISTRY_INFO_MS = 30000;
|
|
4084
4133
|
async function packageDir(value) {
|
|
4085
|
-
for (const dir of [
|
|
4134
|
+
for (const dir of [resolve4(value), join10(await git(["rev-parse", "--show-toplevel"]), "packages", value)]) {
|
|
4086
4135
|
if (await Bun.file(join10(dir, "package.json")).exists())
|
|
4087
4136
|
return dir;
|
|
4088
4137
|
}
|
|
@@ -4457,6 +4506,8 @@ var usage8 = `ft runs [--sha <ref>]
|
|
|
4457
4506
|
|
|
4458
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).
|
|
4459
4508
|
|
|
4509
|
+
--open also opens the newest run listed in the browser.
|
|
4510
|
+
|
|
4460
4511
|
Exits 0 when it listed them, 1 when Forgejo or git cannot be read, 2 on a usage error.`;
|
|
4461
4512
|
var DEFAULT_LIMIT = 10;
|
|
4462
4513
|
var options8 = {
|
|
@@ -4464,6 +4515,7 @@ var options8 = {
|
|
|
4464
4515
|
sha: { type: "string", short: "s", description: "only the runs of this commit" },
|
|
4465
4516
|
workflow: { type: "string", short: "w", description: "only this workflow file, e.g. test.yml" },
|
|
4466
4517
|
json: jsonOption(),
|
|
4518
|
+
...openOption,
|
|
4467
4519
|
...repoOption
|
|
4468
4520
|
};
|
|
4469
4521
|
var TITLE_WIDTH4 = 70;
|
|
@@ -4479,6 +4531,8 @@ async function runs(args) {
|
|
|
4479
4531
|
const matching = found.filter((run) => values.workflow === undefined || run.workflow_id === values.workflow);
|
|
4480
4532
|
const list = matching.slice(0, limit);
|
|
4481
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);
|
|
4482
4536
|
if (values.json === true) {
|
|
4483
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 })));
|
|
4484
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
|
}
|