@recoder.xyz/rithub 0.2.1 → 0.3.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/src/status.mjs ADDED
@@ -0,0 +1,23 @@
1
+ // `rit status`: issues assigned to you, changes you opened, and changes
2
+ // waiting on your review, across every repo you can see -- the one gh-style
3
+ // command that is deliberately NOT scoped to a single `--repo`.
4
+ import { CliError } from "./init.mjs";
5
+ import { resolveSession } from "./config.mjs";
6
+ import { apiCall, buildQuery } from "./http.mjs";
7
+
8
+ async function search(io, apiUrl, token, params) {
9
+ const { status, body } = await apiCall(io, apiUrl, `/api/v1/repos/issues/search${buildQuery(params)}`, { method: "GET" }, token);
10
+ if (status !== 200) throw new CliError(`status lookup failed (HTTP ${status}): ${body?.message ?? "unknown error"}`, { code: "network_error" });
11
+ return (body ?? []).map((i) => ({ repository: i.repository?.full_name, number: i.number, title: i.title, html_url: i.html_url }));
12
+ }
13
+
14
+ export async function runStatus(options, io) {
15
+ const session = resolveSession(io, { apiUrl: options.apiUrl });
16
+ if (!session) throw new CliError("not logged in -- run `rit login` first", { code: "not_logged_in" });
17
+ const [assignedIssues, createdChanges, reviewRequested] = await Promise.all([
18
+ search(io, session.apiUrl, session.token, { type: "issues", state: "open", assigned: true, limit: 20 }),
19
+ search(io, session.apiUrl, session.token, { type: "pulls", state: "open", created: true, limit: 20 }),
20
+ search(io, session.apiUrl, session.token, { type: "pulls", state: "open", review_requested: true, limit: 20 }),
21
+ ]);
22
+ return { username: session.username, assignedIssues, createdChanges, reviewRequested };
23
+ }
@@ -0,0 +1,37 @@
1
+ // `rit webhook list/create`, against `/api/v1/repos/{owner}/{repo}/hooks`.
2
+ import { CliError } from "./init.mjs";
3
+ import { resolveRepoArg, requireSession } from "./repo-arg.mjs";
4
+ import { apiCall } from "./http.mjs";
5
+
6
+ function hooksPath(r) {
7
+ return `/api/v1/repos/${encodeURIComponent(r.owner)}/${encodeURIComponent(r.repo)}/hooks`;
8
+ }
9
+
10
+ export async function runWebhookList(options, io) {
11
+ const r = resolveRepoArg(io, options);
12
+ requireSession(r);
13
+ const { status, body } = await apiCall(io, r.apiUrl, hooksPath(r), { method: "GET" }, r.session.token);
14
+ if (status !== 200) throw new CliError(`could not list webhooks on ${r.owner}/${r.repo} (HTTP ${status}): ${body?.message ?? "unknown error"}`, { code: "network_error" });
15
+ return { owner: r.owner, repo: r.repo, webhooks: (body ?? []).map((h) => ({ id: h.id, url: h.config?.url, events: h.events, active: h.active })) };
16
+ }
17
+
18
+ /** `rit webhook create --url <url> [--events push,issues,pull_request] [--secret <text>]`. */
19
+ export async function runWebhookCreate(options, io) {
20
+ const r = resolveRepoArg(io, options);
21
+ requireSession(r);
22
+ if (!options.url) throw new CliError("`rit webhook create` needs --url <url>", { code: "invalid_argument" });
23
+ const events = (options.events ?? "push").split(",").map((e) => e.trim()).filter(Boolean);
24
+ const payload = {
25
+ // "rithub" (what its own API docs list for a plain JSON webhook) is
26
+ // rejected live with "Invalid hook type: rithub" -- confirmed
27
+ // 2026-12-01. "gogs" is the one from the same enum that the server
28
+ // actually accepts and sends the same JSON payload shape for.
29
+ type: "gogs",
30
+ active: true,
31
+ events,
32
+ config: { url: options.url, content_type: "json", ...(options.secret ? { secret: options.secret } : {}) },
33
+ };
34
+ const { status, body } = await apiCall(io, r.apiUrl, hooksPath(r), { method: "POST", body: JSON.stringify(payload) }, r.session.token);
35
+ if (status !== 201) throw new CliError(`could not create the webhook (HTTP ${status}): ${body?.message ?? "unknown error"}`, { code: "create_failed" });
36
+ return { owner: r.owner, repo: r.repo, id: body.id, url: options.url, events };
37
+ }