Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

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.

Show every commit of a change request, paginated

ea92d7546124954c790c34f3f7655c35cb70bf76 · Keenan Nemetz · 1d ago · parent 31560d91

Show every commit of a change request, paginated

The request page showed the diff and the runs but not the commits the branch
is made of, so a reviewer who reads commit by commit had to leave it for the
repository history. Add a Commits tab that lists them oldest first, each
linking to its commit page.

Page the list with the existing pager rather than cutting it at a fixed
count: a long branch keeps every commit and a page step swaps only the list.
While the request is open the range is base..head; once landed it starts at
the recorded pre-landing base, so the commits that were reviewed remain
visible and the landing merge commit is not listed as one of them.

server/issues_changes_test.go +117

@@ -987,6 +987,123 @@ func TestRequestFilesListsEveryChangedFile(t *testing.T) {
987 987 }
988 988 }
989 989
990 // TestRequestCommitsTabPaginatesTheBranch: the Commits tab lists every commit a
991 // change carries in review order, one page at a time. A branch longer than a
992 // page keeps its tail instead of being cut at a fixed count, and a page step
993 // returns the list fragment rather than reloading the review.
994 func TestRequestCommitsTabPaginatesTheBranch(t *testing.T) {
995 t.Parallel()
996 // The handler's requestCommitPageSize; a test in this package cannot see it,
997 // and the branch is built to cross one page and then some.
998 const commitPageSize = 50
999 f := newFixture(t)
1000 f.publish(f.repo)
1001
1002 base := workRepo(t, map[string]string{"readme.md": "v0\n"})
1003 if _, errs, err := f.git(base, "push", f.sshURL(f.repo), "main:refs/heads/main"); err != nil {
1004 t.Fatalf("main push: %s", errs)
1005 }
1006 feature, head := f.cloneWithChange(t, map[string]string{"readme.md": "v1\n"}, "commit 1")
1007 commits := []string{head}
1008 for i := 2; i <= 55; i++ {
1009 if err := os.WriteFile(filepath.Join(feature, "readme.md"), []byte("v"+strconv.Itoa(i)+"\n"), 0o644); err != nil {
1010 t.Fatal(err)
1011 }
1012 if _, errs, err := runGit(t, feature, "add", "-A"); err != nil {
1013 t.Fatalf("add commit %d: %v: %s", i, err, errs)
1014 }
1015 if _, errs, err := runGit(t, feature, "commit", "-qm", "commit "+strconv.Itoa(i)); err != nil {
1016 t.Fatalf("commit %d: %v: %s", i, err, errs)
1017 }
1018 out, _, _ := runGit(t, feature, "rev-parse", "HEAD")
1019 commits = append(commits, strings.TrimSpace(out))
1020 }
1021 if _, errs, err := f.git(feature, "push", f.sshURL(f.repo), "HEAD:refs/heads/feature"); err != nil {
1022 t.Fatalf("feature push: %s", errs)
1023 }
1024
1025 sess, cookie := f.browserSession(t, f.ownerID)
1026 resp, body := f.browserPost(t, "/"+f.repo+"/changes", cookie, url.Values{
1027 "csrf": {sess.CSRF}, "title": {"The whole branch"}, "body": {"body\n"},
1028 "base": {"main"}, "head": {"feature"},
1029 })
1030 if resp.StatusCode != http.StatusSeeOther {
1031 t.Fatalf("create change: %d\n%s", resp.StatusCode, body)
1032 }
1033 id := strings.TrimPrefix(resp.Header.Get("Location"), "/"+f.repo+"/changes/")
1034 commitsURL := "/" + f.repo + "/changes/" + id + "/commits"
1035
1036 // The conversation page carries the tab, so a reviewer can find the list.
1037 _, page := f.browserGet(t, "/"+f.repo+"/changes/"+id, cookie)
1038 if !strings.Contains(page, `href="`+commitsURL+`"`) {
1039 t.Fatalf("the request tabs do not link to the commits tab:\n%s", page)
1040 }
1041
1042 // Page one is the first 50 commits, oldest first, with links to each commit.
1043 resp, page = f.browserGet(t, commitsURL, cookie)
1044 if resp.StatusCode != http.StatusOK {
1045 t.Fatalf("commits tab = %d\n%s", resp.StatusCode, page)
1046 }
1047 if got := strings.Count(page, `<td class="sha"><a href="/`+f.repo+`/commit/`); got != commitPageSize {
1048 t.Fatalf("page one lists %d commits, want %d:\n%.3000s", got, commitPageSize, page)
1049 }
1050 for _, sha := range []string{commits[0], commits[commitPageSize-1]} {
1051 if !strings.Contains(page, "/"+f.repo+"/commit/"+sha) {
1052 t.Errorf("page one is missing commit %s", sha)
1053 }
1054 }
1055 if strings.Contains(page, "/"+f.repo+"/commit/"+commits[commitPageSize]) {
1056 t.Errorf("page one includes commit %s, which belongs on page two", commits[commitPageSize])
1057 }
1058 if i, j := strings.Index(page, commits[0]), strings.Index(page, commits[commitPageSize-1]); i < 0 || j < 0 || i > j {
1059 t.Errorf("page one is not oldest first")
1060 }
1061 if !strings.Contains(page, "page 1 of 2") || !strings.Contains(page, "of 55") {
1062 t.Errorf("page one has no pager for the whole branch:\n%.3000s", page)
1063 }
1064
1065 // Page two is the tail, not a truncation: the last commit is still reachable.
1066 resp, page = f.browserGet(t, commitsURL+"?page=2", cookie)
1067 if resp.StatusCode != http.StatusOK {
1068 t.Fatalf("commits page two = %d\n%s", resp.StatusCode, page)
1069 }
1070 if got := strings.Count(page, `<td class="sha"><a href="/`+f.repo+`/commit/`); got != 5 {
1071 t.Fatalf("page two lists %d commits, want 5:\n%.3000s", got, page)
1072 }
1073 if !strings.Contains(page, "/"+f.repo+"/commit/"+commits[54]) {
1074 t.Errorf("page two is missing the last commit %s", commits[54])
1075 }
1076 if !strings.Contains(page, "page 2 of 2") {
1077 t.Errorf("page two has no pager:\n%.3000s", page)
1078 }
1079 if strings.Contains(page, "/"+f.repo+"/commit/"+commits[49]) {
1080 t.Errorf("page two repeats commit %s from page one", commits[49])
1081 }
1082
1083 // A page step swaps the list only, so the review around it stays put.
1084 resp, piece := f.htmxGet(t, commitsURL+"?page=2", cookie)
1085 if resp.StatusCode != http.StatusOK || strings.Contains(piece, "<!doctype html>") ||
1086 !strings.Contains(piece, `id="request-commits"`) || !strings.Contains(piece, `hx-target="#request-commits"`) {
1087 t.Fatalf("commits fragment = %d:\n%s", resp.StatusCode, piece)
1088 }
1089 if !strings.Contains(piece, "/"+f.repo+"/commit/"+commits[54]) {
1090 t.Errorf("the fragment is missing the last commit")
1091 }
1092
1093 // Once landed, the range still names the commits the request carried rather
1094 // than emptying out against the branch that now contains them.
1095 resp, body = f.browserPost(t, "/"+f.repo+"/changes/"+id+"/merge", cookie,
1096 url.Values{"csrf": {sess.CSRF}})
1097 if resp.StatusCode != http.StatusSeeOther {
1098 t.Fatalf("merge: %d\n%s", resp.StatusCode, body)
1099 }
1100 resp, page = f.browserGet(t, commitsURL, cookie)
1101 if resp.StatusCode != http.StatusOK || !strings.Contains(page, "of 55") ||
1102 !strings.Contains(page, "/"+f.repo+"/commit/"+commits[0]) {
1103 t.Fatalf("a landed change lost its commits: %d\n%.3000s", resp.StatusCode, page)
1104 }
1105 }
1106
990 1107 func TestLineAnchoredReviewCommentFromTheWeb(t *testing.T) {
991 1108 t.Parallel()
992 1109 f := newFixture(t)