@bensandee/forgejo-cli 0.6.2 → 0.7.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/bin.mjs +77 -18
- package/package.json +1 -1
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.7.0",
|
|
164
164
|
description: "bst-fj: Forgejo API commands without the rest of bst",
|
|
165
165
|
license: "MIT",
|
|
166
166
|
repository: {
|
|
@@ -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) });
|
|
@@ -1696,6 +1697,15 @@ function carryForwardClosingRefs(source, target) {
|
|
|
1696
1697
|
const refLines = missing.map((ref) => ref.text).join("\n");
|
|
1697
1698
|
return target.trim() === "" ? refLines : `${target}\n\n${refLines}`;
|
|
1698
1699
|
}
|
|
1700
|
+
function parseIssueList(value) {
|
|
1701
|
+
const numbers = /* @__PURE__ */ new Set();
|
|
1702
|
+
for (const part of value.split(",")) {
|
|
1703
|
+
const match = /^#?([1-9]\d*)$/.exec(part.trim());
|
|
1704
|
+
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)}.`);
|
|
1705
|
+
numbers.add(Number(match[1]));
|
|
1706
|
+
}
|
|
1707
|
+
return [...numbers];
|
|
1708
|
+
}
|
|
1699
1709
|
// ../forgejo/src/fetcher.ts
|
|
1700
1710
|
const LONG_FETCH_TIMEOUT_MS = 6e5;
|
|
1701
1711
|
function morePagesFollow(res, pageLength, received, pageSize) {
|
|
@@ -4293,6 +4303,7 @@ const PullReviewCommentSchema = z.object({
|
|
|
4293
4303
|
user: z.object({ login: z.string() }).nullish()
|
|
4294
4304
|
});
|
|
4295
4305
|
z.array(PullReviewCommentSchema);
|
|
4306
|
+
z.array(z.object({ id: z.number() }));
|
|
4296
4307
|
// ../forgejo/src/issue-api.ts
|
|
4297
4308
|
var IssueNumberRequiredError = class extends FatalError {
|
|
4298
4309
|
constructor() {
|
|
@@ -6078,7 +6089,51 @@ function checkClosingLinks(messages, plan, allowUnlink) {
|
|
|
6078
6089
|
unlinked
|
|
6079
6090
|
};
|
|
6080
6091
|
}
|
|
6092
|
+
function addClosingIssues(plan, issues) {
|
|
6093
|
+
const wanted = issues.map((issue) => `Closes #${String(issue)}`).join("\n");
|
|
6094
|
+
const added = droppedClosingRefs([wanted], plan.effective.body).map((ref) => Number(ref.issue.slice(1)));
|
|
6095
|
+
if (added.length === 0) return {
|
|
6096
|
+
plan,
|
|
6097
|
+
added
|
|
6098
|
+
};
|
|
6099
|
+
const body = carryForwardClosingRefs(wanted, plan.effective.body);
|
|
6100
|
+
return {
|
|
6101
|
+
plan: {
|
|
6102
|
+
...plan,
|
|
6103
|
+
patch: {
|
|
6104
|
+
...plan.patch,
|
|
6105
|
+
body
|
|
6106
|
+
},
|
|
6107
|
+
effective: {
|
|
6108
|
+
...plan.effective,
|
|
6109
|
+
body
|
|
6110
|
+
}
|
|
6111
|
+
},
|
|
6112
|
+
added
|
|
6113
|
+
};
|
|
6114
|
+
}
|
|
6081
6115
|
const ALWAYS_PROTECTED = /* @__PURE__ */ new Set(["main", "master"]);
|
|
6116
|
+
async function planUpsert(host, existing, derived, options) {
|
|
6117
|
+
let plan;
|
|
6118
|
+
if (existing === null) plan = {
|
|
6119
|
+
patch: {
|
|
6120
|
+
title: derived.title,
|
|
6121
|
+
body: derived.body
|
|
6122
|
+
},
|
|
6123
|
+
effective: derived,
|
|
6124
|
+
previousBody: null
|
|
6125
|
+
};
|
|
6126
|
+
else plan = planPrUpdate(options, derived, prUpdateNeedsLive(options) ? await host.readLive(existing, options.signal ?? null) : null, host.wipTitles);
|
|
6127
|
+
if (options.closes === void 0) return {
|
|
6128
|
+
plan,
|
|
6129
|
+
closesAdded: void 0
|
|
6130
|
+
};
|
|
6131
|
+
const linked = addClosingIssues(plan, options.closes);
|
|
6132
|
+
return {
|
|
6133
|
+
plan: linked.plan,
|
|
6134
|
+
closesAdded: linked.added
|
|
6135
|
+
};
|
|
6136
|
+
}
|
|
6082
6137
|
async function runPrUpsert(git, host, options) {
|
|
6083
6138
|
const { cwd } = options;
|
|
6084
6139
|
const mode = options.mode ?? "upsert";
|
|
@@ -6111,22 +6166,14 @@ async function runPrUpsert(git, host, options) {
|
|
|
6111
6166
|
const existing = open?.number ?? null;
|
|
6112
6167
|
assertModeAllows(mode, existing, branch);
|
|
6113
6168
|
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);
|
|
6169
|
+
const { plan, closesAdded } = await planUpsert(host, existing, derived, options);
|
|
6124
6170
|
const report = checkClosingLinks(messages, plan, options.allowUnlink === true);
|
|
6125
6171
|
options.onClosingLinks?.(report);
|
|
6126
6172
|
const shape = {
|
|
6127
6173
|
branch,
|
|
6128
6174
|
base: open?.base ?? localBase,
|
|
6129
|
-
...plan.effective
|
|
6175
|
+
...plan.effective,
|
|
6176
|
+
...closesAdded === void 0 ? {} : { closesAdded }
|
|
6130
6177
|
};
|
|
6131
6178
|
if (options.dryRun) return {
|
|
6132
6179
|
action: existing === null ? "would-create" : "would-update",
|
|
@@ -6162,7 +6209,7 @@ function describeClosingLinks(report, flags) {
|
|
|
6162
6209
|
const lines = [];
|
|
6163
6210
|
if (report.fromCommits.length > 0) {
|
|
6164
6211
|
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.
|
|
6212
|
+
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
6213
|
}
|
|
6167
6214
|
if (report.unlinked.length > 0) {
|
|
6168
6215
|
const lost = report.unlinked.map((dropped) => dropped.text).join(", ");
|
|
@@ -6214,15 +6261,17 @@ function formatPrCreate(result) {
|
|
|
6214
6261
|
};
|
|
6215
6262
|
}
|
|
6216
6263
|
function formatPrUpdate(result, rewrites, flags) {
|
|
6264
|
+
const added = result.closesAdded ?? [];
|
|
6217
6265
|
if (isDryRun(result)) return {
|
|
6218
6266
|
lines: [`[dry-run] Would push ${prTarget(result)} to ${prLabel(result)}`],
|
|
6219
6267
|
body: {
|
|
6220
|
-
heading: rewrites ? "[dry-run] Body" : "[dry-run] Body (unchanged)",
|
|
6268
|
+
heading: rewrites || added.length > 0 ? "[dry-run] Body" : "[dry-run] Body (unchanged)",
|
|
6221
6269
|
text: result.body
|
|
6222
6270
|
}
|
|
6223
6271
|
};
|
|
6224
6272
|
const lines = [`Updated ${prLabel(result)} (${prTarget(result)})`];
|
|
6225
|
-
if (
|
|
6273
|
+
if (added.length > 0) lines.push(`Linked ${added.map((issue) => `#${String(issue)}`).join(", ")} with a Closes line.`);
|
|
6274
|
+
else if (!rewrites) lines.push(`Title and body left as authored -- pass ${flags.title}/${flags.body} to change them.`);
|
|
6226
6275
|
if (result.url !== null) lines.push(result.url);
|
|
6227
6276
|
return {
|
|
6228
6277
|
lines,
|
|
@@ -6344,7 +6393,7 @@ const COMMANDS = {
|
|
|
6344
6393
|
update: "pnpm exec bst-fj pr:update"
|
|
6345
6394
|
};
|
|
6346
6395
|
const FLAGS = {
|
|
6347
|
-
|
|
6396
|
+
closes: "--closes",
|
|
6348
6397
|
allowUnlink: "--allow-unlink"
|
|
6349
6398
|
};
|
|
6350
6399
|
function warnClosingLinks(report) {
|
|
@@ -6407,13 +6456,17 @@ const prCreateCommand = defineCommand({
|
|
|
6407
6456
|
type: "boolean",
|
|
6408
6457
|
description: "With --upsert: permit a --body that drops a closing keyword the PR carries"
|
|
6409
6458
|
},
|
|
6459
|
+
closes: {
|
|
6460
|
+
type: "string",
|
|
6461
|
+
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"
|
|
6462
|
+
},
|
|
6410
6463
|
"dry-run": {
|
|
6411
6464
|
type: "boolean",
|
|
6412
6465
|
description: "Show what would happen without pushing"
|
|
6413
6466
|
},
|
|
6414
6467
|
json: {
|
|
6415
6468
|
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."
|
|
6469
|
+
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
6470
|
},
|
|
6418
6471
|
verbose: {
|
|
6419
6472
|
type: "boolean",
|
|
@@ -6429,6 +6482,7 @@ const prCreateCommand = defineCommand({
|
|
|
6429
6482
|
body,
|
|
6430
6483
|
base: args.base ?? void 0,
|
|
6431
6484
|
allowUnlink: args["allow-unlink"] === true,
|
|
6485
|
+
closes: args.closes === void 0 ? void 0 : parseIssueList(args.closes),
|
|
6432
6486
|
draft: args.draft === true ? true : void 0,
|
|
6433
6487
|
dryRun: args["dry-run"] === true
|
|
6434
6488
|
});
|
|
@@ -7125,13 +7179,17 @@ const prSubCommands = {
|
|
|
7125
7179
|
type: "boolean",
|
|
7126
7180
|
description: "Permit a --body that drops a closing keyword the current body carries"
|
|
7127
7181
|
},
|
|
7182
|
+
closes: {
|
|
7183
|
+
type: "string",
|
|
7184
|
+
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"
|
|
7185
|
+
},
|
|
7128
7186
|
"dry-run": {
|
|
7129
7187
|
type: "boolean",
|
|
7130
7188
|
description: "Show what would happen without pushing"
|
|
7131
7189
|
},
|
|
7132
7190
|
json: {
|
|
7133
7191
|
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."
|
|
7192
|
+
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
7193
|
},
|
|
7136
7194
|
verbose: {
|
|
7137
7195
|
type: "boolean",
|
|
@@ -7148,6 +7206,7 @@ const prSubCommands = {
|
|
|
7148
7206
|
body,
|
|
7149
7207
|
base: args.base ?? void 0,
|
|
7150
7208
|
allowUnlink: args["allow-unlink"] === true,
|
|
7209
|
+
closes: args.closes === void 0 ? void 0 : parseIssueList(args.closes),
|
|
7151
7210
|
draft: void 0,
|
|
7152
7211
|
dryRun: args["dry-run"] === true
|
|
7153
7212
|
});
|