@bensandee/forgejo-cli 0.6.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/bin/bst-fj.mjs +12 -3
- package/dist/bin.mjs +222 -49
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# @bensandee/forgejo-cli
|
|
2
2
|
|
|
3
3
|
`bst-fj`: the Forgejo API commands, without the rest of `bst`. Most of these commands used to ship on
|
|
4
|
-
`@bensandee/tooling`'s `bst` bin; `issue:*`, `pr:create`, `pr:update`, `pr:ready
|
|
4
|
+
`@bensandee/tooling`'s `bst` bin; `issue:*`, `pr:create`, `pr:update`, `pr:ready`, `pr:reopen` and
|
|
5
|
+
`pr:retarget` still do, and run the same code.
|
|
5
6
|
|
|
6
7
|
## Installation
|
|
7
8
|
|
|
@@ -56,11 +57,13 @@ command takes `--json`, which prints exactly one JSON document, failures include
|
|
|
56
57
|
| `pr:merge` | Merge an open, non-draft, mergeable PR pinned to the head it read; refuses closed, draft, conflicted, unconfirmed or non-green checks (zero statuses included) unless `--ignore-checks`; `--delete-branch` is opt-in |
|
|
57
58
|
| `pr:ready` | Mark a draft pull request ready, dropping one `WIP:` prefix or taking `--title`, and confirm the forge no longer reports a draft |
|
|
58
59
|
| `pr:close` | Close an open pull request, optionally posting `--comment`/`--comment-file` first; reports an already-closed or merged PR without writing; refuses an issue |
|
|
60
|
+
| `pr:reopen` | Reopen a closed pull request and confirm the forge reports it open; reports an already-open PR without writing; refuses a merged PR and an issue |
|
|
59
61
|
| `pr:retarget` | Repoint an open pull request at a new base branch, confirm the forge took it, and report its mergeability as advice |
|
|
60
62
|
| `workflow:dispatch` | Dispatch a workflow with `--workflow`, `--ref` and repeatable `--input`; takes `--repo owner/repo`, not a URL |
|
|
61
63
|
| `ci:runs` | List a repository's workflow runs with their jobs, filtered by workflow, ref, pull request, head SHA or status |
|
|
62
64
|
| `ci:log` | Print one workflow job's whole log, or with `--grep` only the lines whose text matches |
|
|
63
65
|
|
|
64
66
|
Zero posted statuses reads as `no-status`, never as green. Every command is Forgejo-only: on
|
|
65
|
-
GitHub, use `gh`. The `issue:*`, `pr:create`, `pr:update`, `pr:ready` and `pr:retarget`
|
|
67
|
+
GitHub, use `gh`. The `issue:*`, `pr:create`, `pr:update`, `pr:ready`, `pr:reopen` and `pr:retarget`
|
|
68
|
+
commands take the same flags and print the
|
|
66
69
|
same `--json` documents as `bst`'s, except that `issue:create` has no config default for assignees.
|
package/bin/bst-fj.mjs
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
*
|
|
12
12
|
* The indirection costs one module load and makes the bin link independent of build state: the
|
|
13
13
|
* link always exists, and `dist/bin.mjs` only has to be there by the time someone runs it. When
|
|
14
|
-
* it is not, the
|
|
15
|
-
*
|
|
14
|
+
* it is not, the shim says so in one line and names the command that builds it, rather than
|
|
15
|
+
* leaving Node's ERR_MODULE_NOT_FOUND stack trace.
|
|
16
16
|
*
|
|
17
17
|
* Consumers installing from the registry get both files (`files` ships `bin` and `dist`) and are
|
|
18
18
|
* unaffected either way, since a published tarball is always built.
|
|
@@ -22,4 +22,13 @@
|
|
|
22
22
|
* wrong trade for a file whose entire purpose is a side effect: the dynamic form says "run this"
|
|
23
23
|
* rather than "bring in these bindings", which is what is actually meant here.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
import { existsSync } from "node:fs";
|
|
26
|
+
import { fileURLToPath } from "node:url";
|
|
27
|
+
|
|
28
|
+
const entry = new URL("../dist/bin.mjs", import.meta.url);
|
|
29
|
+
if (existsSync(entry)) {
|
|
30
|
+
await import(entry.href);
|
|
31
|
+
} else {
|
|
32
|
+
process.stderr.write(`bst-fj: ${fileURLToPath(entry)} is missing. Run \`pnpm build\` first.\n`);
|
|
33
|
+
process.exitCode = 1;
|
|
34
|
+
}
|
package/dist/bin.mjs
CHANGED
|
@@ -160,7 +160,7 @@ function loadEnvFileForBin(rawArgs, bin, io = processIo) {
|
|
|
160
160
|
// src/version.ts
|
|
161
161
|
const parsed = z.object({ version: z.string() }).safeParse({
|
|
162
162
|
name: "@bensandee/forgejo-cli",
|
|
163
|
-
version: "0.
|
|
163
|
+
version: "0.8.0",
|
|
164
164
|
description: "bst-fj: Forgejo API commands without the rest of bst",
|
|
165
165
|
license: "MIT",
|
|
166
166
|
repository: {
|
|
@@ -196,7 +196,7 @@ const parsed = z.object({ version: z.string() }).safeParse({
|
|
|
196
196
|
"@bensandee/cli-kit": "workspace:*",
|
|
197
197
|
"@bensandee/forgejo": "workspace:*",
|
|
198
198
|
"@types/node": "24.19.2",
|
|
199
|
-
"tsdown": "0.23.
|
|
199
|
+
"tsdown": "0.23.4"
|
|
200
200
|
}
|
|
201
201
|
});
|
|
202
202
|
if (!parsed.success) throw new UnexpectedError(`@bensandee/forgejo-cli's package.json has no string version.`);
|
|
@@ -1284,6 +1284,7 @@ function branchNotFoundMessage(conn, branch) {
|
|
|
1284
1284
|
return `Branch ${branch} not found in ${conn.repository}`;
|
|
1285
1285
|
}
|
|
1286
1286
|
z.object({ full_name: z.string() });
|
|
1287
|
+
z.object({ description: z.string().optional() });
|
|
1287
1288
|
async function getBranchHeadSha(executor, conn, branch) {
|
|
1288
1289
|
const url = `${repoBase(conn)}/branches/${encodeURIComponent(branch)}`;
|
|
1289
1290
|
const res = await executor.fetch(url, { headers: authHeaders(conn) });
|
|
@@ -1449,6 +1450,7 @@ async function settleChecks(fetcher, conn, poll, round) {
|
|
|
1449
1450
|
} else {
|
|
1450
1451
|
consecutiveFailures = 0;
|
|
1451
1452
|
lastGoodChecks = checks;
|
|
1453
|
+
round.observe?.(checks);
|
|
1452
1454
|
pushDisagreementNotice(round.notices, sha, checks);
|
|
1453
1455
|
if (isSettled(checks)) {
|
|
1454
1456
|
const contexts = new Set(checks.contexts.map((check) => check.context));
|
|
@@ -1696,6 +1698,15 @@ function carryForwardClosingRefs(source, target) {
|
|
|
1696
1698
|
const refLines = missing.map((ref) => ref.text).join("\n");
|
|
1697
1699
|
return target.trim() === "" ? refLines : `${target}\n\n${refLines}`;
|
|
1698
1700
|
}
|
|
1701
|
+
function parseIssueList(value) {
|
|
1702
|
+
const numbers = /* @__PURE__ */ new Set();
|
|
1703
|
+
for (const part of value.split(",")) {
|
|
1704
|
+
const match = /^#?([1-9]\d*)$/.exec(part.trim());
|
|
1705
|
+
if (match?.[1] === void 0) throw new FatalError(`--closes takes issue numbers separated by commas, such as 12 or 12,15; got ${JSON.stringify(value)}.`);
|
|
1706
|
+
numbers.add(Number(match[1]));
|
|
1707
|
+
}
|
|
1708
|
+
return [...numbers];
|
|
1709
|
+
}
|
|
1699
1710
|
// ../forgejo/src/fetcher.ts
|
|
1700
1711
|
const LONG_FETCH_TIMEOUT_MS = 6e5;
|
|
1701
1712
|
function morePagesFollow(res, pageLength, received, pageSize) {
|
|
@@ -3337,7 +3348,7 @@ function readActionsJobLog(text) {
|
|
|
3337
3348
|
lines
|
|
3338
3349
|
};
|
|
3339
3350
|
}
|
|
3340
|
-
// src/ci-log.ts
|
|
3351
|
+
// src/ci/ci-log.ts
|
|
3341
3352
|
const ACTIONS_RUN_URL = /\/actions\/runs\/(\d+)\/?(?:[?#]|$)/u;
|
|
3342
3353
|
function parseCiLogTarget(target) {
|
|
3343
3354
|
if (/^\d+$/.test(target)) return {
|
|
@@ -3482,7 +3493,7 @@ const ciLogCommand = defineCommand({
|
|
|
3482
3493
|
out.text(renderCiLog(result));
|
|
3483
3494
|
}
|
|
3484
3495
|
});
|
|
3485
|
-
// src/ci-runs.ts
|
|
3496
|
+
// src/ci/ci-runs.ts
|
|
3486
3497
|
function resolveRunsRef(ref, pr) {
|
|
3487
3498
|
if (ref !== void 0 && pr !== void 0) throw new FatalError("--ref and --pr are the same filter -- give one of them (--pr 273 for a pull request's own runs, --ref main for a branch's).");
|
|
3488
3499
|
if (pr !== void 0) {
|
|
@@ -3650,7 +3661,7 @@ function parseInputs(raw) {
|
|
|
3650
3661
|
}
|
|
3651
3662
|
return inputs;
|
|
3652
3663
|
}
|
|
3653
|
-
// src/workflow-dispatch.ts
|
|
3664
|
+
// src/ci/workflow-dispatch.ts
|
|
3654
3665
|
async function runWorkflowDispatch(fetcher, options) {
|
|
3655
3666
|
const dispatched = await dispatchWorkflow(fetcher, requireForgejoTarget(options.cwd, void 0, "workflow:dispatch is Forgejo-only -- use gh workflow run on GitHub."), {
|
|
3656
3667
|
...options.repo === void 0 ? {} : { repository: options.repo },
|
|
@@ -3667,7 +3678,7 @@ async function runWorkflowDispatch(fetcher, options) {
|
|
|
3667
3678
|
inputs: dispatched.inputs
|
|
3668
3679
|
};
|
|
3669
3680
|
}
|
|
3670
|
-
// src/registry-actions.ts
|
|
3681
|
+
// src/registry/registry-actions.ts
|
|
3671
3682
|
const actionsSubCommands = {
|
|
3672
3683
|
"ci:log": ciLogCommand,
|
|
3673
3684
|
"ci:runs": ciRunsCommand,
|
|
@@ -3841,7 +3852,7 @@ function renderBranchList(listing) {
|
|
|
3841
3852
|
if (listing.truncated) lines.push("Listing truncated at the page cap; more branches exist.");
|
|
3842
3853
|
return lines.join("\n");
|
|
3843
3854
|
}
|
|
3844
|
-
// src/registry-branch.ts
|
|
3855
|
+
// src/registry/registry-branch.ts
|
|
3845
3856
|
const branchSubCommands = {
|
|
3846
3857
|
"branch:delete": defineCommand({
|
|
3847
3858
|
meta: {
|
|
@@ -4181,8 +4192,13 @@ const PrDetailSchema = z.object({
|
|
|
4181
4192
|
draft: z.boolean(),
|
|
4182
4193
|
merged: z.boolean(),
|
|
4183
4194
|
mergeable: z.boolean().nullish(),
|
|
4195
|
+
merge_commit_sha: z.string().nullish(),
|
|
4184
4196
|
state: z.string()
|
|
4185
4197
|
});
|
|
4198
|
+
const MERGE_COMMIT_SHA = /^[0-9a-f]{7,64}$/;
|
|
4199
|
+
function isMergeCommitSha(value) {
|
|
4200
|
+
return value !== void 0 && value !== null && MERGE_COMMIT_SHA.test(value);
|
|
4201
|
+
}
|
|
4186
4202
|
function normalizePrDetail(data) {
|
|
4187
4203
|
return {
|
|
4188
4204
|
head: {
|
|
@@ -4198,6 +4214,7 @@ function normalizePrDetail(data) {
|
|
|
4198
4214
|
draft: data.draft,
|
|
4199
4215
|
merged: data.merged,
|
|
4200
4216
|
mergeable: data.mergeable ?? null,
|
|
4217
|
+
mergeCommitSha: isMergeCommitSha(data.merge_commit_sha) ? data.merge_commit_sha : null,
|
|
4201
4218
|
state: data.state
|
|
4202
4219
|
};
|
|
4203
4220
|
}
|
|
@@ -4242,6 +4259,21 @@ async function retargetPr(executor, conn, prNumber, base) {
|
|
|
4242
4259
|
resource: `#${String(prNumber)}`
|
|
4243
4260
|
});
|
|
4244
4261
|
}
|
|
4262
|
+
async function reopenPr(executor, conn, prNumber) {
|
|
4263
|
+
const url = `${conn.serverUrl}/api/v1/repos/${conn.repository}/pulls/${String(prNumber)}`;
|
|
4264
|
+
const res = await executor.fetch(url, {
|
|
4265
|
+
method: "PATCH",
|
|
4266
|
+
headers: {
|
|
4267
|
+
Authorization: `token ${conn.token}`,
|
|
4268
|
+
"Content-Type": "application/json"
|
|
4269
|
+
},
|
|
4270
|
+
body: JSON.stringify({ state: "open" })
|
|
4271
|
+
}, { idempotent: true });
|
|
4272
|
+
if (!res.ok) await throwForgejoFailure(res, {
|
|
4273
|
+
verb: "reopen PR",
|
|
4274
|
+
resource: `#${String(prNumber)}`
|
|
4275
|
+
});
|
|
4276
|
+
}
|
|
4245
4277
|
const PrContentSchema = z.object({
|
|
4246
4278
|
title: z.string(),
|
|
4247
4279
|
body: z.string().nullish()
|
|
@@ -4293,6 +4325,7 @@ const PullReviewCommentSchema = z.object({
|
|
|
4293
4325
|
user: z.object({ login: z.string() }).nullish()
|
|
4294
4326
|
});
|
|
4295
4327
|
z.array(PullReviewCommentSchema);
|
|
4328
|
+
z.array(z.object({ id: z.number() }));
|
|
4296
4329
|
// ../forgejo/src/issue-api.ts
|
|
4297
4330
|
var IssueNumberRequiredError = class extends FatalError {
|
|
4298
4331
|
constructor() {
|
|
@@ -4630,7 +4663,7 @@ function forgejoIssueTransport(cwd, target, command) {
|
|
|
4630
4663
|
target: resolved.target
|
|
4631
4664
|
};
|
|
4632
4665
|
}
|
|
4633
|
-
// src/commands/issue-comment.ts
|
|
4666
|
+
// src/commands/issue/issue-comment.ts
|
|
4634
4667
|
const issueCommentCommand = defineCommand({
|
|
4635
4668
|
meta: {
|
|
4636
4669
|
name: "issue:comment",
|
|
@@ -4688,7 +4721,7 @@ const issueCommentCommand = defineCommand({
|
|
|
4688
4721
|
}
|
|
4689
4722
|
}
|
|
4690
4723
|
});
|
|
4691
|
-
// src/commands/issue-create.ts
|
|
4724
|
+
// src/commands/issue/issue-create.ts
|
|
4692
4725
|
const issueCreateCommand = defineCommand({
|
|
4693
4726
|
meta: {
|
|
4694
4727
|
name: "issue:create",
|
|
@@ -4854,7 +4887,7 @@ function formatDownload(result, dryRun) {
|
|
|
4854
4887
|
for (const file of result.files) lines.push(` ${file.name} (${String(file.size)} bytes)`);
|
|
4855
4888
|
return lines.join("\n");
|
|
4856
4889
|
}
|
|
4857
|
-
// src/commands/issue-download.ts
|
|
4890
|
+
// src/commands/issue/issue-download.ts
|
|
4858
4891
|
const issueDownloadCommand = defineCommand({
|
|
4859
4892
|
meta: {
|
|
4860
4893
|
name: "issue:download",
|
|
@@ -5033,7 +5066,7 @@ function formatIssueSetLabels(result, dryRun) {
|
|
|
5033
5066
|
if (result.added.length > 0) lines.push(` ${dryRun ? "would add" : "added"}: ${result.added.join(", ")}`);
|
|
5034
5067
|
return lines.join("\n");
|
|
5035
5068
|
}
|
|
5036
|
-
// src/commands/issue-label.ts
|
|
5069
|
+
// src/commands/issue/issue-label.ts
|
|
5037
5070
|
function defineIssueLabelCommand(action) {
|
|
5038
5071
|
const name = action === "add" ? "issue:label" : "issue:unlabel";
|
|
5039
5072
|
return defineCommand({
|
|
@@ -5092,7 +5125,7 @@ function defineIssueLabelCommand(action) {
|
|
|
5092
5125
|
}
|
|
5093
5126
|
const issueLabelCommand = defineIssueLabelCommand("add");
|
|
5094
5127
|
const issueUnlabelCommand = defineIssueLabelCommand("remove");
|
|
5095
|
-
// src/commands/issue-set-labels.ts
|
|
5128
|
+
// src/commands/issue/issue-set-labels.ts
|
|
5096
5129
|
const issueSetLabelsCommand = defineCommand({
|
|
5097
5130
|
meta: {
|
|
5098
5131
|
name: "issue:set-labels",
|
|
@@ -5248,7 +5281,7 @@ function formatIssueState(result, dryRun) {
|
|
|
5248
5281
|
}
|
|
5249
5282
|
return lines.join("\n");
|
|
5250
5283
|
}
|
|
5251
|
-
// src/commands/issue-state.ts
|
|
5284
|
+
// src/commands/issue/issue-state.ts
|
|
5252
5285
|
function defineIssueStateCommand(action) {
|
|
5253
5286
|
const name = action === "close" ? "issue:close" : "issue:reopen";
|
|
5254
5287
|
return defineCommand({
|
|
@@ -5311,7 +5344,7 @@ function defineIssueStateCommand(action) {
|
|
|
5311
5344
|
if (error instanceof IssueNumberRequiredError) throw new FatalError(describeIssueNumberRequired(`pnpm exec bst-fj ${name} 273`));
|
|
5312
5345
|
if (error instanceof EmptyCommentError) throw new FatalError(describeEmptyComment(flags));
|
|
5313
5346
|
if (error instanceof PullRequestStateError) {
|
|
5314
|
-
const advice = action === "close" ? `Run \`pnpm exec bst-fj pr:close ${String(error.number)}\` to close it.` :
|
|
5347
|
+
const advice = action === "close" ? `Run \`pnpm exec bst-fj pr:close ${String(error.number)}\` to close it.` : `Run \`pnpm exec bst-fj pr:reopen ${String(error.number)}\` to reopen it.`;
|
|
5315
5348
|
throw new FatalError(describePullRequestState(error, {
|
|
5316
5349
|
command: `bst-fj ${name}`,
|
|
5317
5350
|
advice
|
|
@@ -5324,7 +5357,7 @@ function defineIssueStateCommand(action) {
|
|
|
5324
5357
|
}
|
|
5325
5358
|
const issueCloseCommand = defineIssueStateCommand("close");
|
|
5326
5359
|
const issueReopenCommand = defineIssueStateCommand("reopen");
|
|
5327
|
-
// src/commands/issue-list.ts
|
|
5360
|
+
// src/commands/issue/issue-list.ts
|
|
5328
5361
|
const issueListCommand = defineCommand({
|
|
5329
5362
|
meta: {
|
|
5330
5363
|
name: "issue:list",
|
|
@@ -5382,7 +5415,7 @@ const issueListCommand = defineCommand({
|
|
|
5382
5415
|
}
|
|
5383
5416
|
}
|
|
5384
5417
|
});
|
|
5385
|
-
// src/commands/issue-update.ts
|
|
5418
|
+
// src/commands/issue/issue-update.ts
|
|
5386
5419
|
const issueUpdateCommand = defineCommand({
|
|
5387
5420
|
meta: {
|
|
5388
5421
|
name: "issue:update",
|
|
@@ -5453,7 +5486,7 @@ const issueUpdateCommand = defineCommand({
|
|
|
5453
5486
|
}
|
|
5454
5487
|
}
|
|
5455
5488
|
});
|
|
5456
|
-
// src/registry-issue.ts
|
|
5489
|
+
// src/registry/registry-issue.ts
|
|
5457
5490
|
const issueSubCommands = {
|
|
5458
5491
|
"issue:view": defineCommand({
|
|
5459
5492
|
meta: {
|
|
@@ -5506,7 +5539,7 @@ const issueSubCommands = {
|
|
|
5506
5539
|
"issue:set-labels": issueSetLabelsCommand,
|
|
5507
5540
|
"issue:download": issueDownloadCommand
|
|
5508
5541
|
};
|
|
5509
|
-
// src/pr-checks.ts
|
|
5542
|
+
// src/pr/pr-checks.ts
|
|
5510
5543
|
async function resolvePrChecksTarget(fetcher, options) {
|
|
5511
5544
|
const ref = parseIssueRef(options.pr);
|
|
5512
5545
|
if (options.repo !== void 0 && ref.number === void 0 && options.branch === void 0) throw new FatalError("--repo requires --pr or --branch -- the current branch of this checkout means nothing in another repository, and inferring it there would silently answer about the wrong PR.");
|
|
@@ -5680,7 +5713,7 @@ function renderPrChecks(report) {
|
|
|
5680
5713
|
lines.push(summaryParts.join(" -- "));
|
|
5681
5714
|
return lines.join("\n");
|
|
5682
5715
|
}
|
|
5683
|
-
// src/commands/pr-checks.ts
|
|
5716
|
+
// src/commands/pr/pr-checks.ts
|
|
5684
5717
|
const prChecksCommand = defineCommand({
|
|
5685
5718
|
meta: {
|
|
5686
5719
|
name: "pr:checks",
|
|
@@ -5767,7 +5800,7 @@ function parsePrNumber(raw) {
|
|
|
5767
5800
|
if (!/^\d+$/.test(raw) || !Number.isSafeInteger(value) || value < 1) throw new FatalError(`Invalid pull request number "${raw}" (expected a positive integer).`);
|
|
5768
5801
|
return value;
|
|
5769
5802
|
}
|
|
5770
|
-
// src/commands/pr-close.ts
|
|
5803
|
+
// src/commands/pr/pr-close.ts
|
|
5771
5804
|
const prCloseCommand = defineCommand({
|
|
5772
5805
|
meta: {
|
|
5773
5806
|
name: "pr:close",
|
|
@@ -6078,7 +6111,51 @@ function checkClosingLinks(messages, plan, allowUnlink) {
|
|
|
6078
6111
|
unlinked
|
|
6079
6112
|
};
|
|
6080
6113
|
}
|
|
6114
|
+
function addClosingIssues(plan, issues) {
|
|
6115
|
+
const wanted = issues.map((issue) => `Closes #${String(issue)}`).join("\n");
|
|
6116
|
+
const added = droppedClosingRefs([wanted], plan.effective.body).map((ref) => Number(ref.issue.slice(1)));
|
|
6117
|
+
if (added.length === 0) return {
|
|
6118
|
+
plan,
|
|
6119
|
+
added
|
|
6120
|
+
};
|
|
6121
|
+
const body = carryForwardClosingRefs(wanted, plan.effective.body);
|
|
6122
|
+
return {
|
|
6123
|
+
plan: {
|
|
6124
|
+
...plan,
|
|
6125
|
+
patch: {
|
|
6126
|
+
...plan.patch,
|
|
6127
|
+
body
|
|
6128
|
+
},
|
|
6129
|
+
effective: {
|
|
6130
|
+
...plan.effective,
|
|
6131
|
+
body
|
|
6132
|
+
}
|
|
6133
|
+
},
|
|
6134
|
+
added
|
|
6135
|
+
};
|
|
6136
|
+
}
|
|
6081
6137
|
const ALWAYS_PROTECTED = /* @__PURE__ */ new Set(["main", "master"]);
|
|
6138
|
+
async function planUpsert(host, existing, derived, options) {
|
|
6139
|
+
let plan;
|
|
6140
|
+
if (existing === null) plan = {
|
|
6141
|
+
patch: {
|
|
6142
|
+
title: derived.title,
|
|
6143
|
+
body: derived.body
|
|
6144
|
+
},
|
|
6145
|
+
effective: derived,
|
|
6146
|
+
previousBody: null
|
|
6147
|
+
};
|
|
6148
|
+
else plan = planPrUpdate(options, derived, prUpdateNeedsLive(options) ? await host.readLive(existing, options.signal ?? null) : null, host.wipTitles);
|
|
6149
|
+
if (options.closes === void 0) return {
|
|
6150
|
+
plan,
|
|
6151
|
+
closesAdded: void 0
|
|
6152
|
+
};
|
|
6153
|
+
const linked = addClosingIssues(plan, options.closes);
|
|
6154
|
+
return {
|
|
6155
|
+
plan: linked.plan,
|
|
6156
|
+
closesAdded: linked.added
|
|
6157
|
+
};
|
|
6158
|
+
}
|
|
6082
6159
|
async function runPrUpsert(git, host, options) {
|
|
6083
6160
|
const { cwd } = options;
|
|
6084
6161
|
const mode = options.mode ?? "upsert";
|
|
@@ -6111,22 +6188,14 @@ async function runPrUpsert(git, host, options) {
|
|
|
6111
6188
|
const existing = open?.number ?? null;
|
|
6112
6189
|
assertModeAllows(mode, existing, branch);
|
|
6113
6190
|
if (!options.dryRun && options.skipPush !== true) await pushBranch(git, cwd, branch, options.pushEnv, options.forceWithLease);
|
|
6114
|
-
|
|
6115
|
-
if (existing === null) plan = {
|
|
6116
|
-
patch: {
|
|
6117
|
-
title: derived.title,
|
|
6118
|
-
body: derived.body
|
|
6119
|
-
},
|
|
6120
|
-
effective: derived,
|
|
6121
|
-
previousBody: null
|
|
6122
|
-
};
|
|
6123
|
-
else plan = planPrUpdate(options, derived, prUpdateNeedsLive(options) ? await host.readLive(existing, signal) : null, host.wipTitles);
|
|
6191
|
+
const { plan, closesAdded } = await planUpsert(host, existing, derived, options);
|
|
6124
6192
|
const report = checkClosingLinks(messages, plan, options.allowUnlink === true);
|
|
6125
6193
|
options.onClosingLinks?.(report);
|
|
6126
6194
|
const shape = {
|
|
6127
6195
|
branch,
|
|
6128
6196
|
base: open?.base ?? localBase,
|
|
6129
|
-
...plan.effective
|
|
6197
|
+
...plan.effective,
|
|
6198
|
+
...closesAdded === void 0 ? {} : { closesAdded }
|
|
6130
6199
|
};
|
|
6131
6200
|
if (options.dryRun) return {
|
|
6132
6201
|
action: existing === null ? "would-create" : "would-update",
|
|
@@ -6162,7 +6231,7 @@ function describeClosingLinks(report, flags) {
|
|
|
6162
6231
|
const lines = [];
|
|
6163
6232
|
if (report.fromCommits.length > 0) {
|
|
6164
6233
|
const said = report.fromCommits.map((dropped) => dropped.text).join(", ");
|
|
6165
|
-
lines.push(`The commits say ${said}, but the PR body does not -- the issue may not close on merge.
|
|
6234
|
+
lines.push(`The commits say ${said}, but the PR body does not -- the issue may not close on merge. Link it with ${flags.closes}.`);
|
|
6166
6235
|
}
|
|
6167
6236
|
if (report.unlinked.length > 0) {
|
|
6168
6237
|
const lost = report.unlinked.map((dropped) => dropped.text).join(", ");
|
|
@@ -6214,15 +6283,17 @@ function formatPrCreate(result) {
|
|
|
6214
6283
|
};
|
|
6215
6284
|
}
|
|
6216
6285
|
function formatPrUpdate(result, rewrites, flags) {
|
|
6286
|
+
const added = result.closesAdded ?? [];
|
|
6217
6287
|
if (isDryRun(result)) return {
|
|
6218
6288
|
lines: [`[dry-run] Would push ${prTarget(result)} to ${prLabel(result)}`],
|
|
6219
6289
|
body: {
|
|
6220
|
-
heading: rewrites ? "[dry-run] Body" : "[dry-run] Body (unchanged)",
|
|
6290
|
+
heading: rewrites || added.length > 0 ? "[dry-run] Body" : "[dry-run] Body (unchanged)",
|
|
6221
6291
|
text: result.body
|
|
6222
6292
|
}
|
|
6223
6293
|
};
|
|
6224
6294
|
const lines = [`Updated ${prLabel(result)} (${prTarget(result)})`];
|
|
6225
|
-
if (
|
|
6295
|
+
if (added.length > 0) lines.push(`Linked ${added.map((issue) => `#${String(issue)}`).join(", ")} with a Closes line.`);
|
|
6296
|
+
else if (!rewrites) lines.push(`Title and body left as authored -- pass ${flags.title}/${flags.body} to change them.`);
|
|
6226
6297
|
if (result.url !== null) lines.push(result.url);
|
|
6227
6298
|
return {
|
|
6228
6299
|
lines,
|
|
@@ -6259,7 +6330,8 @@ function forgejoPrEditHost(fetcher, conn) {
|
|
|
6259
6330
|
readLive: (number) => getPrEditState(fetcher, conn, number),
|
|
6260
6331
|
branchExists: (name) => branchExists(fetcher, conn, name),
|
|
6261
6332
|
setBase: (number, base) => retargetPr(fetcher, conn, number, base),
|
|
6262
|
-
ready: (number, write) => updatePr(fetcher, conn, number, { title: write.title })
|
|
6333
|
+
ready: (number, write) => updatePr(fetcher, conn, number, { title: write.title }),
|
|
6334
|
+
reopen: (number) => reopenPr(fetcher, conn, number)
|
|
6263
6335
|
};
|
|
6264
6336
|
}
|
|
6265
6337
|
// src/git.ts
|
|
@@ -6338,13 +6410,13 @@ function cliGit() {
|
|
|
6338
6410
|
});
|
|
6339
6411
|
}) };
|
|
6340
6412
|
}
|
|
6341
|
-
// src/pr-run.ts
|
|
6413
|
+
// src/pr/pr-run.ts
|
|
6342
6414
|
const COMMANDS = {
|
|
6343
6415
|
create: "pnpm exec bst-fj pr:create",
|
|
6344
6416
|
update: "pnpm exec bst-fj pr:update"
|
|
6345
6417
|
};
|
|
6346
6418
|
const FLAGS = {
|
|
6347
|
-
|
|
6419
|
+
closes: "--closes",
|
|
6348
6420
|
allowUnlink: "--allow-unlink"
|
|
6349
6421
|
};
|
|
6350
6422
|
function warnClosingLinks(report) {
|
|
@@ -6372,7 +6444,7 @@ async function runForgejoPr(githubRefusal, options) {
|
|
|
6372
6444
|
});
|
|
6373
6445
|
}
|
|
6374
6446
|
}
|
|
6375
|
-
// src/commands/pr-create.ts
|
|
6447
|
+
// src/commands/pr/pr-create.ts
|
|
6376
6448
|
const prCreateCommand = defineCommand({
|
|
6377
6449
|
meta: {
|
|
6378
6450
|
name: "pr:create",
|
|
@@ -6407,13 +6479,17 @@ const prCreateCommand = defineCommand({
|
|
|
6407
6479
|
type: "boolean",
|
|
6408
6480
|
description: "With --upsert: permit a --body that drops a closing keyword the PR carries"
|
|
6409
6481
|
},
|
|
6482
|
+
closes: {
|
|
6483
|
+
type: "string",
|
|
6484
|
+
description: "Issues the PR closes, comma-separated (12 or 12,15): adds a Closes #<n> line to the body for each one it does not already close"
|
|
6485
|
+
},
|
|
6410
6486
|
"dry-run": {
|
|
6411
6487
|
type: "boolean",
|
|
6412
6488
|
description: "Show what would happen without pushing"
|
|
6413
6489
|
},
|
|
6414
6490
|
json: {
|
|
6415
6491
|
type: "boolean",
|
|
6416
|
-
description: "Emit one JSON document: action (created | updated | would-create | would-update), number (or null), url (or null), branch, base, title, body, droppedRefs? ([{text, issue}]), dryRun. A create or would-create carries droppedRefs; on a dry run, number and url are null. The document carries no claims member and no claim advice line: the closed-issue claim check reads the repo's .tooling.json and is bst pr:create's alone."
|
|
6492
|
+
description: "Emit one JSON document: action (created | updated | would-create | would-update), number (or null), url (or null), branch, base, title, body, droppedRefs? ([{text, issue}]), closesAdded? (with --closes: the issues it added a Closes line for), dryRun. A create or would-create carries droppedRefs; on a dry run, number and url are null. The document carries no claims member and no claim advice line: the closed-issue claim check reads the repo's .tooling.json and is bst pr:create's alone."
|
|
6417
6493
|
},
|
|
6418
6494
|
verbose: {
|
|
6419
6495
|
type: "boolean",
|
|
@@ -6429,6 +6505,7 @@ const prCreateCommand = defineCommand({
|
|
|
6429
6505
|
body,
|
|
6430
6506
|
base: args.base ?? void 0,
|
|
6431
6507
|
allowUnlink: args["allow-unlink"] === true,
|
|
6508
|
+
closes: args.closes === void 0 ? void 0 : parseIssueList(args.closes),
|
|
6432
6509
|
draft: args.draft === true ? true : void 0,
|
|
6433
6510
|
dryRun: args["dry-run"] === true
|
|
6434
6511
|
});
|
|
@@ -6486,7 +6563,7 @@ async function readPrFilesPage(executor, conn, prNumber, page, limit) {
|
|
|
6486
6563
|
truncated: res.headers.get("x-hasmore") === "true"
|
|
6487
6564
|
};
|
|
6488
6565
|
}
|
|
6489
|
-
// src/pr-files.ts
|
|
6566
|
+
// src/pr/pr-files.ts
|
|
6490
6567
|
function runPrFiles(fetcher, options) {
|
|
6491
6568
|
const number = parsePrNumber(options.number);
|
|
6492
6569
|
return listAllPrFiles(fetcher, requireForgejoTarget(options.cwd, parseRepoTarget(options.repo), "pr:files is Forgejo-only -- gh pr diff --name-only already serves GitHub."), number);
|
|
@@ -6497,7 +6574,7 @@ function renderPrFiles(listing) {
|
|
|
6497
6574
|
if (listing.truncated) lines.push("Listing truncated; the pull request changes more files.");
|
|
6498
6575
|
return lines.join("\n");
|
|
6499
6576
|
}
|
|
6500
|
-
// src/commands/pr-files.ts
|
|
6577
|
+
// src/commands/pr/pr-files.ts
|
|
6501
6578
|
const prFilesCommand = defineCommand({
|
|
6502
6579
|
meta: {
|
|
6503
6580
|
name: "pr:files",
|
|
@@ -6536,7 +6613,7 @@ const prFilesCommand = defineCommand({
|
|
|
6536
6613
|
out.text(renderPrFiles(listing));
|
|
6537
6614
|
}
|
|
6538
6615
|
});
|
|
6539
|
-
// src/pr-list.ts
|
|
6616
|
+
// src/pr/pr-list.ts
|
|
6540
6617
|
function parseState(state) {
|
|
6541
6618
|
if (state === "open" || state === "closed" || state === "all") return state;
|
|
6542
6619
|
throw new FatalError(`Invalid --state "${state}" (expected open, closed, or all).`);
|
|
@@ -6573,7 +6650,7 @@ function renderPrList(result) {
|
|
|
6573
6650
|
return `#${String(pr.number)} ${statusLabel(pr)} ${branches}: ${pr.title ?? "(no title)"}${labels}${url}`;
|
|
6574
6651
|
}).join("\n");
|
|
6575
6652
|
}
|
|
6576
|
-
// src/commands/pr-list.ts
|
|
6653
|
+
// src/commands/pr/pr-list.ts
|
|
6577
6654
|
const prListCommand = defineCommand({
|
|
6578
6655
|
meta: {
|
|
6579
6656
|
name: "pr:list",
|
|
@@ -6790,7 +6867,7 @@ async function runPrMergeCore(fetcher, conn, number, options = {}) {
|
|
|
6790
6867
|
}
|
|
6791
6868
|
};
|
|
6792
6869
|
}
|
|
6793
|
-
// src/pr-merge.ts
|
|
6870
|
+
// src/pr/pr-merge.ts
|
|
6794
6871
|
function parseMethod(raw) {
|
|
6795
6872
|
if (raw === void 0) return "merge";
|
|
6796
6873
|
const method = MERGE_METHODS.find((candidate) => candidate === raw);
|
|
@@ -6817,7 +6894,7 @@ function renderPrMerge(result) {
|
|
|
6817
6894
|
const what = `PR #${String(result.number)} (${result.method}) at ${result.headSha.slice(0, 12)}, checks ${result.checks}`;
|
|
6818
6895
|
return result.merged ? `Merged ${what}.` : `Dry run: would merge ${what}.`;
|
|
6819
6896
|
}
|
|
6820
|
-
// src/commands/pr-merge.ts
|
|
6897
|
+
// src/commands/pr/pr-merge.ts
|
|
6821
6898
|
const prMergeCommand = defineCommand({
|
|
6822
6899
|
meta: {
|
|
6823
6900
|
name: "pr:merge",
|
|
@@ -6879,8 +6956,9 @@ function isOpen(live) {
|
|
|
6879
6956
|
return live.state === "open" && live.merged === false;
|
|
6880
6957
|
}
|
|
6881
6958
|
function notOpenMessage(prNumber, live) {
|
|
6882
|
-
const
|
|
6883
|
-
return `Pull request
|
|
6959
|
+
const number = `#${String(prNumber)}`;
|
|
6960
|
+
if (live.merged) return `Pull request ${number} is merged, so it has no base or draft state left to change.`;
|
|
6961
|
+
return `Pull request ${number} is ${live.state}, so it has no base or draft state left to change. Run \`pr:reopen ${String(prNumber)}\` first if this work is still live.`;
|
|
6884
6962
|
}
|
|
6885
6963
|
async function runPrRetarget(host, options) {
|
|
6886
6964
|
const live = await host.readLive(options.number);
|
|
@@ -6976,8 +7054,47 @@ async function runPrReady(host, options) {
|
|
|
6976
7054
|
dryRun: false
|
|
6977
7055
|
};
|
|
6978
7056
|
}
|
|
7057
|
+
async function runPrReopen(host, options) {
|
|
7058
|
+
const live = await host.readLive(options.number);
|
|
7059
|
+
if (live.merged === true) throw new FatalError(`Pull request #${String(options.number)} was merged, so there is nothing to reopen -- open a new pull request for further work.`);
|
|
7060
|
+
if (live.state === "open") return {
|
|
7061
|
+
action: "already-open",
|
|
7062
|
+
number: options.number,
|
|
7063
|
+
url: live.url,
|
|
7064
|
+
title: live.title,
|
|
7065
|
+
head: live.head,
|
|
7066
|
+
base: live.base,
|
|
7067
|
+
draft: live.draft,
|
|
7068
|
+
dryRun: options.dryRun
|
|
7069
|
+
};
|
|
7070
|
+
if (live.state !== "closed") throw new FatalError(`Pull request #${String(options.number)} reports the state "${live.state}", which this command has no rule for -- it reopens a pull request reported as closed, and guesses at no state it did not expect.`);
|
|
7071
|
+
if (options.dryRun) return {
|
|
7072
|
+
action: "would-reopen",
|
|
7073
|
+
number: options.number,
|
|
7074
|
+
url: live.url,
|
|
7075
|
+
title: live.title,
|
|
7076
|
+
head: live.head,
|
|
7077
|
+
base: live.base,
|
|
7078
|
+
draft: live.draft,
|
|
7079
|
+
dryRun: true
|
|
7080
|
+
};
|
|
7081
|
+
await host.reopen(options.number);
|
|
7082
|
+
const recheck = await host.readLive(options.number);
|
|
7083
|
+
if (!isOpen(recheck)) throw new FatalError(`Pull request #${String(options.number)} still reports \`${recheck.state}\` after the request to reopen it -- reopen it in the forge's web interface.`);
|
|
7084
|
+
return {
|
|
7085
|
+
action: "reopened",
|
|
7086
|
+
number: options.number,
|
|
7087
|
+
url: recheck.url,
|
|
7088
|
+
title: recheck.title,
|
|
7089
|
+
head: recheck.head,
|
|
7090
|
+
base: recheck.base,
|
|
7091
|
+
draft: recheck.draft,
|
|
7092
|
+
dryRun: false
|
|
7093
|
+
};
|
|
7094
|
+
}
|
|
6979
7095
|
const PR_RETARGET_JSON_HELP = "Emit one JSON document: action (retargeted | unchanged | would-retarget), number, url, previousBase, base, head, mergeable (true | false | null, advice only), dryRun; a refusal is an error, never this document.";
|
|
6980
7096
|
const PR_READY_JSON_HELP = "Emit one JSON document: action (readied | retitled | already-ready | would-ready | would-retitle), number, url, previousTitle, title, draft, dryRun; a refusal is an error, never this document.";
|
|
7097
|
+
const PR_REOPEN_JSON_HELP = "Emit one JSON document: action (reopened | already-open | would-reopen), number, url, title, head, base, draft, dryRun; a refusal is an error, never this document.";
|
|
6981
7098
|
function mergeabilityLine(mergeable) {
|
|
6982
7099
|
if (mergeable === true) return "Mergeability: mergeable.";
|
|
6983
7100
|
if (mergeable === false) return "Mergeability: not mergeable -- advice, not a verdict.";
|
|
@@ -7000,7 +7117,17 @@ function renderPrReady(result) {
|
|
|
7000
7117
|
if (result.action === "would-ready") return `Dry run: pull request ${number} would stop being a draft, reading "${result.title}".`;
|
|
7001
7118
|
return `Dry run: pull request ${number} would read "${result.title}".`;
|
|
7002
7119
|
}
|
|
7003
|
-
|
|
7120
|
+
function renderPrReopen(result) {
|
|
7121
|
+
const number = `#${String(result.number)}`;
|
|
7122
|
+
if (result.action === "reopened") {
|
|
7123
|
+
const lines = [`Pull request ${number} is open again (head "${result.head}" -> "${result.base}").`];
|
|
7124
|
+
if (result.draft) lines.push(`It is still a draft -- run pr:ready ${String(result.number)} when it is ready for review.`);
|
|
7125
|
+
return lines.join("\n");
|
|
7126
|
+
}
|
|
7127
|
+
if (result.action === "already-open") return `Pull request ${number} is already open.`;
|
|
7128
|
+
return `Dry run: pull request ${number} would be reopened.`;
|
|
7129
|
+
}
|
|
7130
|
+
// src/registry/registry-pr.ts
|
|
7004
7131
|
const prSubCommands = {
|
|
7005
7132
|
"pr:checks": prChecksCommand,
|
|
7006
7133
|
"pr:close": prCloseCommand,
|
|
@@ -7052,6 +7179,47 @@ const prSubCommands = {
|
|
|
7052
7179
|
out.text(renderPrReady(result));
|
|
7053
7180
|
}
|
|
7054
7181
|
}),
|
|
7182
|
+
"pr:reopen": defineCommand({
|
|
7183
|
+
meta: {
|
|
7184
|
+
name: "pr:reopen",
|
|
7185
|
+
description: "Reopen a closed, unmerged pull request and confirm the forge reports it open. An already-open pull request is reported without writing; a merged one, or an issue, is refused (Forgejo-only; use gh pr reopen on GitHub)"
|
|
7186
|
+
},
|
|
7187
|
+
args: {
|
|
7188
|
+
number: {
|
|
7189
|
+
type: "positional",
|
|
7190
|
+
required: true,
|
|
7191
|
+
description: "Pull request number"
|
|
7192
|
+
},
|
|
7193
|
+
repo: {
|
|
7194
|
+
type: "string",
|
|
7195
|
+
description: "Repository URL (default: this repo)"
|
|
7196
|
+
},
|
|
7197
|
+
"dry-run": {
|
|
7198
|
+
type: "boolean",
|
|
7199
|
+
description: "Run every read and report, but do not write"
|
|
7200
|
+
},
|
|
7201
|
+
json: {
|
|
7202
|
+
type: "boolean",
|
|
7203
|
+
description: PR_REOPEN_JSON_HELP
|
|
7204
|
+
},
|
|
7205
|
+
verbose: {
|
|
7206
|
+
type: "boolean",
|
|
7207
|
+
description: "Emit detailed debug output"
|
|
7208
|
+
}
|
|
7209
|
+
},
|
|
7210
|
+
async run({ args }) {
|
|
7211
|
+
const out = createCliOutput(args.json === true);
|
|
7212
|
+
const conn = requireForgejoTargetFromRepo(process.cwd(), args.repo ?? void 0, "pr:reopen is Forgejo-only -- use gh pr reopen <n> on GitHub.");
|
|
7213
|
+
const number = parsePrNumber(args.number);
|
|
7214
|
+
if (!(await forgejoIssueApi(cliFetcher(), conn).get(number)).isPullRequest) throw new FatalError(`#${String(number)} is an issue, not a pull request -- pr:reopen refuses to write issue state. Use \`pnpm exec bst-fj issue:reopen ${String(number)}\` to reopen it.`);
|
|
7215
|
+
const result = await runPrReopen(forgejoPrEditHost(cliFetcher(), conn), {
|
|
7216
|
+
number,
|
|
7217
|
+
dryRun: args["dry-run"] === true
|
|
7218
|
+
});
|
|
7219
|
+
out.json(result);
|
|
7220
|
+
out.text(renderPrReopen(result));
|
|
7221
|
+
}
|
|
7222
|
+
}),
|
|
7055
7223
|
"pr:retarget": defineCommand({
|
|
7056
7224
|
meta: {
|
|
7057
7225
|
name: "pr:retarget",
|
|
@@ -7125,13 +7293,17 @@ const prSubCommands = {
|
|
|
7125
7293
|
type: "boolean",
|
|
7126
7294
|
description: "Permit a --body that drops a closing keyword the current body carries"
|
|
7127
7295
|
},
|
|
7296
|
+
closes: {
|
|
7297
|
+
type: "string",
|
|
7298
|
+
description: "Issues the PR closes, comma-separated (12 or 12,15): adds a Closes #<n> line to the body for each one it does not already close"
|
|
7299
|
+
},
|
|
7128
7300
|
"dry-run": {
|
|
7129
7301
|
type: "boolean",
|
|
7130
7302
|
description: "Show what would happen without pushing"
|
|
7131
7303
|
},
|
|
7132
7304
|
json: {
|
|
7133
7305
|
type: "boolean",
|
|
7134
|
-
description: "Emit one JSON document: action (updated | would-update), number (or null), url (or null), branch, base, title, body, dryRun, rewrites. On a dry run, number and url are null."
|
|
7306
|
+
description: "Emit one JSON document: action (updated | would-update), number (or null), url (or null), branch, base, title, body, closesAdded? (with --closes: the issues it added a Closes line for), dryRun, rewrites. On a dry run, number and url are null."
|
|
7135
7307
|
},
|
|
7136
7308
|
verbose: {
|
|
7137
7309
|
type: "boolean",
|
|
@@ -7148,6 +7320,7 @@ const prSubCommands = {
|
|
|
7148
7320
|
body,
|
|
7149
7321
|
base: args.base ?? void 0,
|
|
7150
7322
|
allowUnlink: args["allow-unlink"] === true,
|
|
7323
|
+
closes: args.closes === void 0 ? void 0 : parseIssueList(args.closes),
|
|
7151
7324
|
draft: void 0,
|
|
7152
7325
|
dryRun: args["dry-run"] === true
|
|
7153
7326
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bensandee/forgejo-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "bst-fj: Forgejo API commands without the rest of bst",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@bensandee/cli-kit": "0.0.0",
|
|
36
36
|
"@bensandee/forgejo": "0.7.0",
|
|
37
37
|
"@types/node": "24.19.2",
|
|
38
|
-
"tsdown": "0.23.
|
|
38
|
+
"tsdown": "0.23.4"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsdown",
|