@bensandee/forgejo-cli 0.7.0 → 0.9.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 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` and `pr:retarget` still do, and run the same code.
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` commands take the same flags and print the
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 failure is an explicit ERR_MODULE_NOT_FOUND naming the missing build output --
15
- * a far better error than a command that appears not to exist.
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
- await import("../dist/bin.mjs");
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.7.0",
163
+ version: "0.9.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.1"
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.`);
@@ -1450,6 +1450,7 @@ async function settleChecks(fetcher, conn, poll, round) {
1450
1450
  } else {
1451
1451
  consecutiveFailures = 0;
1452
1452
  lastGoodChecks = checks;
1453
+ round.observe?.(checks);
1453
1454
  pushDisagreementNotice(round.notices, sha, checks);
1454
1455
  if (isSettled(checks)) {
1455
1456
  const contexts = new Set(checks.contexts.map((check) => check.context));
@@ -2653,6 +2654,14 @@ async function settleBackoff(attempt, baseDelayMs) {
2653
2654
  const delay = Math.min(baseDelayMs * 2 ** (attempt - 1), SETTLE_MAX_DELAY_MS);
2654
2655
  await new Promise((resolve) => setTimeout(resolve, delay));
2655
2656
  }
2657
+ const ReleaseAssetSchema = z.object({
2658
+ id: z.number(),
2659
+ name: z.string()
2660
+ });
2661
+ z.object({
2662
+ id: z.number(),
2663
+ assets: z.array(ReleaseAssetSchema).nullish()
2664
+ });
2656
2665
  z.looseObject({
2657
2666
  id: z.number(),
2658
2667
  tag_name: z.string(),
@@ -3347,7 +3356,7 @@ function readActionsJobLog(text) {
3347
3356
  lines
3348
3357
  };
3349
3358
  }
3350
- // src/ci-log.ts
3359
+ // src/ci/ci-log.ts
3351
3360
  const ACTIONS_RUN_URL = /\/actions\/runs\/(\d+)\/?(?:[?#]|$)/u;
3352
3361
  function parseCiLogTarget(target) {
3353
3362
  if (/^\d+$/.test(target)) return {
@@ -3492,7 +3501,7 @@ const ciLogCommand = defineCommand({
3492
3501
  out.text(renderCiLog(result));
3493
3502
  }
3494
3503
  });
3495
- // src/ci-runs.ts
3504
+ // src/ci/ci-runs.ts
3496
3505
  function resolveRunsRef(ref, pr) {
3497
3506
  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).");
3498
3507
  if (pr !== void 0) {
@@ -3660,7 +3669,7 @@ function parseInputs(raw) {
3660
3669
  }
3661
3670
  return inputs;
3662
3671
  }
3663
- // src/workflow-dispatch.ts
3672
+ // src/ci/workflow-dispatch.ts
3664
3673
  async function runWorkflowDispatch(fetcher, options) {
3665
3674
  const dispatched = await dispatchWorkflow(fetcher, requireForgejoTarget(options.cwd, void 0, "workflow:dispatch is Forgejo-only -- use gh workflow run on GitHub."), {
3666
3675
  ...options.repo === void 0 ? {} : { repository: options.repo },
@@ -3677,7 +3686,7 @@ async function runWorkflowDispatch(fetcher, options) {
3677
3686
  inputs: dispatched.inputs
3678
3687
  };
3679
3688
  }
3680
- // src/registry-actions.ts
3689
+ // src/registry/registry-actions.ts
3681
3690
  const actionsSubCommands = {
3682
3691
  "ci:log": ciLogCommand,
3683
3692
  "ci:runs": ciRunsCommand,
@@ -3851,7 +3860,7 @@ function renderBranchList(listing) {
3851
3860
  if (listing.truncated) lines.push("Listing truncated at the page cap; more branches exist.");
3852
3861
  return lines.join("\n");
3853
3862
  }
3854
- // src/registry-branch.ts
3863
+ // src/registry/registry-branch.ts
3855
3864
  const branchSubCommands = {
3856
3865
  "branch:delete": defineCommand({
3857
3866
  meta: {
@@ -4065,6 +4074,7 @@ async function findOpenPr(executor, conn, head, signal = null) {
4065
4074
  const PullListItemSchema = z.object({
4066
4075
  number: z.number(),
4067
4076
  title: z.string().nullish(),
4077
+ body: z.string().nullish(),
4068
4078
  head: z.object({
4069
4079
  ref: z.string(),
4070
4080
  repo: z.object({ full_name: z.string() }).nullish()
@@ -4112,6 +4122,7 @@ async function listPulls(executor, conn, options = {}) {
4112
4122
  const items = parsed.data.map((pr) => ({
4113
4123
  number: pr.number,
4114
4124
  title: pr.title ?? null,
4125
+ body: pr.body ?? null,
4115
4126
  headRef: pr.head.ref,
4116
4127
  headRepo: pr.head.repo?.full_name ?? null,
4117
4128
  baseRef: pr.base?.ref ?? null,
@@ -4191,8 +4202,13 @@ const PrDetailSchema = z.object({
4191
4202
  draft: z.boolean(),
4192
4203
  merged: z.boolean(),
4193
4204
  mergeable: z.boolean().nullish(),
4205
+ merge_commit_sha: z.string().nullish(),
4194
4206
  state: z.string()
4195
4207
  });
4208
+ const MERGE_COMMIT_SHA = /^[0-9a-f]{7,64}$/;
4209
+ function isMergeCommitSha(value) {
4210
+ return value !== void 0 && value !== null && MERGE_COMMIT_SHA.test(value);
4211
+ }
4196
4212
  function normalizePrDetail(data) {
4197
4213
  return {
4198
4214
  head: {
@@ -4208,6 +4224,7 @@ function normalizePrDetail(data) {
4208
4224
  draft: data.draft,
4209
4225
  merged: data.merged,
4210
4226
  mergeable: data.mergeable ?? null,
4227
+ mergeCommitSha: isMergeCommitSha(data.merge_commit_sha) ? data.merge_commit_sha : null,
4211
4228
  state: data.state
4212
4229
  };
4213
4230
  }
@@ -4252,6 +4269,21 @@ async function retargetPr(executor, conn, prNumber, base) {
4252
4269
  resource: `#${String(prNumber)}`
