vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Let change update correct a request's title and description
12221a79f903723b8388c24ef6e1b850855e43b7 · Keenan Nemetz · 3d ago · parent d1c3b323
Let change update correct a request's title and description The metadata writer already replaces a request's prose without moving the base, head, or approvals, and it works after a request closes or merges. Expose that through --title and -m/-F, mirroring issue edit, and document the command. The new test holds the command to the metadata rule: an approval stays bound to the same commit across a prose edit.
server/change_prose_test.go +104
| @@ -0,0 +1,104 @@ | |||
| 1 | package server_test | ||
| 2 | |||
| 3 | // The title and description are prose, not what a review names: an approval | ||
| 4 | // names the base and head. `change update --title` and `-m`/`-F` therefore | ||
| 5 | // correct a request without starting the review over, and they stay possible | ||
| 6 | // after the request closes. The metadata writer already had this property; this | ||
| 7 | // holds the command line to it. | ||
| 8 | |||
| 9 | import ( | ||
| 10 | "strings" | ||
| 11 | "testing" | ||
| 12 | |||
| 13 | "rodent.software/vole/metadata" | ||
| 14 | ) | ||
| 15 | |||
| 16 | func TestChangeUpdateEditsProseWithoutTouchingReview(t *testing.T) { | ||
| 17 | t.Parallel() | ||
| 18 | f := newFixture(t) | ||
| 19 | writerKey := f.addWriter(t) | ||
| 20 | f.publish(f.repo) | ||
| 21 | |||
| 22 | base := workRepo(t, map[string]string{"readme.md": "v1\n"}) | ||
| 23 | if _, errs, err := f.git(base, "push", f.sshURL(f.repo), "main:refs/heads/main"); err != nil { | ||
| 24 | t.Fatalf("initial main: %s", errs) | ||
| 25 | } | ||
| 26 | |||
| 27 | work, head := f.cloneWithChange(t, map[string]string{"readme.md": "v2\n"}, "feature") | ||
| 28 | if _, errs, err := runGit(t, work, "checkout", "-q", "-b", "feature"); err != nil { | ||
| 29 | t.Fatalf("branch: %s", errs) | ||
| 30 | } | ||
| 31 | if _, errs, err := f.git(work, "push", f.sshURL(f.repo), "feature:refs/heads/feature"); err != nil { | ||
| 32 | t.Fatalf("feature push: %s", errs) | ||
| 33 | } | ||
| 34 | out, errs, err := f.cli(work, "change", "new", "--title", "Teh typo", | ||
| 35 | "--base", "main", "--head", "feature", "-m", "the first try") | ||
| 36 | if err != nil { | ||
| 37 | t.Fatalf("change new: %v\n%s", err, errs) | ||
| 38 | } | ||
| 39 | id := strings.Fields(out)[0] | ||
| 40 | |||
| 41 | // A maintainer approves the exact commit, so the edit has something to leave | ||
| 42 | // alone: the approval names the base and head, not the prose. | ||
| 43 | meta := f.newMetaRepo(t) | ||
| 44 | meta.key = writerKey | ||
| 45 | if err := meta.apply(map[string]string{ | ||
| 46 | "changes/" + id + "/approvals/" + f.accountName("wilbur") + ".md": approvalFile("main", head), | ||
| 47 | }, "approve"); err != nil { | ||
| 48 | t.Fatalf("approval push: %v", err) | ||
| 49 | } | ||
| 50 | |||
| 51 | out, errs, err = f.cli(work, "change", "update", id, "--title", "The typo", "-m", "the real reason") | ||
| 52 | if err != nil { | ||
| 53 | t.Fatalf("change update: %v\n%s", err, errs) | ||
| 54 | } | ||
| 55 | if !strings.Contains(out, "The typo") { | ||
| 56 | t.Fatalf("updated request was not printed:\n%s", out) | ||
| 57 | } | ||
| 58 | |||
| 59 | m := mustRepo(t, f) | ||
| 60 | got, err := metadata.GetRequest(m.Git(), id) | ||
| 61 | if err != nil { | ||
| 62 | t.Fatal(err) | ||
| 63 | } | ||
| 64 | if got.Title != "The typo" { | ||
| 65 | t.Fatalf("title = %q, want %q", got.Title, "The typo") | ||
| 66 | } | ||
| 67 | if strings.TrimSpace(got.Description) != "the real reason" { | ||
| 68 | t.Fatalf("description = %q", got.Description) | ||
| 69 | } | ||
| 70 | if got.Base != "main" || got.Head != head { | ||
| 71 | t.Fatalf("the prose edit moved the review: base=%q head=%q, want main/%s", got.Base, got.Head, head) | ||
| 72 | } | ||
| 73 | if len(got.Approvals) != 1 || got.Approvals[0].Head != head || got.Approvals[0].Base != "main" { | ||
| 74 | t.Fatalf("the prose edit changed the approvals: %+v", got.Approvals) | ||
| 75 | } | ||
| 76 | |||
| 77 | // The same edit is allowed after the request closes: a record with a typo is | ||
| 78 | // still worth fixing, and SetRequestDetails says so deliberately. | ||
| 79 | if _, errs, err := f.cli(work, "change", "close", id); err != nil { | ||
| 80 | t.Fatalf("change close: %v\n%s", err, errs) | ||
| 81 | } | ||
| 82 | if _, errs, err := f.cli(work, "change", "update", id, "--title", "The typo, fixed"); err != nil { | ||
| 83 | t.Fatalf("change update on a closed request: %v\n%s", err, errs) | ||
| 84 | } | ||
| 85 | got, err = metadata.GetRequest(m.Git(), id) | ||
| 86 | if err != nil { | ||
| 87 | t.Fatal(err) | ||
| 88 | } | ||
| 89 | if got.State != "closed" { | ||
| 90 | t.Fatalf("state = %q, want closed", got.State) | ||
| 91 | } | ||
| 92 | if got.Title != "The typo, fixed" { | ||
| 93 | t.Fatalf("closed title = %q", got.Title) | ||
| 94 | } | ||
| 95 | |||
| 96 | // A title cannot be emptied, and an edit that says nothing is a usage error | ||
| 97 | // rather than a commit that rewrites the record with the same bytes. | ||
| 98 | if _, errs, err := f.cli(work, "change", "update", id, "--title", " "); err == nil { | ||
| 99 | t.Fatalf("a blank title was accepted:\n%s", errs) | ||
| 100 | } | ||
| 101 | if _, errs, err := f.cli(work, "change", "update", id, "--title", "The typo, fixed"); err == nil { | ||
| 102 | t.Fatalf("an edit that changed nothing was accepted:\n%s", errs) | ||
| 103 | } | ||
| 104 | } | ||