Public: anyone can read this; the crew can change it.
`forge tell` in the CLI files a tell from the terminal with the current repository as context #15779
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15751-forge-tell-in-the-cli-files-a-tell-from → main 0 commits fork
3 files
changed +34
−1
docs/features/cli-tell-which-app.md added +9
| @@ -0,0 +1,9 @@ | ||
| 1 | --- | |
| 2 | topic: Tell the crew | |
| 3 | row: forge tell asks which app when the folder has no repository | |
| 4 | --- | |
| 5 | # `forge tell` with no repository lists your apps | |
| 6 | ||
| 7 | `forge tell "words"` files a tell on the repository of the current directory and prints the issue number and link. When the folder has no repository on this forge, it exits 2, says why, and lists your apps (`which app? your apps:`) so the next command is `--repo owner/name`. | |
| 8 | ||
| 9 | - Code: `src/cli/commands/tell.ts`; tests in `test/cli-tell.test.ts`. |
src/cli/commands/tell.ts +12 −1
| @@ -69,11 +69,22 @@ async function tell(out: Out, args: Args): Promise<number> { | ||
| 69 | 69 | const loaded = await requireConfig(out); |
| 70 | 70 | if (typeof loaded === "number") return loaded; |
| 71 | 71 | const ref = await resolveRepo(only, loaded.url); |
| 72 | const api = new ForgeApi(loaded.url, loaded.token); | |
| 72 | 73 | if (typeof ref === "string") { |
| 73 | 74 | out.err(`forge tell: ${ref}`); |
| 75 | // No repository here: ask which app, listing the ones the person has. | |
| 76 | if (only === undefined) { | |
| 77 | const apps = await api.pins(); | |
| 78 | if (apps.ok && apps.value.length > 0) { | |
| 79 | out.err("which app? your apps:"); | |
| 80 | for (const a of apps.value.slice(0, 20)) | |
| 81 | out.err(` ${inert(`${a.owner}/${a.name}`)}`); | |
| 82 | out.err('then: forge tell "words" --repo owner/name'); | |
| 83 | } | |
| 84 | } | |
| 74 | 85 | return EXIT.usage; |
| 75 | 86 | } |
| 76 | const told = await new ForgeApi(loaded.url, loaded.token).tell( | |
| 87 | const told = await api.tell( | |
| 77 | 88 | ref.owner, |
| 78 | 89 | ref.name, |
| 79 | 90 | text, |
test/cli-tell.test.ts +13
| @@ -20,6 +20,8 @@ beforeAll(async () => { | ||
| 20 | 20 | port: 0, |
| 21 | 21 | async fetch(req) { |
| 22 | 22 | const url = new URL(req.url); |
| 23 | if (url.pathname === "/api/v1/user/pins") | |
| 24 | return Response.json({ items: [{ owner: "alice", name: "shop" }, { owner: "alice", name: "blog" }] }); | |
| 23 | 25 | if (url.pathname !== "/api/v1/feed/tells" || req.method !== "POST") |
| 24 | 26 | return Response.json({ error: "not_found", message: "no" }, { status: 404 }); |
| 25 | 27 | seen.push({ auth: req.headers.get("authorization"), body: await req.json() }); |
| @@ -127,6 +129,17 @@ test("an origin elsewhere asks for --repo and exits 2", async () => { | ||
| 127 | 129 | const run = await forge(["tell", "hi"], join(dir, "other")); |
| 128 | 130 | expect(run.code).toBe(EXIT.usage); |
| 129 | 131 | expect(run.err).toContain("--repo"); |
| 132 | expect(run.err).toContain("which app?"); | |
| 133 | expect(run.err).toContain("alice/shop"); | |
| 134 | expect(run.err).toContain("alice/blog"); | |
| 135 | }); | |
| 136 | ||
| 137 | test("an oversized text is refused with the reason, without a request", async () => { | |
| 138 | const before = seen.length; | |
| 139 | const run = await forge(["tell", "x".repeat(5000)]); | |
| 140 | expect(run.code).toBe(EXIT.usage); | |
| 141 | expect(run.err).toContain("1 to"); | |
| 142 | expect(seen.length).toBe(before); | |
| 130 | 143 | }); |
| 131 | 144 | |
| 132 | 145 | test("a refusal prints the API's words and exits 1; a 401 exits 3", async () => { |
new above
offline