@recoder.xyz/rithub 0.3.3 → 0.3.5
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 +10 -0
- package/package.json +1 -1
- package/src/cli.mjs +20 -0
- package/src/export.mjs +78 -0
package/README.md
CHANGED
|
@@ -144,10 +144,20 @@ rit logout [--json]
|
|
|
144
144
|
rit whoami [--json]
|
|
145
145
|
rit clone <owner/repo|repo> [dir] [--json]
|
|
146
146
|
rit push [--private] [--name <name>] [--json]
|
|
147
|
+
rit export [--output <path>] [--nightly on|off] [--json]
|
|
147
148
|
rit help, --help, -h
|
|
148
149
|
rit --version, -v
|
|
149
150
|
```
|
|
150
151
|
|
|
152
|
+
**`rit export`** (RIT-RET, 2026-12-01): one archive of every repo you own --
|
|
153
|
+
real `git bundle --all` for each repo (and its wiki, if any; `git clone
|
|
154
|
+
<bundle>` reproduces the exact commits, no history rewriting), plus
|
|
155
|
+
issues/pulls/releases+assets as documented JSON (the engine's own public
|
|
156
|
+
API object shape). Same job as the one-click `https://rithub.dev/export`
|
|
157
|
+
page, just without the browser round trip. `rit export --nightly on`
|
|
158
|
+
opts into a 7-day-retained nightly copy kept server-side instead of
|
|
159
|
+
running an export now.
|
|
160
|
+
|
|
151
161
|
The full `gh`-parity surface added on top of it, every command taking
|
|
152
162
|
`--repo <owner/name>` to override inferring the repo from the current
|
|
153
163
|
directory's git remote, and `--json` for machine-readable output:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@recoder.xyz/rithub",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "A gh-style CLI for Rithub: full gh parity -- issue/change(pr)/release/branch/label/milestone/key/secret/webhook/org/user/search/status/browse/api, plus login/clone/repo/push and `rit init`'s no-human agent signup. One command, zero deps.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
package/src/cli.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { runLogin, runLogout, runWhoami } from "./auth.mjs";
|
|
|
3
3
|
import { runClone, runRepoCreate, runPush } from "./repo.mjs";
|
|
4
4
|
import { runWorkCommand, runRepoWorkCommand } from "./cli-work.mjs";
|
|
5
5
|
import { runPushApprove, runPushDeny, runPushStatus, runPushList, markAgentSessionIfNeeded } from "./push-approval.mjs";
|
|
6
|
+
import { runExport } from "./export.mjs";
|
|
6
7
|
|
|
7
8
|
const USAGE = `rit <command> [options] (alias: rithub)
|
|
8
9
|
|
|
@@ -39,6 +40,12 @@ const USAGE = `rit <command> [options] (alias: rithub)
|
|
|
39
40
|
a human to approve instead of landing.
|
|
40
41
|
push approve|deny|status <id> act on a held push/branch-delete
|
|
41
42
|
push list --owner <o> --repo <r> [--status pending|approved|denied]
|
|
43
|
+
export [--output <path>] one archive: every repo you own as a
|
|
44
|
+
real git bundle (+ wiki), issues/
|
|
45
|
+
pulls/releases+assets as documented
|
|
46
|
+
JSON. \`export --nightly on|off\`
|
|
47
|
+
toggles a 7-day-retained nightly copy
|
|
48
|
+
kept server-side instead of exporting.
|
|
42
49
|
|
|
43
50
|
repo <cmd> create|list|view|fork|delete|rename|edit|archive|sync|sync-now|import
|
|
44
51
|
issue <cmd> list|create|view|close|reopen|edit|comment
|
|
@@ -160,6 +167,19 @@ export async function main(argv, io) {
|
|
|
160
167
|
return 0;
|
|
161
168
|
}
|
|
162
169
|
|
|
170
|
+
if (command === "export") {
|
|
171
|
+
const args = parseFlags(rest, { valueFlags: ["--output", "--nightly", "--api-url"], boolFlags: ["--json"] });
|
|
172
|
+
const result = await runExport({ output: args.output, nightly: args.nightly, apiUrl: args.apiUrl }, io);
|
|
173
|
+
if (args.json) {
|
|
174
|
+
io.out(JSON.stringify(result));
|
|
175
|
+
} else if ("nightly" in result) {
|
|
176
|
+
io.out(`Nightly export copy ${result.nightly ? "enabled" : "disabled"}.`);
|
|
177
|
+
} else {
|
|
178
|
+
io.out(`Exported to ${result.output} (${result.size_bytes} bytes): ${result.totals?.repos ?? "?"} repo(s), ${result.totals?.issues ?? "?"} issue(s), ${result.totals?.pulls ?? "?"} pull(s), ${result.totals?.releases ?? "?"} release(s).`);
|
|
179
|
+
}
|
|
180
|
+
return 0;
|
|
181
|
+
}
|
|
182
|
+
|
|
163
183
|
if (command === "clone") {
|
|
164
184
|
const args = parseFlags(rest, { valueFlags: ["--api-url"], boolFlags: ["--json"] });
|
|
165
185
|
const [target, dir] = args._;
|
package/src/export.mjs
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// `rit export` -- RIT-RET (2026-12-01): the CLI half of the full account
|
|
2
|
+
// export (the other half is the one-click "Export your account" page at
|
|
3
|
+
// https://rithub.dev/export). Same job, same server
|
|
4
|
+
// (apps/rithub-export): this just saves a browser round trip for a
|
|
5
|
+
// caller that already has its own token. Polls until the archive is
|
|
6
|
+
// ready, then downloads it straight to disk.
|
|
7
|
+
import { writeFileSync } from "node:fs";
|
|
8
|
+
import { CliError, DEFAULT_API_URL } from "./init.mjs";
|
|
9
|
+
import { resolveSession } from "./config.mjs";
|
|
10
|
+
|
|
11
|
+
const POLL_INTERVAL_MS = 2000;
|
|
12
|
+
const MAX_WAIT_MS = 20 * 60_000; // a real multi-repo export can take a while; this is a ceiling, not a target
|
|
13
|
+
|
|
14
|
+
async function jsonCall(io, apiUrl, path, init, token) {
|
|
15
|
+
const res = await io.fetchImpl(`${apiUrl}${path}`, {
|
|
16
|
+
...init,
|
|
17
|
+
headers: { accept: "application/json", "user-agent": "rithub-cli", "content-type": "application/json", authorization: `token ${token}`, ...(init?.headers ?? {}) },
|
|
18
|
+
});
|
|
19
|
+
const text = await res.text();
|
|
20
|
+
let body = null;
|
|
21
|
+
try {
|
|
22
|
+
body = text ? JSON.parse(text) : null;
|
|
23
|
+
} catch {
|
|
24
|
+
body = { message: text.slice(0, 300) };
|
|
25
|
+
}
|
|
26
|
+
return { status: res.status, body };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function sleep(ms) {
|
|
30
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** `rit export [--output <path>] [--nightly on|off]`. With `--nightly`,
|
|
34
|
+
* just toggles the opt-in server-side nightly copy and returns -- no
|
|
35
|
+
* export runs. Otherwise starts one, polls `GET /export/api/jobs/:id`
|
|
36
|
+
* until `done`/`failed`, then downloads the finished archive. */
|
|
37
|
+
export async function runExport(options, io) {
|
|
38
|
+
const apiUrl = (options.apiUrl ?? io.env.RITHUB_API_URL ?? DEFAULT_API_URL).replace(/\/+$/, "");
|
|
39
|
+
const session = resolveSession(io, { apiUrl });
|
|
40
|
+
if (!session) throw new CliError("not logged in -- run `rit login`", { code: "not_logged_in" });
|
|
41
|
+
|
|
42
|
+
if (options.nightly) {
|
|
43
|
+
const enabled = options.nightly === "on";
|
|
44
|
+
const { status, body } = await jsonCall(io, apiUrl, "/export/api/nightly", { method: "POST", body: JSON.stringify({ enabled }) }, session.token);
|
|
45
|
+
if (status !== 200) throw new CliError(`could not set the nightly export preference (HTTP ${status}): ${body?.error ?? "unknown error"}`, { code: "export_failed" });
|
|
46
|
+
return { nightly: body.enabled };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const started = await jsonCall(io, apiUrl, "/export/api/start", { method: "POST" }, session.token);
|
|
50
|
+
if (started.status !== 202) {
|
|
51
|
+
throw new CliError(`could not start the export (HTTP ${started.status}): ${started.body?.error ?? "unknown error"}`, { code: "export_failed" });
|
|
52
|
+
}
|
|
53
|
+
const jobId = started.body.id;
|
|
54
|
+
io.out(`Export started (${jobId}), waiting...`);
|
|
55
|
+
|
|
56
|
+
const deadline = (io.now?.() ?? Date.now()) + MAX_WAIT_MS;
|
|
57
|
+
let job = null;
|
|
58
|
+
while ((io.now?.() ?? Date.now()) < deadline) {
|
|
59
|
+
await (io.sleep ?? sleep)(POLL_INTERVAL_MS);
|
|
60
|
+
const polled = await jsonCall(io, apiUrl, `/export/api/jobs/${jobId}`, { method: "GET" }, session.token);
|
|
61
|
+
if (polled.status !== 200) throw new CliError(`lost track of the export job (HTTP ${polled.status})`, { code: "export_failed" });
|
|
62
|
+
job = polled.body;
|
|
63
|
+
if (job.status === "done" || job.status === "failed") break;
|
|
64
|
+
}
|
|
65
|
+
if (!job || (job.status !== "done" && job.status !== "failed")) {
|
|
66
|
+
throw new CliError(`the export is still running after ${Math.round(MAX_WAIT_MS / 60000)} minutes -- check https://rithub.dev/export for status`, { code: "export_timeout" });
|
|
67
|
+
}
|
|
68
|
+
if (job.status === "failed") {
|
|
69
|
+
throw new CliError(`the export failed: ${job.error ?? "unknown error"}`, { code: "export_failed" });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const outputPath = options.output ?? `rithub-export-${session.username ?? "account"}-${jobId}.tar.gz`;
|
|
73
|
+
const res = await io.fetchImpl(`${apiUrl}/export/download/${jobId}`, { headers: { authorization: `token ${session.token}`, "user-agent": "rithub-cli" } });
|
|
74
|
+
if (res.status !== 200) throw new CliError(`could not download the finished archive (HTTP ${res.status})`, { code: "export_failed" });
|
|
75
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
76
|
+
writeFileSync(outputPath, buf);
|
|
77
|
+
return { id: jobId, output: outputPath, size_bytes: buf.length, totals: job.totals };
|
|
78
|
+
}
|