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/web/request_commits.go +105
| @@ -0,0 +1,105 @@ | |||
| 1 | package web | ||
| 2 | |||
| 3 | // The Commits tab lists the commits a change request carries, oldest first, so | ||
| 4 | // a reviewer can read the branch the way it was written and open any commit on | ||
| 5 | // its own page. It is a list, not a second diff: the commit page already owns | ||
| 6 | // the files and the patch. | ||
| 7 | |||
| 8 | import ( | ||
| 9 | "net/http" | ||
| 10 | "strconv" | ||
| 11 | "strings" | ||
| 12 | |||
| 13 | "rodent.software/vole/core/git" | ||
| 14 | "rodent.software/vole/metadata" | ||
| 15 | ) | ||
| 16 | |||
| 17 | // requestCommitPageSize is how many commits one page of the change shows. A | ||
| 18 | // commit row is one line, so a page can hold more than the issue and change | ||
| 19 | // lists without becoming a scroll. | ||
| 20 | const requestCommitPageSize = 50 | ||
| 21 | |||
| 22 | // requestCommitsView is the Commits tab: the page of commits and the pager that | ||
| 23 | // says where in the branch they sit. | ||
| 24 | type requestCommitsView struct { | ||
| 25 | requestSidebarView | ||
| 26 | Tab string | ||
| 27 | Commits []git.Commit | ||
| 28 | Pager pager | ||
| 29 | } | ||
| 30 | |||
| 31 | // RequestCommits serves the Commits tab for one change. Pagination swaps only | ||
| 32 | // the list, so a reviewer keeps the request header, tabs, and sidebar in place | ||
| 33 | // while stepping through the branch. | ||
| 34 | func (w *Web) RequestCommits(rw http.ResponseWriter, r *http.Request) { | ||
| 35 | m, ok := w.open(rw, r) | ||
| 36 | if !ok { | ||
| 37 | return | ||
| 38 | } | ||
| 39 | req, err := w.requestAt(memoOf(r), m, r.PathValue("id")) | ||
| 40 | if err != nil { | ||
| 41 | w.notFound(rw, r) | ||
| 42 | return | ||
| 43 | } | ||
| 44 | |||
| 45 | change := w.reviewDiff(m, req) | ||
| 46 | commits, err := requestCommits(m.Git(), req, change) | ||
| 47 | if err != nil { | ||
| 48 | w.Logger("request commits %s: %v", req.ID, err) | ||
| 49 | } | ||
| 50 | page, _ := strconv.Atoi(r.URL.Query().Get("page")) | ||
| 51 | pg := newPager(len(commits), requestCommitPageSize, page, func(n int) string { | ||
| 52 | return requestCommitsURL(m.Name, req.ID, n) | ||
| 53 | }).forSwap("Commit pages", "#request-commits") | ||
| 54 | from, to := pg.rows() | ||
| 55 | commits = commits[from:to] | ||
| 56 | |||
| 57 | view := requestCommitsView{ | ||
| 58 | requestSidebarView: w.requestSidebar(r, m, req, "commits", "").withLanding(w.landingFrom(m, req, change)), | ||
| 59 | Tab: "commits", | ||
| 60 | Commits: commits, | ||
| 61 | Pager: pg, | ||
| 62 | } | ||
| 63 | if htmxRequest(r) { | ||
| 64 | w.render(rw, "request_commit_list", view, 0) | ||
| 65 | return | ||
| 66 | } | ||
| 67 | w.render(rw, "request_commits", view, 0) | ||
| 68 | } | ||
| 69 | |||
| 70 | // requestCommits lists the commits a request carries, oldest first. While the | ||
| 71 | // request is open that is the base..head range; once it has merged, the range | ||
| 72 | // starts at the recorded pre-landing base and stops at the head, so the landing | ||
| 73 | // merge commit is not shown as part of what was reviewed. | ||
| 74 | func requestCommits(g *git.Repo, req *metadata.Request, change reviewChange) ([]git.Commit, error) { | ||
| 75 | from, to, ok := requestCommitRange(req, change) | ||
| 76 | if !ok { | ||
| 77 | return nil, nil | ||
| 78 | } | ||
| 79 | return g.LogRange(from, to) | ||
| 80 | } | ||
| 81 | |||
| 82 | // requestCommitRange names the ends of the range the Commits tab lists. An open | ||
| 83 | // request's inventory is the three-dot range string; a landed one keeps the base | ||
| 84 | // tip that was the "before" side of the landing. A landed request written before | ||
| 85 | // merged_base existed has no range to show: the whole history is not its change. | ||
| 86 | func requestCommitRange(req *metadata.Request, change reviewChange) (from, to string, ok bool) { | ||
| 87 | if req.Head == "" { | ||
| 88 | return "", "", false | ||
| 89 | } | ||
| 90 | if base, head, cut := strings.Cut(change.From, "..."); cut { | ||
| 91 | return base, head, true | ||
| 92 | } | ||
| 93 | if change.From == "" || change.To == "" { | ||
| 94 | return "", "", false | ||
| 95 | } | ||
| 96 | return change.From, req.Head, true | ||
| 97 | } | ||
| 98 | |||
| 99 | func requestCommitsURL(name, id string, page int) string { | ||
| 100 | u := "/" + name + "/changes/" + id + "/commits" | ||
| 101 | if page > 1 { | ||
| 102 | u += "?page=" + strconv.Itoa(page) | ||
| 103 | } | ||
| 104 | return u | ||
| 105 | } | ||