4253
4270
  });
4254
4271
  }
4272
+ async function reopenPr(executor, conn, prNumber) {
4273
+ const url = `${conn.serverUrl}/api/v1/repos/${conn.repository}/pulls/${String(prNumber)}`;
4274
+ const res = await executor.fetch(url, {
4275
+ method: "PATCH",
4276
+ headers: {
4277
+ Authorization: `token ${conn.token}`,
4278
+ "Content-Type": "application/json"
4279
+ },
4280
+ body: JSON.stringify({ state: "open" })
4281
+ }, { idempotent: true });
4282
+ if (!res.ok) await throwForgejoFailure(res, {
4283
+ verb: "reopen PR",
4284
+ resource: `#${String(prNumber)}`
4285
+ });
4286
+ }
4255
4287
  const PrContentSchema = z.object({
4256
4288
  title: z.string(),
4257
4289
  body: z.string().nullish()
@@ -4641,7 +4673,7 @@ function forgejoIssueTransport(cwd, target, command) {
4641
4673
  target: resolved.target
4642
4674
  };
4643
4675
  }
4644
- // src/commands/issue-comment.ts
4676
+ // src/commands/issue/issue-comment.ts
4645
4677
  const issueCommentCommand = defineCommand({
4646
4678
  meta: {
4647
4679
  name: "issue:comment",
@@ -4699,7 +4731,7 @@ const issueCommentCommand = defineCommand({
4699
4731
  }
4700
4732
  }
4701
4733
  });
4702
- // src/commands/issue-create.ts
4734
+ // src/commands/issue/issue-create.ts
4703
4735
  const issueCreateCommand = defineCommand({
4704
4736
  meta: {
4705
4737
  name: "issue:create",
@@ -4865,7 +4897,7 @@ function formatDownload(result, dryRun) {
4865
4897
  for (const file of result.files) lines.push(` ${file.name} (${String(file.size)} bytes)`);
4866
4898
  return lines.join("\n");
4867
4899
  }
4868
- // src/commands/issue-download.ts
4900
+ // src/commands/issue/issue-download.ts
4869
4901
  const issueDownloadCommand = defineCommand({
4870
4902
  meta: {
4871
4903
  name: "issue:download",
@@ -5044,7 +5076,7 @@ function formatIssueSetLabels(result, dryRun) {
5044
5076
  if (result.added.length > 0) lines.push(` ${dryRun ? "would add" : "added"}: ${result.added.join(", ")}`);
5045
5077
  return lines.join("\n");
5046
5078
  }
5047
- // src/commands/issue-label.ts
5079
+ // src/commands/issue/issue-label.ts
5048
5080
  function defineIssueLabelCommand(action) {
5049
5081
  const name = action === "add" ? "issue:label" : "issue:unlabel";
5050
5082
  return defineCommand({
@@ -5103,7 +5135,7 @@ function defineIssueLabelCommand(action) {
5103
5135
  }
5104
5136
  const issueLabelCommand = defineIssueLabelCommand("add");
5105
5137
  const issueUnlabelCommand = defineIssueLabelCommand("remove");
5106
- // src/commands/issue-set-labels.ts
5138
+ // src/commands/issue/issue-set-labels.ts
5107
5139
  const issueSetLabelsCommand = defineCommand({
5108
5140
  meta: {
5109
5141
  name: "issue:set-labels",
@@ -5259,7 +5291,7 @@ function formatIssueState(result, dryRun) {
5259
5291
  }
5260
5292
  return lines.join("\n");
5261
5293
  }
5262
- // src/commands/issue-state.ts
5294
+ // src/commands/issue/issue-state.ts
5263
5295
  function defineIssueStateCommand(action) {
5264
5296
  const name = action === "close" ? "issue:close" : "issue:reopen";
5265
5297
  return defineCommand({
@@ -5322,7 +5354,7 @@ function defineIssueStateCommand(action) {
5322
5354
  if (error instanceof IssueNumberRequiredError) throw new FatalError(describeIssueNumberRequired(`pnpm exec bst-fj ${name} 273`));
5323
5355
  if (error instanceof EmptyCommentError) throw new FatalError(describeEmptyComment(flags));
5324
5356
  if (error instanceof PullRequestStateError) {
5325
- const advice = action === "close" ? `Run \`pnpm exec bst-fj pr:close ${String(error.number)}\` to close it.` : "Use the forge UI to change a pull request's state.";
5357
+ 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.`;
5326
5358
  throw new FatalError(describePullRequestState(error, {
5327
5359
  command: `bst-fj ${name}`,
5328
5360
  advice
@@ -5335,7 +5367,7 @@ function defineIssueStateCommand(action) {
5335
5367
  }
5336
5368
  const issueCloseCommand = defineIssueStateCommand("close");
5337
5369
  const issueReopenCommand = defineIssueStateCommand("reopen");
5338
- // src/commands/issue-list.ts
5370
+ // src/commands/issue/issue-list.ts
5339
5371
  const issueListCommand = defineCommand({
5340
5372
  meta: {
5341
5373
  name: "issue:list",
@@ -5393,7 +5425,7 @@ const issueListCommand = defineCommand({
5393
5425
  }
5394
5426
  }
5395
5427
  });
5396
- // src/commands/issue-update.ts
5428
+ // src/commands/issue/issue-update.ts
5397
5429
  const issueUpdateCommand = defineCommand({
5398
5430
  meta: {
5399
5431
  name: "issue:update",
@@ -5464,7 +5496,7 @@ const issueUpdateCommand = defineCommand({
5464
5496
  }
5465
5497
  }
5466
5498
  });
5467
- // src/registry-issue.ts
5499
+ // src/registry/registry-issue.ts
5468
5500
  const issueSubCommands = {
5469
5501
  "issue:view": defineCommand({
5470
5502
  meta: {
@@ -5517,7 +5549,7 @@ const issueSubCommands = {
5517
5549
  "issue:set-labels": issueSetLabelsCommand,
5518
5550
  "issue:download": issueDownloadCommand
5519
5551
  };
5520
- // src/pr-checks.ts
5552
+ // src/pr/pr-checks.ts
5521
5553
  async function resolvePrChecksTarget(fetcher, options) {
5522
5554
  const ref = parseIssueRef(options.pr);
5523
5555
  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.");
@@ -5691,7 +5723,7 @@ function renderPrChecks(report) {
5691
5723
  lines.push(summaryParts.join(" -- "));
5692
5724
  return lines.join("\n");
5693
5725
  }
5694
- // src/commands/pr-checks.ts
5726
+ // src/commands/pr/pr-checks.ts
5695
5727
  const prChecksCommand = defineCommand({
5696
5728
  meta: {
5697
5729
  name: "pr:checks",
@@ -5778,7 +5810,7 @@ function parsePrNumber(raw) {
5778
5810
  if (!/^\d+$/.test(raw) || !Number.isSafeInteger(value) || value < 1) throw new FatalError(`Invalid pull request number "${raw}" (expected a positive integer).`);
5779
5811
  return value;
5780
5812
  }
5781
- // src/commands/pr-close.ts
5813
+ // src/commands/pr/pr-close.ts
5782
5814
  const prCloseCommand = defineCommand({
5783
5815
  meta: {
5784
5816
  name: "pr:close",
@@ -6308,7 +6340,8 @@ function forgejoPrEditHost(fetcher, conn) {
6308
6340
  readLive: (number) => getPrEditState(fetcher, conn, number),
6309
6341
  branchExists: (name) => branchExists(fetcher, conn, name),
6310
6342
  setBase: (number, base) => retargetPr(fetcher, conn, number, base),
6311
- ready: (number, write) => updatePr(fetcher, conn, number, { title: write.title })
6343
+ ready: (number, write) => updatePr(fetcher, conn, number, { title: write.title }),
6344
+ reopen: (number) => reopenPr(fetcher, conn, number)
6312
6345
  };
6313
6346
  }
6314
6347
  // src/git.ts
@@ -6387,7 +6420,7 @@ function cliGit() {
6387
6420
  });
6388
6421
  }) };
6389
6422
  }
6390
- // src/pr-run.ts
6423
+ // src/pr/pr-run.ts
6391
6424
  const COMMANDS = {
6392
6425
  create: "pnpm exec bst-fj pr:create",
6393
6426
  update: "pnpm exec bst-fj pr:update"
@@ -6421,7 +6454,7 @@ async function runForgejoPr(githubRefusal, options) {
6421
6454
  });
6422
6455
  }
6423
6456
  }
6424
- // src/commands/pr-create.ts
6457
+ // src/commands/pr/pr-create.ts
6425
6458
  const prCreateCommand = defineCommand({
6426
6459
  meta: {
6427
6460
  name: "pr:create",
@@ -6540,7 +6573,7 @@ async function readPrFilesPage(executor, conn, prNumber, page, limit) {
6540
6573
  truncated: res.headers.get("x-hasmore") === "true"
6541
6574
  };
6542
6575
  }
6543
- // src/pr-files.ts
6576
+ // src/pr/pr-files.ts
6544
6577
  function runPrFiles(fetcher, options) {
6545
6578
  const number = parsePrNumber(options.number);
6546
6579
  return listAllPrFiles(fetcher, requireForgejoTarget(options.cwd, parseRepoTarget(options.repo), "pr:files is Forgejo-only -- gh pr diff --name-only already serves GitHub."), number);
@@ -6551,7 +6584,7 @@ function renderPrFiles(listing) {
6551
6584
  if (listing.truncated) lines.push("Listing truncated; the pull request changes more files.");
6552
6585
  return lines.join("\n");
6553
6586
  }
6554
- // src/commands/pr-files.ts
6587
+ // src/commands/pr/pr-files.ts
6555
6588
  const prFilesCommand = defineCommand({
6556
6589
  meta: {
6557
6590
  name: "pr:files",
@@ -6590,7 +6623,7 @@ const prFilesCommand = defineCommand({
6590
6623
  out.text(renderPrFiles(listing));
6591
6624
  }
6592
6625
  });
6593
- // src/pr-list.ts
6626
+ // src/pr/pr-list.ts
6594
6627
  function parseState(state) {
6595
6628
  if (state === "open" || state === "closed" || state === "all") return state;
6596
6629
  throw new FatalError(`Invalid --state "${state}" (expected open, closed, or all).`);
@@ -6627,7 +6660,7 @@ function renderPrList(result) {
6627
6660
  return `#${String(pr.number)} ${statusLabel(pr)} ${branches}: ${pr.title ?? "(no title)"}${labels}${url}`;
6628
6661
  }).join("\n");
6629
6662
  }
6630
- // src/commands/pr-list.ts
6663
+ // src/commands/pr/pr-list.ts
6631
6664
  const prListCommand = defineCommand({
6632
6665
  meta: {
6633
6666
  name: "pr:list",
@@ -6844,7 +6877,7 @@ async function runPrMergeCore(fetcher, conn, number, options = {}) {
6844
6877
  }
6845
6878
  };
6846
6879
  }
6847
- // src/pr-merge.ts
6880
+ // src/pr/pr-merge.ts
6848
6881
  function parseMethod(raw) {
6849
6882
  if (raw === void 0) return "merge";
6850
6883
  const method = MERGE_METHODS.find((candidate) => candidate === raw);
@@ -6871,7 +6904,7 @@ function renderPrMerge(result) {
6871
6904
  const what = `PR #${String(result.number)} (${result.method}) at ${result.headSha.slice(0, 12)}, checks ${result.checks}`;
6872
6905
  return result.merged ? `Merged ${what}.` : `Dry run: would merge ${what}.`;
6873
6906
  }
6874
- // src/commands/pr-merge.ts
6907
+ // src/commands/pr/pr-merge.ts
6875
6908
  const prMergeCommand = defineCommand({
6876
6909
  meta: {
6877
6910
  name: "pr:merge",
@@ -6933,8 +6966,9 @@ function isOpen(live) {
6933
6966
  return live.state === "open" && live.merged === false;
6934
6967
  }
6935
6968
  function notOpenMessage(prNumber, live) {
6936
- const what = live.merged ? "merged" : live.state;
6937
- return `Pull request #${String(prNumber)} is ${what}, so it has no base or draft state left to change. Reopen it first if this work is still live.`;
6969
+ const number = `#${String(prNumber)}`;
6970
+ if (live.merged) return `Pull request ${number} is merged, so it has no base or draft state left to change.`;
6971
+ 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.`;
6938
6972
  }
6939
6973
  async function runPrRetarget(host, options) {
6940
6974
  const live = await host.readLive(options.number);
@@ -7030,8 +7064,47 @@ async function runPrReady(host, options) {
7030
7064
  dryRun: false
7031
7065
  };
7032
7066
  }
7067
+ async function runPrReopen(host, options) {
7068
+ const live = await host.readLive(options.number);
7069
+ 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.`);
7070
+ if (live.state === "open") return {
7071
+ action: "already-open",
7072
+ number: options.number,
7073
+ url: live.url,
7074
+ title: live.title,
7075
+ head: live.head,
7076
+ base: live.base,
7077
+ draft: live.draft,
7078
+ dryRun: options.dryRun
7079
+ };
7080
+ 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.`);
7081
+ if (options.dryRun) return {
7082
+ action: "would-reopen",
7083
+ number: options.number,
7084
+ url: live.url,
7085
+ title: live.title,
7086
+ head: live.head,
7087
+ base: live.base,
7088
+ draft: live.draft,
7089
+ dryRun: true
7090
+ };
7091
+ await host.reopen(options.number);
7092
+ const recheck = await host.readLive(options.number);
7093
+ 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.`);
7094
+ return {
7095
+ action: "reopened",
7096
+ number: options.number,
7097
+ url: recheck.url,
7098
+ title: recheck.title,
7099
+ head: recheck.head,
7100
+ base: recheck.base,
7101
+ draft: recheck.draft,
7102
+ dryRun: false
7103
+ };
7104
+ }
7033
7105
  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.";
7034
7106
  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.";
7107
+ 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.";
7035
7108
  function mergeabilityLine(mergeable) {
7036
7109
  if (mergeable === true) return "Mergeability: mergeable.";
7037
7110
  if (mergeable === false) return "Mergeability: not mergeable -- advice, not a verdict.";
@@ -7054,7 +7127,17 @@ function renderPrReady(result) {
7054
7127
  if (result.action === "would-ready") return `Dry run: pull request ${number} would stop being a draft, reading "${result.title}".`;
7055
7128
  return `Dry run: pull request ${number} would read "${result.title}".`;
7056
7129
  }
7057
- // src/registry-pr.ts
7130
+ function renderPrReopen(result) {
7131
+ const number = `#${String(result.number)}`;
7132
+ if (result.action === "reopened") {
7133
+ const lines = [`Pull request ${number} is open again (head "${result.head}" -> "${result.base}").`];
7134
+ if (result.draft) lines.push(`It is still a draft -- run pr:ready ${String(result.number)} when it is ready for review.`);
7135
+ return lines.join("\n");
7136
+ }
7137
+ if (result.action === "already-open") return `Pull request ${number} is already open.`;
7138
+ return `Dry run: pull request ${number} would be reopened.`;
7139
+ }
7140
+ // src/registry/registry-pr.ts
7058
7141
  const prSubCommands = {
7059
7142
  "pr:checks": prChecksCommand,
7060
7143
  "pr:close": prCloseCommand,
@@ -7106,6 +7189,47 @@ const prSubCommands = {
7106
7189
  out.text(renderPrReady(result));
7107
7190
  }
7108
7191
  }),
7192
+ "pr:reopen": defineCommand({
7193
+ meta: {
7194
+ name: "pr:reopen",
7195
+ 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)"
7196
+ },
7197
+ args: {
7198
+ number: {
7199
+ type: "positional",
7200
+ required: true,
7201
+ description: "Pull request number"
7202
+ },
7203
+ repo: {
7204
+ type: "string",
7205
+ description: "Repository URL (default: this repo)"
7206
+ },
7207
+ "dry-run": {
7208
+ type: "boolean",
7209
+ description: "Run every read and report, but do not write"
7210
+ },
7211
+ json: {
7212
+ type: "boolean",
7213
+ description: PR_REOPEN_JSON_HELP
7214
+ },
7215
+ verbose: {
7216
+ type: "boolean",
7217
+ description: "Emit detailed debug output"
7218
+ }
7219
+ },
7220
+ async run({ args }) {
7221
+ const out = createCliOutput(args.json === true);
7222
+ const conn = requireForgejoTargetFromRepo(process.cwd(), args.repo ?? void 0, "pr:reopen is Forgejo-only -- use gh pr reopen <n> on GitHub.");
7223
+ const number = parsePrNumber(args.number);
7224
+ 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.`);
7225
+ const result = await runPrReopen(forgejoPrEditHost(cliFetcher(), conn), {
7226
+ number,
7227
+ dryRun: args["dry-run"] === true
7228
+ });
7229
+ out.json(result);
7230
+ out.text(renderPrReopen(result));
7231
+ }
7232
+ }),
7109
7233
  "pr:retarget": defineCommand({
7110
7234
  meta: {
7111
7235
  name: "pr:retarget",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bensandee/forgejo-cli",
3
- "version": "0.7.0",
3
+ "version": "0.9.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.1"
38
+ "tsdown": "0.23.4"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "tsdown",