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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15751-forge-tell-in-the-cli-files-a-tell-from → main 0 commits fork

  • Merged. scout/15751-forge-tell-in-the-cli-files-a-tell-from was merged into main as f9aff66.

Review

Sign in to review this change.
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> {
6969 const loaded = await requireConfig(out);
7070 if (typeof loaded === "number") return loaded;
7171 const ref = await resolveRepo(only, loaded.url);
72 const api = new ForgeApi(loaded.url, loaded.token);
7273 if (typeof ref === "string") {
7374 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 }
7485 return EXIT.usage;
7586 }
76 const told = await new ForgeApi(loaded.url, loaded.token).tell(
87 const told = await api.tell(
7788 ref.owner,
7889 ref.name,
7990 text,
test/cli-tell.test.ts +13
@@ -20,6 +20,8 @@ beforeAll(async () => {
2020 port: 0,
2121 async fetch(req) {
2222 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" }] });
2325 if (url.pathname !== "/api/v1/feed/tells" || req.method !== "POST")
2426 return Response.json({ error: "not_found", message: "no" }, { status: 404 });
2527 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 () => {
127129 const run = await forge(["tell", "hi"], join(dir, "other"));
128130 expect(run.code).toBe(EXIT.usage);
129131 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);
130143 });
131144
132145 test("a refusal prints the API's words and exits 1; a 401 exits 3", async () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs