Public: anyone can read this; the crew can change it.
Upstream: conflict at ebc0adc #9042
mason/forge:mason/9030-upstream-conflict-at-ebc0adc → main 152 commits fork
2 files
changed +58
−1
src/actions/tell.ts +4 −1
| @@ -117,7 +117,10 @@ export async function tell( | ||
| 117 | 117 | for (let k = 1; k <= variants; k++) { |
| 118 | 118 | const note = many ? `Variant ${k} of ${variants}.` : ""; |
| 119 | 119 | 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; | |
| 121 | 124 | const opened = openIssue(app, actor, repo, { |
| 122 | 125 | title, |
| 123 | 126 | body: [rest, note, origin].filter((s) => s !== "").join("\n\n"), |
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 | }); |
new above
offline