@bensandee/forgejo-cli 0.6.0 → 0.6.1
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 +107 -199
- package/package.json +1 -1
package/dist/bin.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { FatalError, TransientError, UnexpectedError, describeError, redact, red
|
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { defineCommand, renderUsage, runCommand, runMain } from "citty";
|
|
8
8
|
import { execFileSync, spawn } from "node:child_process";
|
|
9
|
-
|
|
9
|
+
// ../cli-kit/src/json.ts
|
|
10
10
|
function resolveJsonMode(rawArgs) {
|
|
11
11
|
if (!rawArgs.some(requestsJson)) return false;
|
|
12
12
|
if (rawArgs.includes("--help") || rawArgs.includes("-h")) return false;
|
|
@@ -100,8 +100,7 @@ function classifyThrown(error, verbose) {
|
|
|
100
100
|
detail
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
|
|
104
|
-
//#region ../cli-kit/src/env-file.ts
|
|
103
|
+
// ../cli-kit/src/env-file.ts
|
|
105
104
|
const ENV_FILE_VAR = "BST_ENV_FILE";
|
|
106
105
|
function loadEnvFileFromEnv() {
|
|
107
106
|
const raw = process.env[ENV_FILE_VAR]?.trim();
|
|
@@ -158,11 +157,10 @@ function loadEnvFileForBin(rawArgs, bin, io = processIo) {
|
|
|
158
157
|
return io.exit(1);
|
|
159
158
|
}
|
|
160
159
|
}
|
|
161
|
-
|
|
162
|
-
//#region src/version.ts
|
|
160
|
+
// src/version.ts
|
|
163
161
|
const parsed = z.object({ version: z.string() }).safeParse({
|
|
164
162
|
name: "@bensandee/forgejo-cli",
|
|
165
|
-
version: "0.6.
|
|
163
|
+
version: "0.6.1",
|
|
166
164
|
description: "bst-fj: Forgejo API commands without the rest of bst",
|
|
167
165
|
license: "MIT",
|
|
168
166
|
repository: {
|
|
@@ -203,14 +201,12 @@ const parsed = z.object({ version: z.string() }).safeParse({
|
|
|
203
201
|
});
|
|
204
202
|
if (!parsed.success) throw new UnexpectedError(`@bensandee/forgejo-cli's package.json has no string version.`);
|
|
205
203
|
const BST_FJ_VERSION = parsed.data.version;
|
|
206
|
-
|
|
207
|
-
//#region src/env-file-preload.ts
|
|
204
|
+
// src/env-file-preload.ts
|
|
208
205
|
const envFileLoad = loadEnvFileForBin(process.argv.slice(2), {
|
|
209
206
|
name: "bst-fj",
|
|
210
207
|
version: BST_FJ_VERSION
|
|
211
208
|
});
|
|
212
|
-
|
|
213
|
-
//#region ../cli-kit/src/logger.ts
|
|
209
|
+
// ../cli-kit/src/logger.ts
|
|
214
210
|
const RANK = {
|
|
215
211
|
error: 0,
|
|
216
212
|
warn: 1,
|
|
@@ -310,8 +306,7 @@ function createLogger(options = {}) {
|
|
|
310
306
|
});
|
|
311
307
|
}
|
|
312
308
|
const rootLogger = createLogger();
|
|
313
|
-
|
|
314
|
-
//#region ../cli-kit/src/flags.ts
|
|
309
|
+
// ../cli-kit/src/flags.ts
|
|
315
310
|
const UNIVERSAL_FLAGS = [
|
|
316
311
|
"--help",
|
|
317
312
|
"-h",
|
|
@@ -648,8 +643,7 @@ function parseLimitFlag(raw) {
|
|
|
648
643
|
if (!Number.isInteger(value) || value < 1) throw new FatalError(`--limit must be a positive integer, got "${raw}"`);
|
|
649
644
|
return value;
|
|
650
645
|
}
|
|
651
|
-
|
|
652
|
-
//#region ../cli-kit/src/output.ts
|
|
646
|
+
// ../cli-kit/src/output.ts
|
|
653
647
|
const stdout = (msg) => console.log(msg);
|
|
654
648
|
function initialState() {
|
|
655
649
|
return {
|
|
@@ -712,8 +706,7 @@ function flushJsonOutput() {
|
|
|
712
706
|
function jsonDocumentWritten() {
|
|
713
707
|
return state.wrote;
|
|
714
708
|
}
|
|
715
|
-
|
|
716
|
-
//#region ../cli-kit/src/path-probe.ts
|
|
709
|
+
// ../cli-kit/src/path-probe.ts
|
|
717
710
|
function probeCliPath(value) {
|
|
718
711
|
try {
|
|
719
712
|
const stat = statSync(value, { throwIfNoEntry: false });
|
|
@@ -723,8 +716,7 @@ function probeCliPath(value) {
|
|
|
723
716
|
return "missing";
|
|
724
717
|
}
|
|
725
718
|
}
|
|
726
|
-
|
|
727
|
-
//#region ../cli-kit/src/run.ts
|
|
719
|
+
// ../cli-kit/src/run.ts
|
|
728
720
|
function classifyWithHook(error, verbose, hook) {
|
|
729
721
|
const classified = classifyThrown(error, verbose);
|
|
730
722
|
const worded = hook?.(error);
|
|
@@ -878,8 +870,7 @@ const log = {
|
|
|
878
870
|
current.debug(message);
|
|
879
871
|
}
|
|
880
872
|
};
|
|
881
|
-
|
|
882
|
-
//#region ../forgejo/src/connection.ts
|
|
873
|
+
// ../forgejo/src/connection.ts
|
|
883
874
|
function parseGitUrl(urlStr) {
|
|
884
875
|
try {
|
|
885
876
|
const url = new URL(urlStr);
|
|
@@ -1006,14 +997,12 @@ function normalizeGitUrl(raw) {
|
|
|
1006
997
|
return null;
|
|
1007
998
|
}
|
|
1008
999
|
}
|
|
1009
|
-
|
|
1010
|
-
//#region src/describe-forge-error.ts
|
|
1000
|
+
// src/describe-forge-error.ts
|
|
1011
1001
|
function describeForgeError(error) {
|
|
1012
1002
|
if (error instanceof RepoTargetEmptyError) return "--repo was given with no repository URL (expected e.g. https://host/owner/repo).";
|
|
1013
1003
|
if (error instanceof RepoTargetMismatchError) return `--repo disagrees with the issue URL: --repo names ${error.given}, the issue URL names ${error.fromReference}.`;
|
|
1014
1004
|
}
|
|
1015
|
-
|
|
1016
|
-
//#region ../forgejo/src/fetch-retry.ts
|
|
1005
|
+
// ../forgejo/src/fetch-retry.ts
|
|
1017
1006
|
const DEFAULT_RETRY_POLICY = {
|
|
1018
1007
|
attempts: 5,
|
|
1019
1008
|
baseDelayMs: 250,
|
|
@@ -1070,13 +1059,11 @@ function fetchWithRetry(fetchImpl, policy = DEFAULT_RETRY_POLICY, defaultTimeout
|
|
|
1070
1059
|
function createForgeFetcher(policy = DEFAULT_RETRY_POLICY) {
|
|
1071
1060
|
return { fetch: fetchWithRetry((input, init) => globalThis.fetch(input, init), policy) };
|
|
1072
1061
|
}
|
|
1073
|
-
|
|
1074
|
-
//#region src/fetcher.ts
|
|
1062
|
+
// src/fetcher.ts
|
|
1075
1063
|
function cliFetcher() {
|
|
1076
1064
|
return createForgeFetcher();
|
|
1077
1065
|
}
|
|
1078
|
-
|
|
1079
|
-
//#region ../forgejo/src/errors.ts
|
|
1066
|
+
// ../forgejo/src/errors.ts
|
|
1080
1067
|
var ForgeAccessError = class extends FatalError {};
|
|
1081
1068
|
function authHeaders(conn) {
|
|
1082
1069
|
return { Authorization: `token ${conn.token}` };
|
|
@@ -1173,8 +1160,7 @@ async function throwForgejoFailure(res, operation, notFoundMessage) {
|
|
|
1173
1160
|
if (res.status === 410) throw new FatalError(`${message}\nForgejo returned 410 Gone -- issues are likely disabled on this repository; retrying will not help.`);
|
|
1174
1161
|
throw new TransientError(message);
|
|
1175
1162
|
}
|
|
1176
|
-
|
|
1177
|
-
//#region ../forgejo/src/commit-status.ts
|
|
1163
|
+
// ../forgejo/src/commit-status.ts
|
|
1178
1164
|
const CombinedStatusSchema = z.object({
|
|
1179
1165
|
state: z.string(),
|
|
1180
1166
|
statuses: z.array(z.unknown())
|
|
@@ -1318,8 +1304,7 @@ async function branchExists(executor, conn, branch) {
|
|
|
1318
1304
|
}, branchNotFoundMessage(conn, branch));
|
|
1319
1305
|
return true;
|
|
1320
1306
|
}
|
|
1321
|
-
|
|
1322
|
-
//#region ../cli-kit/src/git.ts
|
|
1307
|
+
// ../cli-kit/src/git.ts
|
|
1323
1308
|
const BRANCH_REF_PREFIX = "refs/heads/";
|
|
1324
1309
|
const ORIGIN_READ_TIMEOUT_MS = 5e3;
|
|
1325
1310
|
function defaultGitRunner(args, cwd, options) {
|
|
@@ -1382,8 +1367,7 @@ function readPackageRepositoryUrl(cwd) {
|
|
|
1382
1367
|
if (!repo) return null;
|
|
1383
1368
|
return typeof repo === "string" ? repo : repo.url;
|
|
1384
1369
|
}
|
|
1385
|
-
|
|
1386
|
-
//#region src/connection.ts
|
|
1370
|
+
// src/connection.ts
|
|
1387
1371
|
function resolveRepoUrl(cwd) {
|
|
1388
1372
|
return resolveRepoUrlFrom(() => readOriginUrl(cwd), () => readPackageRepositoryUrl(cwd));
|
|
1389
1373
|
}
|
|
@@ -1405,8 +1389,7 @@ function requireForgejoTarget(cwd, target, githubRefusal, env = process.env) {
|
|
|
1405
1389
|
if (conn === null) throw new FatalError(githubRefusal);
|
|
1406
1390
|
return conn;
|
|
1407
1391
|
}
|
|
1408
|
-
|
|
1409
|
-
//#region ../forgejo/src/check-poll.ts
|
|
1392
|
+
// ../forgejo/src/check-poll.ts
|
|
1410
1393
|
function classifyBaseStatus(checks) {
|
|
1411
1394
|
if (!checks.parsed) return "unparseable";
|
|
1412
1395
|
if (checks.contexts.length === 0) return "no-status";
|
|
@@ -1493,16 +1476,14 @@ function renderCheckLine(check) {
|
|
|
1493
1476
|
if (check.verdict === "red" && check.targetUrl !== null) line += ` (${check.targetUrl})`;
|
|
1494
1477
|
return line;
|
|
1495
1478
|
}
|
|
1496
|
-
|
|
1497
|
-
//#region ../cli-kit/src/env-override.ts
|
|
1479
|
+
// ../cli-kit/src/env-override.ts
|
|
1498
1480
|
function envMsOverride(raw, productionMs) {
|
|
1499
1481
|
if (raw === void 0) return productionMs;
|
|
1500
1482
|
const parsed = Number(raw.trim());
|
|
1501
1483
|
if (!Number.isSafeInteger(parsed) || parsed <= 0) return productionMs;
|
|
1502
1484
|
return Math.min(parsed, productionMs);
|
|
1503
1485
|
}
|
|
1504
|
-
|
|
1505
|
-
//#region src/poll-timings.ts
|
|
1486
|
+
// src/poll-timings.ts
|
|
1506
1487
|
const DEFAULT_TIMEOUT_MS = 12e5;
|
|
1507
1488
|
const DEFAULT_INTERVAL_MS = 15e3;
|
|
1508
1489
|
const MIN_INTERVAL_MS = 5e3;
|
|
@@ -1514,15 +1495,13 @@ function resolvePollTimings(options) {
|
|
|
1514
1495
|
intervalMs: envMsOverride(process.env["BST_TEST_CHECK_POLL_INTERVAL_MS"], Math.max(requestedIntervalMs, MIN_INTERVAL_MS))
|
|
1515
1496
|
};
|
|
1516
1497
|
}
|
|
1517
|
-
|
|
1518
|
-
//#region src/sleep.ts
|
|
1498
|
+
// src/sleep.ts
|
|
1519
1499
|
function sleep(ms) {
|
|
1520
1500
|
return new Promise((resolve) => {
|
|
1521
1501
|
setTimeout(resolve, ms);
|
|
1522
1502
|
});
|
|
1523
1503
|
}
|
|
1524
|
-
|
|
1525
|
-
//#region src/commit-status.ts
|
|
1504
|
+
// src/commit-status.ts
|
|
1526
1505
|
async function resolveCommitStatusTarget(fetcher, options) {
|
|
1527
1506
|
const targetRepo = parseRepoTarget(options.repo);
|
|
1528
1507
|
const conn = requireForgejoTarget(options.cwd, targetRepo, "commit:status is Forgejo-only: GitHub Actions publishes check runs, not commit statuses. Use `gh run list` / `gh run view` instead.");
|
|
@@ -1632,8 +1611,7 @@ function renderCommitStatus(report) {
|
|
|
1632
1611
|
lines.push(summaryParts.join(" -- "));
|
|
1633
1612
|
return lines.join("\n");
|
|
1634
1613
|
}
|
|
1635
|
-
|
|
1636
|
-
//#region src/commands/commit-status.ts
|
|
1614
|
+
// src/commands/commit-status.ts
|
|
1637
1615
|
const commitStatusCommand = defineCommand({
|
|
1638
1616
|
meta: {
|
|
1639
1617
|
name: "commit:status",
|
|
@@ -1687,8 +1665,7 @@ const commitStatusCommand = defineCommand({
|
|
|
1687
1665
|
process.exitCode = report.status === "green" ? 0 : 1;
|
|
1688
1666
|
}
|
|
1689
1667
|
});
|
|
1690
|
-
|
|
1691
|
-
//#region ../forgejo/src/fetcher.ts
|
|
1668
|
+
// ../forgejo/src/fetcher.ts
|
|
1692
1669
|
const LONG_FETCH_TIMEOUT_MS = 6e5;
|
|
1693
1670
|
function morePagesFollow(res, pageLength, received, pageSize) {
|
|
1694
1671
|
if (pageLength === 0) return false;
|
|
@@ -1697,8 +1674,7 @@ function morePagesFollow(res, pageLength, received, pageSize) {
|
|
|
1697
1674
|
if (!Number.isSafeInteger(total) || total < 0) return pageLength >= pageSize;
|
|
1698
1675
|
return received < total;
|
|
1699
1676
|
}
|
|
1700
|
-
|
|
1701
|
-
//#region ../forgejo/src/label-provisioning.ts
|
|
1677
|
+
// ../forgejo/src/label-provisioning.ts
|
|
1702
1678
|
const LabelSchema = z.object({
|
|
1703
1679
|
id: z.number(),
|
|
1704
1680
|
name: z.string(),
|
|
@@ -1871,8 +1847,7 @@ async function deleteForgejoLabel(executor, conn, id) {
|
|
|
1871
1847
|
resource: String(id)
|
|
1872
1848
|
}, repoNotFoundMessage(conn));
|
|
1873
1849
|
}
|
|
1874
|
-
|
|
1875
|
-
//#region ../forgejo/src/issues.ts
|
|
1850
|
+
// ../forgejo/src/issues.ts
|
|
1876
1851
|
const IssueResponseSchema = z.object({
|
|
1877
1852
|
number: z.number(),
|
|
1878
1853
|
title: z.string(),
|
|
@@ -1931,13 +1906,15 @@ const DependencyResponseSchema = z.object({
|
|
|
1931
1906
|
});
|
|
1932
1907
|
z.array(DependencyResponseSchema);
|
|
1933
1908
|
function issueListParams(type, query) {
|
|
1934
|
-
const
|
|
1909
|
+
const kind = query.type ?? type;
|
|
1910
|
+
const params = new URLSearchParams(kind === "all" ? {} : { type: kind });
|
|
1935
1911
|
params.set("state", query.state);
|
|
1936
1912
|
params.set("limit", String(query.limit));
|
|
1937
1913
|
if (query.label !== void 0) params.set("labels", query.label);
|
|
1938
1914
|
if (query.page !== void 0) params.set("page", String(query.page));
|
|
1939
1915
|
if (query.since !== void 0) params.set("since", query.since);
|
|
1940
1916
|
if (query.sort !== void 0) params.set("sort", query.sort);
|
|
1917
|
+
if (query.q !== void 0) params.set("q", query.q);
|
|
1941
1918
|
return params;
|
|
1942
1919
|
}
|
|
1943
1920
|
async function fetchIssueListPage(executor, conn, params) {
|
|
@@ -2089,8 +2066,7 @@ async function setForgejoIssueState(executor, conn, number, state) {
|
|
|
2089
2066
|
}, issueNotFoundMessage(conn, number));
|
|
2090
2067
|
return normalizeIssue(parseIssueOrThrow(await res.json()));
|
|
2091
2068
|
}
|
|
2092
|
-
|
|
2093
|
-
//#region ../forgejo/src/label-sync.ts
|
|
2069
|
+
// ../forgejo/src/label-sync.ts
|
|
2094
2070
|
function resolveSyncMode(check, dryRun) {
|
|
2095
2071
|
if (check) return "check";
|
|
2096
2072
|
if (dryRun) return "dry-run";
|
|
@@ -2264,8 +2240,7 @@ function syncSummaryLines(result) {
|
|
|
2264
2240
|
failureLines: result.failures.map((failure) => `${failure.repository}: failed: ${failure.error}`)
|
|
2265
2241
|
};
|
|
2266
2242
|
}
|
|
2267
|
-
|
|
2268
|
-
//#region src/label-sets-file.ts
|
|
2243
|
+
// src/label-sets-file.ts
|
|
2269
2244
|
function readLabelSet(path, setName) {
|
|
2270
2245
|
let raw;
|
|
2271
2246
|
try {
|
|
@@ -2292,8 +2267,7 @@ function readLabelSet(path, setName) {
|
|
|
2292
2267
|
}
|
|
2293
2268
|
return specs;
|
|
2294
2269
|
}
|
|
2295
|
-
|
|
2296
|
-
//#region src/labels.ts
|
|
2270
|
+
// src/labels.ts
|
|
2297
2271
|
async function runLabelsList(fetcher, conn) {
|
|
2298
2272
|
const labels = await fetchAllForgejoLabels(fetcher, conn);
|
|
2299
2273
|
return {
|
|
@@ -2327,8 +2301,7 @@ function renderSync(result) {
|
|
|
2327
2301
|
for (const line of repoLines) rootLogger.info(line);
|
|
2328
2302
|
for (const line of failureLines) rootLogger.warn(line);
|
|
2329
2303
|
}
|
|
2330
|
-
|
|
2331
|
-
//#region src/commands/labels.ts
|
|
2304
|
+
// src/commands/labels.ts
|
|
2332
2305
|
const GITHUB_REFUSAL = "bst-fj labels requires a Forgejo repository";
|
|
2333
2306
|
const listCommand$1 = defineCommand({
|
|
2334
2307
|
meta: {
|
|
@@ -2435,8 +2408,7 @@ const labelsCommand = defineCommand({
|
|
|
2435
2408
|
sync: syncCommand
|
|
2436
2409
|
}
|
|
2437
2410
|
});
|
|
2438
|
-
|
|
2439
|
-
//#region ../forgejo/src/releases.ts
|
|
2411
|
+
// ../forgejo/src/releases.ts
|
|
2440
2412
|
const SETTLE_ATTEMPTS = 4;
|
|
2441
2413
|
const SETTLE_BASE_DELAY_MS = 2e3;
|
|
2442
2414
|
const SETTLE_MAX_DELAY_MS = 16e3;
|
|
@@ -2658,8 +2630,7 @@ z.looseObject({
|
|
|
2658
2630
|
created: z.string().nullish()
|
|
2659
2631
|
})
|
|
2660
2632
|
});
|
|
2661
|
-
|
|
2662
|
-
//#region src/commands/release-create.ts
|
|
2633
|
+
// src/commands/release-create.ts
|
|
2663
2634
|
const releaseCreateCommand = defineCommand({
|
|
2664
2635
|
meta: {
|
|
2665
2636
|
name: "release:create",
|
|
@@ -2708,8 +2679,7 @@ const releaseCreateCommand = defineCommand({
|
|
|
2708
2679
|
else rootLogger.info(`Created Forgejo release for ${args.tag}`);
|
|
2709
2680
|
}
|
|
2710
2681
|
});
|
|
2711
|
-
|
|
2712
|
-
//#region ../forgejo/src/secrets.ts
|
|
2682
|
+
// ../forgejo/src/secrets.ts
|
|
2713
2683
|
const ActionSecretListSchema = z.array(z.object({ name: z.string() }));
|
|
2714
2684
|
const SECRETS_PAGE_SIZE = 50;
|
|
2715
2685
|
const SECRETS_MAX_PAGES = 20;
|
|
@@ -2765,8 +2735,7 @@ async function deleteActionSecret(executor, conn, secretName) {
|
|
|
2765
2735
|
resource: secretName
|
|
2766
2736
|
}));
|
|
2767
2737
|
}
|
|
2768
|
-
|
|
2769
|
-
//#region src/secrets.ts
|
|
2738
|
+
// src/secrets.ts
|
|
2770
2739
|
async function runSecretsSet(fetcher, config) {
|
|
2771
2740
|
if (!isValidSecretName(config.secretName)) throw new FatalError(`Invalid secret name "${config.secretName}". A name must match [A-Za-z_][A-Za-z0-9_]* and must not start with FORGEJO_, GITEA_, GITHUB_, or a digit.`);
|
|
2772
2741
|
if (config.dryRun) {
|
|
@@ -2808,8 +2777,7 @@ async function runSecretsDelete(fetcher, config) {
|
|
|
2808
2777
|
repository: config.conn.repository
|
|
2809
2778
|
};
|
|
2810
2779
|
}
|
|
2811
|
-
|
|
2812
|
-
//#region src/commands/secrets.ts
|
|
2780
|
+
// src/commands/secrets.ts
|
|
2813
2781
|
function readSecretValue(body) {
|
|
2814
2782
|
if (body) return body;
|
|
2815
2783
|
try {
|
|
@@ -2938,8 +2906,7 @@ const secretsCommand = defineCommand({
|
|
|
2938
2906
|
delete: deleteCommand
|
|
2939
2907
|
}
|
|
2940
2908
|
});
|
|
2941
|
-
|
|
2942
|
-
//#region ../forgejo/src/user.ts
|
|
2909
|
+
// ../forgejo/src/user.ts
|
|
2943
2910
|
const AuthenticatedUserSchema = z.object({
|
|
2944
2911
|
login: z.string(),
|
|
2945
2912
|
email: z.string().nullish()
|
|
@@ -2962,8 +2929,7 @@ async function getAuthenticatedUser(executor, conn, signal = null) {
|
|
|
2962
2929
|
email: parsed.data.email || null
|
|
2963
2930
|
};
|
|
2964
2931
|
}
|
|
2965
|
-
|
|
2966
|
-
//#region ../forgejo/src/webhooks.ts
|
|
2932
|
+
// ../forgejo/src/webhooks.ts
|
|
2967
2933
|
const WebhookSchema = z.object({
|
|
2968
2934
|
id: z.number(),
|
|
2969
2935
|
type: z.string(),
|
|
@@ -3044,8 +3010,7 @@ async function searchRepos(executor, conn) {
|
|
|
3044
3010
|
return parsed.data.data;
|
|
3045
3011
|
})).map((r) => r.full_name);
|
|
3046
3012
|
}
|
|
3047
|
-
|
|
3048
|
-
//#region src/commands/webhooks.ts
|
|
3013
|
+
// src/commands/webhooks.ts
|
|
3049
3014
|
function collectGroup(label, scopeHint, status) {
|
|
3050
3015
|
if (status.status === "ok") return status.hooks.length > 0 ? {
|
|
3051
3016
|
label,
|
|
@@ -3121,8 +3086,7 @@ const webhooksCommand = defineCommand({
|
|
|
3121
3086
|
renderText(inventory, conn.serverUrl);
|
|
3122
3087
|
}
|
|
3123
3088
|
});
|
|
3124
|
-
|
|
3125
|
-
//#region ../forgejo/src/actions.ts
|
|
3089
|
+
// ../forgejo/src/actions.ts
|
|
3126
3090
|
function forgeTimestamp(value) {
|
|
3127
3091
|
if (value === null || value === void 0 || value === "") return null;
|
|
3128
3092
|
const ms = Date.parse(value);
|
|
@@ -3300,8 +3264,7 @@ async function dispatchWorkflow(executor, conn, options) {
|
|
|
3300
3264
|
inputs: options.inputs
|
|
3301
3265
|
};
|
|
3302
3266
|
}
|
|
3303
|
-
|
|
3304
|
-
//#region ../forgejo/src/actions-log.ts
|
|
3267
|
+
// ../forgejo/src/actions-log.ts
|
|
3305
3268
|
const CSI_SEQUENCE = /\u001b\[[0-?]*[ -/]*[@-~]/gu;
|
|
3306
3269
|
const OSC_SEQUENCE = /\u001b\][^\u0007]*(?:\u0007|\u001b\\)/gu;
|
|
3307
3270
|
const LONE_ESCAPE = /\u001b/gu;
|
|
@@ -3343,8 +3306,7 @@ function readActionsJobLog(text) {
|
|
|
3343
3306
|
lines
|
|
3344
3307
|
};
|
|
3345
3308
|
}
|
|
3346
|
-
|
|
3347
|
-
//#region src/ci-log.ts
|
|
3309
|
+
// src/ci-log.ts
|
|
3348
3310
|
const ACTIONS_RUN_URL = /\/actions\/runs\/(\d+)\/?(?:[?#]|$)/u;
|
|
3349
3311
|
function parseCiLogTarget(target) {
|
|
3350
3312
|
if (/^\d+$/.test(target)) return {
|
|
@@ -3435,8 +3397,7 @@ function renderCiLog(result) {
|
|
|
3435
3397
|
for (const line of result.lines) lines.push(line.at === null ? line.text : `${line.at} ${line.text}`);
|
|
3436
3398
|
return lines.join("\n");
|
|
3437
3399
|
}
|
|
3438
|
-
|
|
3439
|
-
//#region src/commands/ci-log.ts
|
|
3400
|
+
// src/commands/ci-log.ts
|
|
3440
3401
|
const ciLogCommand = defineCommand({
|
|
3441
3402
|
meta: {
|
|
3442
3403
|
name: "ci:log",
|
|
@@ -3490,8 +3451,7 @@ const ciLogCommand = defineCommand({
|
|
|
3490
3451
|
out.text(renderCiLog(result));
|
|
3491
3452
|
}
|
|
3492
3453
|
});
|
|
3493
|
-
|
|
3494
|
-
//#region src/ci-runs.ts
|
|
3454
|
+
// src/ci-runs.ts
|
|
3495
3455
|
function resolveRunsRef(ref, pr) {
|
|
3496
3456
|
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).");
|
|
3497
3457
|
if (pr !== void 0) {
|
|
@@ -3567,8 +3527,7 @@ function renderCiRuns(result) {
|
|
|
3567
3527
|
}
|
|
3568
3528
|
return lines.join("\n");
|
|
3569
3529
|
}
|
|
3570
|
-
|
|
3571
|
-
//#region src/commands/ci-runs.ts
|
|
3530
|
+
// src/commands/ci-runs.ts
|
|
3572
3531
|
const ciRunsCommand = defineCommand({
|
|
3573
3532
|
meta: {
|
|
3574
3533
|
name: "ci:runs",
|
|
@@ -3633,8 +3592,7 @@ const ciRunsCommand = defineCommand({
|
|
|
3633
3592
|
out.text(renderCiRuns(result));
|
|
3634
3593
|
}
|
|
3635
3594
|
});
|
|
3636
|
-
|
|
3637
|
-
//#region ../cli-kit/src/workflow-inputs.ts
|
|
3595
|
+
// ../cli-kit/src/workflow-inputs.ts
|
|
3638
3596
|
const INPUT_FLAG = "--input";
|
|
3639
3597
|
const INPUT_FLAG_EQ = "--input=";
|
|
3640
3598
|
function collectInputArgs(rawArgs) {
|
|
@@ -3661,8 +3619,7 @@ function parseInputs(raw) {
|
|
|
3661
3619
|
}
|
|
3662
3620
|
return inputs;
|
|
3663
3621
|
}
|
|
3664
|
-
|
|
3665
|
-
//#region src/workflow-dispatch.ts
|
|
3622
|
+
// src/workflow-dispatch.ts
|
|
3666
3623
|
async function runWorkflowDispatch(fetcher, options) {
|
|
3667
3624
|
const dispatched = await dispatchWorkflow(fetcher, requireForgejoTarget(options.cwd, void 0, "workflow:dispatch is Forgejo-only -- use gh workflow run on GitHub."), {
|
|
3668
3625
|
...options.repo === void 0 ? {} : { repository: options.repo },
|
|
@@ -3679,8 +3636,7 @@ async function runWorkflowDispatch(fetcher, options) {
|
|
|
3679
3636
|
inputs: dispatched.inputs
|
|
3680
3637
|
};
|
|
3681
3638
|
}
|
|
3682
|
-
|
|
3683
|
-
//#region src/registry-actions.ts
|
|
3639
|
+
// src/registry-actions.ts
|
|
3684
3640
|
const actionsSubCommands = {
|
|
3685
3641
|
"ci:log": ciLogCommand,
|
|
3686
3642
|
"ci:runs": ciRunsCommand,
|
|
@@ -3749,8 +3705,7 @@ const DirEntrySchema = z.looseObject({
|
|
|
3749
3705
|
type: z.string()
|
|
3750
3706
|
});
|
|
3751
3707
|
z.array(DirEntrySchema);
|
|
3752
|
-
|
|
3753
|
-
//#region ../forgejo/src/branches.ts
|
|
3708
|
+
// ../forgejo/src/branches.ts
|
|
3754
3709
|
const BranchEntrySchema = z.object({
|
|
3755
3710
|
name: z.string(),
|
|
3756
3711
|
protected: z.boolean().optional(),
|
|
@@ -3829,8 +3784,7 @@ async function deleteBranch(executor, conn, branch) {
|
|
|
3829
3784
|
resource: `${conn.repository}/${branch}`
|
|
3830
3785
|
});
|
|
3831
3786
|
}
|
|
3832
|
-
|
|
3833
|
-
//#region src/branch.ts
|
|
3787
|
+
// src/branch.ts
|
|
3834
3788
|
const REFUSAL_WORDS = {
|
|
3835
3789
|
forbidden: "forbidden",
|
|
3836
3790
|
locked: "locked",
|
|
@@ -3856,8 +3810,7 @@ function renderBranchList(listing) {
|
|
|
3856
3810
|
if (listing.truncated) lines.push("Listing truncated at the page cap; more branches exist.");
|
|
3857
3811
|
return lines.join("\n");
|
|
3858
3812
|
}
|
|
3859
|
-
|
|
3860
|
-
//#region src/registry-branch.ts
|
|
3813
|
+
// src/registry-branch.ts
|
|
3861
3814
|
const branchSubCommands = {
|
|
3862
3815
|
"branch:delete": defineCommand({
|
|
3863
3816
|
meta: {
|
|
@@ -3927,8 +3880,7 @@ const branchSubCommands = {
|
|
|
3927
3880
|
}
|
|
3928
3881
|
})
|
|
3929
3882
|
};
|
|
3930
|
-
|
|
3931
|
-
//#region ../cli-kit/src/body-source.ts
|
|
3883
|
+
// ../cli-kit/src/body-source.ts
|
|
3932
3884
|
function tryRead(read, label) {
|
|
3933
3885
|
try {
|
|
3934
3886
|
return read();
|
|
@@ -3948,8 +3900,7 @@ function readBodySource(body, bodyFile, options = {}) {
|
|
|
3948
3900
|
if (!existsSync(bodyFile)) throw new FatalError(`${flags.file} not found: ${bodyFile}`);
|
|
3949
3901
|
return tryRead(() => readFileSync(bodyFile, "utf-8"), `${flags.file} "${bodyFile}"`);
|
|
3950
3902
|
}
|
|
3951
|
-
|
|
3952
|
-
//#region ../forgejo/src/issue-comments.ts
|
|
3903
|
+
// ../forgejo/src/issue-comments.ts
|
|
3953
3904
|
const CommentResponseSchema = z.object({
|
|
3954
3905
|
id: z.number(),
|
|
3955
3906
|
body: z.string().nullish(),
|
|
@@ -4023,8 +3974,7 @@ async function addForgejoComment(executor, conn, number, body) {
|
|
|
4023
3974
|
}, issueNotFoundMessage(conn, number));
|
|
4024
3975
|
return normalizeComment(parseCommentOrThrow(await res.json()));
|
|
4025
3976
|
}
|
|
4026
|
-
|
|
4027
|
-
//#region ../forgejo/src/pr-title.ts
|
|
3977
|
+
// ../forgejo/src/pr-title.ts
|
|
4028
3978
|
const WIP_PREFIXES = ["WIP:", "[WIP]"];
|
|
4029
3979
|
function hasWipPrefix(title) {
|
|
4030
3980
|
return matchedWipPrefix(title) !== void 0;
|
|
@@ -4038,8 +3988,7 @@ function stripWipPrefix(title) {
|
|
|
4038
3988
|
if (prefix === void 0) return title;
|
|
4039
3989
|
return title.slice(prefix.length).trimStart();
|
|
4040
3990
|
}
|
|
4041
|
-
|
|
4042
|
-
//#region ../forgejo/src/pr.ts
|
|
3991
|
+
// ../forgejo/src/pr.ts
|
|
4043
3992
|
const CreatedPrSchema = z.object({
|
|
4044
3993
|
number: z.number(),
|
|
4045
3994
|
html_url: z.string().optional()
|
|
@@ -4090,9 +4039,12 @@ function updatedBefore(since) {
|
|
|
4090
4039
|
return (pr) => pr.updatedAt !== null && Date.parse(pr.updatedAt) < since;
|
|
4091
4040
|
}
|
|
4092
4041
|
async function listPulls(executor, conn, options = {}) {
|
|
4042
|
+
const startPage = options.startPage ?? 1;
|
|
4043
|
+
if (!Number.isInteger(startPage) || startPage < 1) throw new FatalError(`Cannot list PRs on ${conn.repository}: startPage must be an integer of at least 1, got ${String(startPage)}`);
|
|
4044
|
+
const lastPage = startPage + PULLS_MAX_PAGES - 1;
|
|
4093
4045
|
const headers = { Authorization: `token ${conn.token}` };
|
|
4094
4046
|
const pulls = [];
|
|
4095
|
-
for (let page =
|
|
4047
|
+
for (let page = startPage; page <= lastPage; page++) {
|
|
4096
4048
|
options.signal?.throwIfAborted();
|
|
4097
4049
|
const params = new URLSearchParams({
|
|
4098
4050
|
state: options.state ?? "all",
|
|
@@ -4132,9 +4084,9 @@ async function listPulls(executor, conn, options = {}) {
|
|
|
4132
4084
|
if (options.stopWhen !== void 0 && items.some(options.stopWhen)) break;
|
|
4133
4085
|
if (options.updatedSince !== void 0 && items.some(updatedBefore(options.updatedSince))) break;
|
|
4134
4086
|
if (options.limit !== void 0 && pulls.length >= options.limit) break;
|
|
4135
|
-
if (page ===
|
|
4087
|
+
if (page === lastPage) {
|
|
4136
4088
|
log.warn(`PR listing on ${conn.repository} hit the ${String(PULLS_MAX_PAGES)}-page cap without an empty page; results may be truncated`);
|
|
4137
|
-
options.onPageCap?.();
|
|
4089
|
+
options.onPageCap?.(lastPage);
|
|
4138
4090
|
}
|
|
4139
4091
|
}
|
|
4140
4092
|
return pulls;
|
|
@@ -4306,8 +4258,7 @@ const PullReviewCommentSchema = z.object({
|
|
|
4306
4258
|
user: z.object({ login: z.string() }).nullish()
|
|
4307
4259
|
});
|
|
4308
4260
|
z.array(PullReviewCommentSchema);
|
|
4309
|
-
|
|
4310
|
-
//#region ../forgejo/src/issue-api.ts
|
|
4261
|
+
// ../forgejo/src/issue-api.ts
|
|
4311
4262
|
var IssueNumberRequiredError = class extends FatalError {
|
|
4312
4263
|
constructor() {
|
|
4313
4264
|
super("An issue number or issue URL is required.");
|
|
@@ -4334,8 +4285,7 @@ function forgejoIssueApi(fetcher, conn) {
|
|
|
4334
4285
|
pullRequest: (number) => getForgejoPrDetail(fetcher, conn, number)
|
|
4335
4286
|
};
|
|
4336
4287
|
}
|
|
4337
|
-
|
|
4338
|
-
//#region ../forgejo/src/issue-messages.ts
|
|
4288
|
+
// ../forgejo/src/issue-messages.ts
|
|
4339
4289
|
const ISSUE_LIST_JSON_HELP = "Emit one JSON document: issues ([{number, title, state, url, author, labels, createdAt, updatedAt, closedAt (null while open), isPullRequest, assignees, attachments ([{id, name, size, createdAt, downloadUrl}])}]), truncated.";
|
|
4340
4290
|
const ISSUE_CREATE_JSON_HELP = "Emit one JSON document: number, url, assignees. A dry run reports number 0 and an empty url.";
|
|
4341
4291
|
const ISSUE_STATE_JSON_HELP = "Emit one JSON document: number, url, action (close | reopen), state ({previous, current}), changed, comment? ({posted}; present only when a comment was given).";
|
|
@@ -4366,8 +4316,7 @@ function describeNoLabelsGiven(error, clearFlag) {
|
|
|
4366
4316
|
function describeAttachmentExists(error, forceFlag) {
|
|
4367
4317
|
return `"${error.filePath}" already exists -- pass ${forceFlag} to overwrite it.`;
|
|
4368
4318
|
}
|
|
4369
|
-
|
|
4370
|
-
//#region ../forgejo/src/issue-run.ts
|
|
4319
|
+
// ../forgejo/src/issue-run.ts
|
|
4371
4320
|
var NothingToUpdateError = class extends FatalError {
|
|
4372
4321
|
constructor() {
|
|
4373
4322
|
super("Nothing to change: neither a title nor a body was given.");
|
|
@@ -4623,8 +4572,7 @@ function formatIssueList(result) {
|
|
|
4623
4572
|
}
|
|
4624
4573
|
return lines.join("\n");
|
|
4625
4574
|
}
|
|
4626
|
-
|
|
4627
|
-
//#region src/issue-transport.ts
|
|
4575
|
+
// src/issue-transport.ts
|
|
4628
4576
|
function githubRefusal(command) {
|
|
4629
4577
|
return `bst-fj is Forgejo-only -- use \`gh\` or \`pnpm exec bst ${command}\` for a github.com repository.`;
|
|
4630
4578
|
}
|
|
@@ -4647,8 +4595,7 @@ function forgejoIssueTransport(cwd, target, command) {
|
|
|
4647
4595
|
target: resolved.target
|
|
4648
4596
|
};
|
|
4649
4597
|
}
|
|
4650
|
-
|
|
4651
|
-
//#region src/commands/issue-comment.ts
|
|
4598
|
+
// src/commands/issue-comment.ts
|
|
4652
4599
|
const issueCommentCommand = defineCommand({
|
|
4653
4600
|
meta: {
|
|
4654
4601
|
name: "issue:comment",
|
|
@@ -4706,8 +4653,7 @@ const issueCommentCommand = defineCommand({
|
|
|
4706
4653
|
}
|
|
4707
4654
|
}
|
|
4708
4655
|
});
|
|
4709
|
-
|
|
4710
|
-
//#region src/commands/issue-create.ts
|
|
4656
|
+
// src/commands/issue-create.ts
|
|
4711
4657
|
const issueCreateCommand = defineCommand({
|
|
4712
4658
|
meta: {
|
|
4713
4659
|
name: "issue:create",
|
|
@@ -4780,8 +4726,7 @@ const issueCreateCommand = defineCommand({
|
|
|
4780
4726
|
}
|
|
4781
4727
|
}
|
|
4782
4728
|
});
|
|
4783
|
-
|
|
4784
|
-
//#region ../forgejo/src/issue-run-download.ts
|
|
4729
|
+
// ../forgejo/src/issue-run-download.ts
|
|
4785
4730
|
function isReadableFile(filePath) {
|
|
4786
4731
|
try {
|
|
4787
4732
|
readFileSync(filePath);
|
|
@@ -4874,8 +4819,7 @@ function formatDownload(result, dryRun) {
|
|
|
4874
4819
|
for (const file of result.files) lines.push(` ${file.name} (${String(file.size)} bytes)`);
|
|
4875
4820
|
return lines.join("\n");
|
|
4876
4821
|
}
|
|
4877
|
-
|
|
4878
|
-
//#region src/commands/issue-download.ts
|
|
4822
|
+
// src/commands/issue-download.ts
|
|
4879
4823
|
const issueDownloadCommand = defineCommand({
|
|
4880
4824
|
meta: {
|
|
4881
4825
|
name: "issue:download",
|
|
@@ -4934,8 +4878,7 @@ const issueDownloadCommand = defineCommand({
|
|
|
4934
4878
|
}
|
|
4935
4879
|
}
|
|
4936
4880
|
});
|
|
4937
|
-
|
|
4938
|
-
//#region ../forgejo/src/issue-labels.ts
|
|
4881
|
+
// ../forgejo/src/issue-labels.ts
|
|
4939
4882
|
const TimelineEntrySchema = z.object({
|
|
4940
4883
|
id: z.number(),
|
|
4941
4884
|
type: z.string(),
|
|
@@ -4986,8 +4929,7 @@ async function replaceForgejoIssueLabels(executor, conn, number, labelIds) {
|
|
|
4986
4929
|
resource: `#${String(number)}`
|
|
4987
4930
|
}, issueNotFoundMessage(conn, number));
|
|
4988
4931
|
}
|
|
4989
|
-
|
|
4990
|
-
//#region ../forgejo/src/issue-run-labels.ts
|
|
4932
|
+
// ../forgejo/src/issue-run-labels.ts
|
|
4991
4933
|
async function labelIssue(resolve, request) {
|
|
4992
4934
|
const ref = parseIssueRef(request.ref);
|
|
4993
4935
|
const number = requireIssueNumber(ref);
|
|
@@ -5056,8 +4998,7 @@ function formatIssueSetLabels(result, dryRun) {
|
|
|
5056
4998
|
if (result.added.length > 0) lines.push(` ${dryRun ? "would add" : "added"}: ${result.added.join(", ")}`);
|
|
5057
4999
|
return lines.join("\n");
|
|
5058
5000
|
}
|
|
5059
|
-
|
|
5060
|
-
//#region src/commands/issue-label.ts
|
|
5001
|
+
// src/commands/issue-label.ts
|
|
5061
5002
|
function defineIssueLabelCommand(action) {
|
|
5062
5003
|
const name = action === "add" ? "issue:label" : "issue:unlabel";
|
|
5063
5004
|
return defineCommand({
|
|
@@ -5116,8 +5057,7 @@ function defineIssueLabelCommand(action) {
|
|
|
5116
5057
|
}
|
|
5117
5058
|
const issueLabelCommand = defineIssueLabelCommand("add");
|
|
5118
5059
|
const issueUnlabelCommand = defineIssueLabelCommand("remove");
|
|
5119
|
-
|
|
5120
|
-
//#region src/commands/issue-set-labels.ts
|
|
5060
|
+
// src/commands/issue-set-labels.ts
|
|
5121
5061
|
const issueSetLabelsCommand = defineCommand({
|
|
5122
5062
|
meta: {
|
|
5123
5063
|
name: "issue:set-labels",
|
|
@@ -5177,8 +5117,7 @@ const issueSetLabelsCommand = defineCommand({
|
|
|
5177
5117
|
}
|
|
5178
5118
|
}
|
|
5179
5119
|
});
|
|
5180
|
-
|
|
5181
|
-
//#region ../forgejo/src/issue-run-state.ts
|
|
5120
|
+
// ../forgejo/src/issue-run-state.ts
|
|
5182
5121
|
var EmptyCommentError = class extends FatalError {
|
|
5183
5122
|
constructor() {
|
|
5184
5123
|
super("The comment resolved to empty text.");
|
|
@@ -5274,8 +5213,7 @@ function formatIssueState(result, dryRun) {
|
|
|
5274
5213
|
}
|
|
5275
5214
|
return lines.join("\n");
|
|
5276
5215
|
}
|
|
5277
|
-
|
|
5278
|
-
//#region src/commands/issue-state.ts
|
|
5216
|
+
// src/commands/issue-state.ts
|
|
5279
5217
|
function defineIssueStateCommand(action) {
|
|
5280
5218
|
const name = action === "close" ? "issue:close" : "issue:reopen";
|
|
5281
5219
|
return defineCommand({
|
|
@@ -5351,8 +5289,7 @@ function defineIssueStateCommand(action) {
|
|
|
5351
5289
|
}
|
|
5352
5290
|
const issueCloseCommand = defineIssueStateCommand("close");
|
|
5353
5291
|
const issueReopenCommand = defineIssueStateCommand("reopen");
|
|
5354
|
-
|
|
5355
|
-
//#region src/commands/issue-list.ts
|
|
5292
|
+
// src/commands/issue-list.ts
|
|
5356
5293
|
const issueListCommand = defineCommand({
|
|
5357
5294
|
meta: {
|
|
5358
5295
|
name: "issue:list",
|
|
@@ -5410,8 +5347,7 @@ const issueListCommand = defineCommand({
|
|
|
5410
5347
|
}
|
|
5411
5348
|
}
|
|
5412
5349
|
});
|
|
5413
|
-
|
|
5414
|
-
//#region src/commands/issue-update.ts
|
|
5350
|
+
// src/commands/issue-update.ts
|
|
5415
5351
|
const issueUpdateCommand = defineCommand({
|
|
5416
5352
|
meta: {
|
|
5417
5353
|
name: "issue:update",
|
|
@@ -5482,8 +5418,7 @@ const issueUpdateCommand = defineCommand({
|
|
|
5482
5418
|
}
|
|
5483
5419
|
}
|
|
5484
5420
|
});
|
|
5485
|
-
|
|
5486
|
-
//#region src/registry-issue.ts
|
|
5421
|
+
// src/registry-issue.ts
|
|
5487
5422
|
const issueSubCommands = {
|
|
5488
5423
|
"issue:view": defineCommand({
|
|
5489
5424
|
meta: {
|
|
@@ -5536,8 +5471,7 @@ const issueSubCommands = {
|
|
|
5536
5471
|
"issue:set-labels": issueSetLabelsCommand,
|
|
5537
5472
|
"issue:download": issueDownloadCommand
|
|
5538
5473
|
};
|
|
5539
|
-
|
|
5540
|
-
//#region src/pr-checks.ts
|
|
5474
|
+
// src/pr-checks.ts
|
|
5541
5475
|
async function resolvePrChecksTarget(fetcher, options) {
|
|
5542
5476
|
const ref = parseIssueRef(options.pr);
|
|
5543
5477
|
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.");
|
|
@@ -5711,8 +5645,7 @@ function renderPrChecks(report) {
|
|
|
5711
5645
|
lines.push(summaryParts.join(" -- "));
|
|
5712
5646
|
return lines.join("\n");
|
|
5713
5647
|
}
|
|
5714
|
-
|
|
5715
|
-
//#region src/commands/pr-checks.ts
|
|
5648
|
+
// src/commands/pr-checks.ts
|
|
5716
5649
|
const prChecksCommand = defineCommand({
|
|
5717
5650
|
meta: {
|
|
5718
5651
|
name: "pr:checks",
|
|
@@ -5776,8 +5709,7 @@ const prChecksCommand = defineCommand({
|
|
|
5776
5709
|
process.exitCode = report.status === "green" ? 0 : 1;
|
|
5777
5710
|
}
|
|
5778
5711
|
});
|
|
5779
|
-
|
|
5780
|
-
//#region ../forgejo/src/pr-close.ts
|
|
5712
|
+
// ../forgejo/src/pr-close.ts
|
|
5781
5713
|
async function closePullRequest(api, request) {
|
|
5782
5714
|
rejectEmptyComment(request.comment);
|
|
5783
5715
|
return changeState(api, request.number, {
|
|
@@ -5794,15 +5726,13 @@ function formatPrClose(result, dryRun) {
|
|
|
5794
5726
|
return lines.join("\n");
|
|
5795
5727
|
}
|
|
5796
5728
|
const PR_CLOSE_JSON_HELP = "Emit one JSON document: number, url, action (close), state ({previous, current}), changed, merged? (present only when the pull request was already closed), comment? ({posted}; present only when a comment was given).";
|
|
5797
|
-
|
|
5798
|
-
//#region ../forgejo/src/pr-number.ts
|
|
5729
|
+
// ../forgejo/src/pr-number.ts
|
|
5799
5730
|
function parsePrNumber(raw) {
|
|
5800
5731
|
const value = Number(raw);
|
|
5801
5732
|
if (!/^\d+$/.test(raw) || !Number.isSafeInteger(value) || value < 1) throw new FatalError(`Invalid pull request number "${raw}" (expected a positive integer).`);
|
|
5802
5733
|
return value;
|
|
5803
5734
|
}
|
|
5804
|
-
|
|
5805
|
-
//#region src/commands/pr-close.ts
|
|
5735
|
+
// src/commands/pr-close.ts
|
|
5806
5736
|
const prCloseCommand = defineCommand({
|
|
5807
5737
|
meta: {
|
|
5808
5738
|
name: "pr:close",
|
|
@@ -5866,8 +5796,7 @@ const prCloseCommand = defineCommand({
|
|
|
5866
5796
|
}
|
|
5867
5797
|
}
|
|
5868
5798
|
});
|
|
5869
|
-
|
|
5870
|
-
//#region ../forgejo/src/closing-refs.ts
|
|
5799
|
+
// ../forgejo/src/closing-refs.ts
|
|
5871
5800
|
const CLOSING_REF = /(?:^|[\s([])(clos(?:e|es|ed)|fix(?:es|ed)?|resolv(?:e|es|ed))(?::[ \t]*|[ \t]+)((?:[\w.-]+\/[\w.-]+)?#\d+)(?![\w-])/gim;
|
|
5872
5801
|
function capitalize(word) {
|
|
5873
5802
|
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
@@ -5897,8 +5826,7 @@ function carryForwardClosingRefs(source, target) {
|
|
|
5897
5826
|
const refLines = missing.map((ref) => ref.text).join("\n");
|
|
5898
5827
|
return target.trim() === "" ? refLines : `${target}\n\n${refLines}`;
|
|
5899
5828
|
}
|
|
5900
|
-
|
|
5901
|
-
//#region ../forgejo/src/git.ts
|
|
5829
|
+
// ../forgejo/src/git.ts
|
|
5902
5830
|
const GIT_LOCAL_TIMEOUT_MS = 6e4;
|
|
5903
5831
|
const GIT_WRITE_TIMEOUT_MS = 3e5;
|
|
5904
5832
|
function pickDefaultBranch(override, originHead) {
|
|
@@ -6009,8 +5937,7 @@ async function pushBranch(git, cwd, branch, env, forceWithLease = false) {
|
|
|
6009
5937
|
});
|
|
6010
5938
|
if (result.exitCode !== 0) throw new FatalError(`Failed to push ${branch}: ${result.stderr || result.stdout}`);
|
|
6011
5939
|
}
|
|
6012
|
-
|
|
6013
|
-
//#region ../forgejo/src/pr-upsert.ts
|
|
5940
|
+
// ../forgejo/src/pr-upsert.ts
|
|
6014
5941
|
const COMMIT_TYPES = /* @__PURE__ */ new Set([
|
|
6015
5942
|
"feat",
|
|
6016
5943
|
"fix",
|
|
@@ -6218,8 +6145,7 @@ async function runPrUpsert(git, host, options) {
|
|
|
6218
6145
|
...shape
|
|
6219
6146
|
};
|
|
6220
6147
|
}
|
|
6221
|
-
|
|
6222
|
-
//#region ../forgejo/src/pr-upsert-messages.ts
|
|
6148
|
+
// ../forgejo/src/pr-upsert-messages.ts
|
|
6223
6149
|
function describePrModeError(error, commands) {
|
|
6224
6150
|
if (error.reason === "already-open") {
|
|
6225
6151
|
const createVerb = commands.create.split(" ").at(-1) ?? commands.create;
|
|
@@ -6298,8 +6224,7 @@ function formatPrUpdate(result, rewrites, flags) {
|
|
|
6298
6224
|
body: null
|
|
6299
6225
|
};
|
|
6300
6226
|
}
|
|
6301
|
-
|
|
6302
|
-
//#region ../forgejo/src/pr-host.ts
|
|
6227
|
+
// ../forgejo/src/pr-host.ts
|
|
6303
6228
|
function forgejoPrHost(fetcher, conn) {
|
|
6304
6229
|
return {
|
|
6305
6230
|
wipTitles: true,
|
|
@@ -6332,8 +6257,7 @@ function forgejoPrEditHost(fetcher, conn) {
|
|
|
6332
6257
|
ready: (number, write) => updatePr(fetcher, conn, number, { title: write.title })
|
|
6333
6258
|
};
|
|
6334
6259
|
}
|
|
6335
|
-
|
|
6336
|
-
//#region src/git.ts
|
|
6260
|
+
// src/git.ts
|
|
6337
6261
|
const TIMED_OUT_EXIT_CODE = 124;
|
|
6338
6262
|
const ABORTED_EXIT_CODE = 143;
|
|
6339
6263
|
function cliGit() {
|
|
@@ -6409,8 +6333,7 @@ function cliGit() {
|
|
|
6409
6333
|
});
|
|
6410
6334
|
}) };
|
|
6411
6335
|
}
|
|
6412
|
-
|
|
6413
|
-
//#region src/pr-run.ts
|
|
6336
|
+
// src/pr-run.ts
|
|
6414
6337
|
const COMMANDS = {
|
|
6415
6338
|
create: "pnpm exec bst-fj pr:create",
|
|
6416
6339
|
update: "pnpm exec bst-fj pr:update"
|
|
@@ -6444,8 +6367,7 @@ async function runForgejoPr(githubRefusal, options) {
|
|
|
6444
6367
|
});
|
|
6445
6368
|
}
|
|
6446
6369
|
}
|
|
6447
|
-
|
|
6448
|
-
//#region src/commands/pr-create.ts
|
|
6370
|
+
// src/commands/pr-create.ts
|
|
6449
6371
|
const prCreateCommand = defineCommand({
|
|
6450
6372
|
meta: {
|
|
6451
6373
|
name: "pr:create",
|
|
@@ -6514,8 +6436,7 @@ const prCreateCommand = defineCommand({
|
|
|
6514
6436
|
if (summary.body !== null) out.text(`${summary.body.heading}\n${summary.body.text}`);
|
|
6515
6437
|
}
|
|
6516
6438
|
});
|
|
6517
|
-
|
|
6518
|
-
//#region ../forgejo/src/pr-files.ts
|
|
6439
|
+
// ../forgejo/src/pr-files.ts
|
|
6519
6440
|
const DEFAULT_LIMIT = 100;
|
|
6520
6441
|
const PrFileEntrySchema = z.object({
|
|
6521
6442
|
filename: z.string(),
|
|
@@ -6560,8 +6481,7 @@ async function readPrFilesPage(executor, conn, prNumber, page, limit) {
|
|
|
6560
6481
|
truncated: res.headers.get("x-hasmore") === "true"
|
|
6561
6482
|
};
|
|
6562
6483
|
}
|
|
6563
|
-
|
|
6564
|
-
//#region src/pr-files.ts
|
|
6484
|
+
// src/pr-files.ts
|
|
6565
6485
|
function runPrFiles(fetcher, options) {
|
|
6566
6486
|
const number = parsePrNumber(options.number);
|
|
6567
6487
|
return listAllPrFiles(fetcher, requireForgejoTarget(options.cwd, parseRepoTarget(options.repo), "pr:files is Forgejo-only -- gh pr diff --name-only already serves GitHub."), number);
|
|
@@ -6572,8 +6492,7 @@ function renderPrFiles(listing) {
|
|
|
6572
6492
|
if (listing.truncated) lines.push("Listing truncated; the pull request changes more files.");
|
|
6573
6493
|
return lines.join("\n");
|
|
6574
6494
|
}
|
|
6575
|
-
|
|
6576
|
-
//#region src/commands/pr-files.ts
|
|
6495
|
+
// src/commands/pr-files.ts
|
|
6577
6496
|
const prFilesCommand = defineCommand({
|
|
6578
6497
|
meta: {
|
|
6579
6498
|
name: "pr:files",
|
|
@@ -6612,8 +6531,7 @@ const prFilesCommand = defineCommand({
|
|
|
6612
6531
|
out.text(renderPrFiles(listing));
|
|
6613
6532
|
}
|
|
6614
6533
|
});
|
|
6615
|
-
|
|
6616
|
-
//#region src/pr-list.ts
|
|
6534
|
+
// src/pr-list.ts
|
|
6617
6535
|
function parseState(state) {
|
|
6618
6536
|
if (state === "open" || state === "closed" || state === "all") return state;
|
|
6619
6537
|
throw new FatalError(`Invalid --state "${state}" (expected open, closed, or all).`);
|
|
@@ -6650,8 +6568,7 @@ function renderPrList(result) {
|
|
|
6650
6568
|
return `#${String(pr.number)} ${statusLabel(pr)} ${branches}: ${pr.title ?? "(no title)"}${labels}${url}`;
|
|
6651
6569
|
}).join("\n");
|
|
6652
6570
|
}
|
|
6653
|
-
|
|
6654
|
-
//#region src/commands/pr-list.ts
|
|
6571
|
+
// src/commands/pr-list.ts
|
|
6655
6572
|
const prListCommand = defineCommand({
|
|
6656
6573
|
meta: {
|
|
6657
6574
|
name: "pr:list",
|
|
@@ -6694,8 +6611,7 @@ const prListCommand = defineCommand({
|
|
|
6694
6611
|
out.text(renderPrList(result));
|
|
6695
6612
|
}
|
|
6696
6613
|
});
|
|
6697
|
-
|
|
6698
|
-
//#region ../forgejo/src/pr-merge.ts
|
|
6614
|
+
// ../forgejo/src/pr-merge.ts
|
|
6699
6615
|
async function mergePr(executor, conn, prNumber, options) {
|
|
6700
6616
|
const url = `${conn.serverUrl}/api/v1/repos/${conn.repository}/pulls/${String(prNumber)}/merge`;
|
|
6701
6617
|
const body = {
|
|
@@ -6798,8 +6714,7 @@ z.object({
|
|
|
6798
6714
|
sha: z.string()
|
|
6799
6715
|
})
|
|
6800
6716
|
});
|
|
6801
|
-
|
|
6802
|
-
//#region ../forgejo/src/pr-merge-run.ts
|
|
6717
|
+
// ../forgejo/src/pr-merge-run.ts
|
|
6803
6718
|
const MERGE_METHODS = [
|
|
6804
6719
|
"merge",
|
|
6805
6720
|
"rebase",
|
|
@@ -6870,8 +6785,7 @@ async function runPrMergeCore(fetcher, conn, number, options = {}) {
|
|
|
6870
6785
|
}
|
|
6871
6786
|
};
|
|
6872
6787
|
}
|
|
6873
|
-
|
|
6874
|
-
//#region src/pr-merge.ts
|
|
6788
|
+
// src/pr-merge.ts
|
|
6875
6789
|
function parseMethod(raw) {
|
|
6876
6790
|
if (raw === void 0) return "merge";
|
|
6877
6791
|
const method = MERGE_METHODS.find((candidate) => candidate === raw);
|
|
@@ -6898,8 +6812,7 @@ function renderPrMerge(result) {
|
|
|
6898
6812
|
const what = `PR #${String(result.number)} (${result.method}) at ${result.headSha.slice(0, 12)}, checks ${result.checks}`;
|
|
6899
6813
|
return result.merged ? `Merged ${what}.` : `Dry run: would merge ${what}.`;
|
|
6900
6814
|
}
|
|
6901
|
-
|
|
6902
|
-
//#region src/commands/pr-merge.ts
|
|
6815
|
+
// src/commands/pr-merge.ts
|
|
6903
6816
|
const prMergeCommand = defineCommand({
|
|
6904
6817
|
meta: {
|
|
6905
6818
|
name: "pr:merge",
|
|
@@ -6955,8 +6868,7 @@ const prMergeCommand = defineCommand({
|
|
|
6955
6868
|
out.text(renderPrMerge(result));
|
|
6956
6869
|
}
|
|
6957
6870
|
});
|
|
6958
|
-
|
|
6959
|
-
//#region ../forgejo/src/pr-edit.ts
|
|
6871
|
+
// ../forgejo/src/pr-edit.ts
|
|
6960
6872
|
const MERGEABLE_RECHECK_DELAY_MS = 2e3;
|
|
6961
6873
|
function isOpen(live) {
|
|
6962
6874
|
return live.state === "open" && live.merged === false;
|
|
@@ -7083,8 +6995,7 @@ function renderPrReady(result) {
|
|
|
7083
6995
|
if (result.action === "would-ready") return `Dry run: pull request ${number} would stop being a draft, reading "${result.title}".`;
|
|
7084
6996
|
return `Dry run: pull request ${number} would read "${result.title}".`;
|
|
7085
6997
|
}
|
|
7086
|
-
|
|
7087
|
-
//#region src/registry-pr.ts
|
|
6998
|
+
// src/registry-pr.ts
|
|
7088
6999
|
const prSubCommands = {
|
|
7089
7000
|
"pr:checks": prChecksCommand,
|
|
7090
7001
|
"pr:close": prCloseCommand,
|
|
@@ -7249,8 +7160,7 @@ const prSubCommands = {
|
|
|
7249
7160
|
}
|
|
7250
7161
|
})
|
|
7251
7162
|
};
|
|
7252
|
-
|
|
7253
|
-
//#region src/registry.ts
|
|
7163
|
+
// src/registry.ts
|
|
7254
7164
|
const bstFjSubCommands = {
|
|
7255
7165
|
"commit:status": commitStatusCommand,
|
|
7256
7166
|
labels: labelsCommand,
|
|
@@ -7262,8 +7172,7 @@ const bstFjSubCommands = {
|
|
|
7262
7172
|
webhooks: webhooksCommand,
|
|
7263
7173
|
...issueSubCommands
|
|
7264
7174
|
};
|
|
7265
|
-
|
|
7266
|
-
//#region src/bin.ts
|
|
7175
|
+
// src/bin.ts
|
|
7267
7176
|
applyVerbosityFromArgs(process.argv.slice(2));
|
|
7268
7177
|
rootLogger.debug(describeEnvFileLoad(envFileLoad));
|
|
7269
7178
|
setForgejoLogger(rootLogger);
|
|
@@ -7275,5 +7184,4 @@ await runCli({
|
|
|
7275
7184
|
subCommands: bstFjSubCommands,
|
|
7276
7185
|
describeError: describeForgeError
|
|
7277
7186
|
});
|
|
7278
|
-
//#endregion
|
|
7279
7187
|
export {};
|