Public: anyone can read this; the crew can change it.

Upstream: conflict at ebc0adc #9035

Closed opened this in answer to
Closed without merging

mason/forge:mason/9030-upstream-conflict-at-ebc0adc → main 151 commits fork 1 thread · 1 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
2 files changed +66 −2
src/actions/tell.ts +12 −2
@@ -117,7 +117,10 @@ export async function tell(
117117 for (let k = 1; k <= variants; k++) {
118118 const note = many ? `Variant ${k} of ${variants}.` : "";
119119 const origin = from === null ? "" : `Told from [${from}](${from})`;
120 const rest = text === firstLine ? "" : text;
120 // The body is what follows the title; a title cut short keeps the
121 // whole text in the body, so nothing said is lost.
122 const rest =
123 title === firstLine ? text.slice(firstLine.length).trim() : text;
outdated

text starts with firstLine (both trimmed), so indexOf is always 0. Use text.slice(firstLine.length).trim().

121124 const opened = openIssue(app, actor, repo, {
122125 title,
123126 body: [rest, note, origin].filter((s) => s !== "").join("\n\n"),
@@ -145,7 +148,14 @@ export async function tell(
145148 return ok(told());
146149
147150 function told(): Told {
148 return { issue: issues[0]!, routed, assigned, issues, assignedNumbers, variantGroup };
151 return {
152 issue: issues[0]!,
153 routed,
154 assigned,
155 issues,
156 assignedNumbers,
157 variantGroup,
158 };
149159 }
150160 }
151161
test/tell-body.test.ts added +54
@@ -0,0 +1,54 @@
1 /**
2 * An issue opened by a tell keeps its title out of its body: the body is
3 * what follows the first line, as Open issue would file it. A title cut
4 * short keeps the whole text in the body.
5 */
6 import { afterAll, beforeAll, expect, test } from "bun:test";
7 import { mkdtemp, rm } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { createApp, type App } from "../src/app.ts";
11 import { createRepo } from "../src/actions/repos.ts";
12 import { tell } from "../src/actions/tell.ts";
13 import type { Repo } from "../src/core/repos.ts";
14 import type { User } from "../src/core/users.ts";
15 import { seedAdmin } from "./helpers/admin.ts";
16 import { quietLogs } from "./helpers/globals.ts";
17
18 quietLogs();
19
20 let dataDir: string;
21 let app: App;
22 let alice: User;
23 let repo: Repo;
24
25 beforeAll(async () => {
26 dataDir = await mkdtemp(join(tmpdir(), "forge-tell-body-"));
27 app = createApp({ dataDir, port: 0 });
28 const a = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-long-tell-passphrase" });
29 if (!a.ok) throw new Error("signup failed");
30 alice = a.value;
31 const made = await createRepo(app, alice, { name: "notes", visibility: "public" });
32 if (!made.ok) throw new Error("repo failed");
33 repo = made.value;
34 });
35
36 afterAll(async () => {
37 app.close();
38 await rm(dataDir, { recursive: true, force: true });
39 });
40
41 test("the body does not repeat the title", async () => {
42 const told = await tell(app, alice, repo, "Make it purple\n\nThe header only.");
43 if (!told.ok) throw new Error(String(told.error));
44 expect(told.value.issue.title).toBe("Make it purple");
45 expect(told.value.issue.body).toBe("The header only.");
46 });
47
48 test("a title cut short keeps the whole text in the body", async () => {
49 const long = `${"word ".repeat(30).trim()}\n\nMore.`;
50 const told = await tell(app, alice, repo, long);
51 if (!told.ok) throw new Error(String(told.error));
52 expect(told.value.issue.title.endsWith("…")).toBe(true);
53 expect(told.value.issue.body).toBe(long);
54 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs