Public: anyone can read this; the crew can change it.
A file edit's refusal words live in one module, src/actions/edit_words.ts, and the contents route reads them from there #5547
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/5544-a-file-edit-s-refusal-words-live-in-one → main 1 commit fork
3 files
changed +48
−19
src/actions/edit_words.ts added +23
| @@ -0,0 +1,23 @@ | ||
| 1 | /** | |
| 2 | * The words a file edit refuses in (#5544): one sentence per refusal kind, | |
| 3 | * so `POST …/contents` and any other door that writes a file say the same | |
| 4 | * thing for the same failure. | |
| 5 | */ | |
| 6 | export function editMessage(kind: string): string { | |
| 7 | switch (kind) { | |
| 8 | case "protected_branch": | |
| 9 | return "the default branch is protected; only a repo admin may commit to it directly"; | |
| 10 | case "file_too_large": | |
| 11 | return "that file is larger than an edit may carry; push it instead"; | |
| 12 | case "commit_too_large": | |
| 13 | return "the edit is larger than one commit may carry; push it instead"; | |
| 14 | case "branch_moved": | |
| 15 | return "the branch moved while this edit was being written; re-read and retry"; | |
| 16 | case "land_refused": | |
| 17 | return "the origin refused this commit; nothing was changed here either"; | |
| 18 | case "pull_failed": | |
| 19 | return "the commit landed, but the pull request could not be opened"; | |
| 20 | default: | |
| 21 | return "this edit could not be applied"; | |
| 22 | } | |
| 23 | } |
src/http/api.ts +1 −19
| @@ -71,6 +71,7 @@ import { | ||
| 71 | 71 | } from "../actions/accounts.ts"; |
| 72 | 72 | import { resendVerification } from "../actions/verify.ts"; |
| 73 | 73 | import { CAPPED_WORDS } from "../actions/mail.ts"; |
| 74 | import { editMessage } from "../actions/edit_words.ts"; | |
| 74 | 75 | import { emailVerified } from "../core/verify.ts"; |
| 75 | 76 | import { readHealth } from "../actions/health.ts"; |
| 76 | 77 | import { isProbe } from "../kernel/probe.ts"; |
| @@ -1004,25 +1005,6 @@ function contributeFailure(error: unknown): Response { | ||
| 1004 | 1005 | return originAware(code, 422); |
| 1005 | 1006 | } |
| 1006 | 1007 | |
| 1007 | function editMessage(kind: string): string { | |
| 1008 | switch (kind) { | |
| 1009 | case "protected_branch": | |
| 1010 | return "the default branch is protected; only a repo admin may commit to it directly"; | |
| 1011 | case "file_too_large": | |
| 1012 | return "that file is larger than an edit may carry; push it instead"; | |
| 1013 | case "commit_too_large": | |
| 1014 | return "the edit is larger than one commit may carry; push it instead"; | |
| 1015 | case "branch_moved": | |
| 1016 | return "the branch moved while this edit was being written; re-read and retry"; | |
| 1017 | case "land_refused": | |
| 1018 | return "the origin refused this commit; nothing was changed here either"; | |
| 1019 | case "pull_failed": | |
| 1020 | return "the commit landed, but the pull request could not be opened"; | |
| 1021 | default: | |
| 1022 | return "this edit could not be applied"; | |
| 1023 | } | |
| 1024 | } | |
| 1025 | ||
| 1026 | 1008 | // ---- query parsing ---- |
| 1027 | 1009 | |
| 1028 | 1010 | /** `?state=&label=&author=&limit=&cursor=` for issue and pull lists. */ |
test/edit-refusal-words.test.ts added +24
| @@ -0,0 +1,24 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { editMessage } from "../src/actions/edit_words.ts"; | |
| 3 | ||
| 4 | // Each refusal kind gives its exact sentence, so every door that writes a | |
| 5 | // file refuses in the same words (#5544). | |
| 6 | const WORDS: Array<[string, string]> = [ | |
| 7 | ["protected_branch", "the default branch is protected; only a repo admin may commit to it directly"], | |
| 8 | ["file_too_large", "that file is larger than an edit may carry; push it instead"], | |
| 9 | ["commit_too_large", "the edit is larger than one commit may carry; push it instead"], | |
| 10 | ["branch_moved", "the branch moved while this edit was being written; re-read and retry"], | |
| 11 | ["land_refused", "the origin refused this commit; nothing was changed here either"], | |
| 12 | ["pull_failed", "the commit landed, but the pull request could not be opened"], | |
| 13 | ]; | |
| 14 | ||
| 15 | for (const [kind, sentence] of WORDS) { | |
| 16 | test(`editMessage(${kind}) says its sentence`, () => { | |
| 17 | expect(editMessage(kind)).toBe(sentence); | |
| 18 | }); | |
| 19 | } | |
| 20 | ||
| 21 | test("an unknown kind falls back to the default sentence", () => { | |
| 22 | expect(editMessage("something_else")).toBe("this edit could not be applied"); | |
| 23 | expect(editMessage("")).toBe("this edit could not be applied"); | |
| 24 | }); |
new above
offline