- commit
- e33f7d3
- parent
- c2d9e74
- author
- Eric Bower
- date
- 2024-12-23 22:57:29 -0500 EST
feat: dedicated range-diff page
3 files changed,
+83,
-34
+6,
-18
1@@ -61,7 +61,7 @@
2 {{range .Patchsets}}
3 {{if .RangeDiff}}
4 <details>
5- <summary class="text-sm">Range Diff ↕</summary>
6+ <summary class="text-sm">Range Diff ↕ <code><a href="/rd/{{.ID}}">rd-{{.ID}}</a></code></summary>
7 <div class="group">
8 {{- range .RangeDiff -}}
9 <div>
10@@ -69,22 +69,6 @@
11 {{.Header}}
12 </code>
13 </div>
14- {{- if .Diff -}}
15- <details class="interdiff">
16- <summary class="text-sm">Summary</summary>
17- <div><pre>
18- {{- range .Diff -}}
19- {{- if eq .Type -1 -}}
20- <span style="color: tomato;">{{.Text}}</span>
21- {{- else if eq .Type 1 -}}
22- <span style="color: limegreen;">{{.Text}}</span>
23- {{- else -}}
24- <span>{{.Text}}</span>
25- {{- end -}}
26- {{- end -}}
27- </pre></div>
28- </details>
29- {{- end -}}
30 {{- end -}}
31 </div>
32 </details>
33@@ -106,6 +90,10 @@
34
35 <hr class="w-full" />
36
37- {{template "patchset" .}}
38+ {{if .IsRangeDiff}}
39+ {{template "range-diff" .}}
40+ {{else}}
41+ {{template "patchset" .}}
42+ {{end}}
43 </main>
44 {{end}}
+50,
-0
1@@ -0,0 +1,50 @@
2+{{define "range-diff"}}
3+<div class="group">
4+ <div class="flex gap-2 collapse">
5+ <div class="group patchset-list" style="width: 350px;">
6+ <h2 class="text-xl mt">
7+ Range-diff <code>rd-{{.Patchset.ID}}</code>
8+ </h2>
9+
10+ {{range $diff := .PatchsetData.RangeDiff}}
11+ <div>
12+ <a href="#{{$diff.Header}}">{{$diff.Header}}</a>
13+ </div>
14+ {{else}}
15+ <div class="box">
16+ No range diff found for patchset.
17+ </div>
18+ {{end}}
19+
20+ <div><a href="#top">Back to top</a></div>
21+ </div>
22+
23+ <div class="max-w flex-1">
24+ <div class="group">
25+ {{range .PatchsetData.RangeDiff}}
26+ <div class="group" id="{{.Header}}">
27+ <div>
28+ <code class='{{if eq .Type "rm"}}pill-admin{{else if eq .Type "add"}}pill-success{{else if eq .Type "diff"}}pill-review{{end}}'>
29+ {{.Header}}
30+ </code>
31+ </div>
32+ {{- if .Diff -}}
33+ <pre>{{- range .Diff -}}
34+ {{- if eq .Type -1 -}}
35+ <span style="color: tomato;">{{.Text}}</span>
36+ {{- else if eq .Type 1 -}}
37+ <span style="color: limegreen;">{{.Text}}</span>
38+ {{- else -}}
39+ <span>{{.Text}}</span>
40+ {{- end -}}
41+ {{- end -}}</pre>
42+ {{- end -}}
43+ </div>
44+ {{- end -}}
45+ </div>
46+
47+ <hr class="my" />
48+ </div>
49+ </div>
50+</div>
51+{{end}}
M
web.go
+27,
-16
1@@ -83,6 +83,7 @@ func getTemplate(file string) *template.Template {
2 filepath.Join("tmpl", file),
3 filepath.Join("tmpl", "user-pill.html"),
4 filepath.Join("tmpl", "patchset.html"),
5+ filepath.Join("tmpl", "range-diff.html"),
6 filepath.Join("tmpl", "pr-header.html"),
7 filepath.Join("tmpl", "pr-list-item.html"),
8 filepath.Join("tmpl", "pr-table.html"),
9@@ -472,14 +473,16 @@ type PatchsetData struct {
10 }
11
12 type PrDetailData struct {
13- Page string
14- Repo LinkData
15- Pr PrData
16- Patchset *Patchset
17- Patches []PatchData
18- Branch string
19- Logs []EventLogData
20- Patchsets []PatchsetData
21+ Page string
22+ Repo LinkData
23+ Pr PrData
24+ Patchset *Patchset
25+ PatchsetData *PatchsetData
26+ Patches []PatchData
27+ Branch string
28+ Logs []EventLogData
29+ Patchsets []PatchsetData
30+ IsRangeDiff bool
31 MetaData
32 }
33
34@@ -507,7 +510,7 @@ func createPrDetail(page string) http.HandlerFunc {
35 w.WriteHeader(http.StatusInternalServerError)
36 return
37 }
38- } else if page == "ps" {
39+ } else if page == "ps" || page == "rd" {
40 ps, err = web.Pr.GetPatchsetByID(int64(prID))
41 if err != nil {
42 web.Pr.Backend.Logger.Error("cannot get patchset", "err", err)
43@@ -532,6 +535,7 @@ func createPrDetail(page string) http.HandlerFunc {
44
45 // get patchsets and diff from previous patchset
46 patchsetsData := []PatchsetData{}
47+ var selectedPatchsetData *PatchsetData
48 for idx, patchset := range patchsets {
49 user, err := web.Pr.GetUserByID(patchset.UserID)
50 if err != nil {
51@@ -565,7 +569,7 @@ func createPrDetail(page string) http.HandlerFunc {
52 ps = patchset
53 }
54
55- patchsetsData = append(patchsetsData, PatchsetData{
56+ data := PatchsetData{
57 Patchset: patchset,
58 FormattedID: getFormattedPatchsetID(patchset.ID),
59 UserData: UserData{
60@@ -577,7 +581,11 @@ func createPrDetail(page string) http.HandlerFunc {
61 },
62 Date: patchset.CreatedAt.Format(time.RFC3339),
63 RangeDiff: rangeDiff,
64- })
65+ }
66+ patchsetsData = append(patchsetsData, data)
67+ if ps.ID == patchset.ID {
68+ selectedPatchsetData = &data
69+ }
70 }
71
72 patchesData := []PatchData{}
73@@ -754,11 +762,13 @@ func createPrDetail(page string) http.HandlerFunc {
74 Url: template.URL(url),
75 Text: repoNs,
76 },
77- Branch: "main",
78- Patchset: ps,
79- Patches: patchesData,
80- Patchsets: patchsetsData,
81- Logs: logData,
82+ Branch: "main",
83+ Patchset: ps,
84+ PatchsetData: selectedPatchsetData,
85+ IsRangeDiff: page == "rd",
86+ Patches: patchesData,
87+ Patchsets: patchsetsData,
88+ Logs: logData,
89 Pr: PrData{
90 ID: pr.ID,
91 UserData: UserData{
92@@ -1030,6 +1040,7 @@ func StartWebServer(cfg *GitCfg) {
93 http.HandleFunc("GET /prs/{id}", ctxMdw(ctx, createPrDetail("pr")))
94 http.HandleFunc("GET /prs/{id}/rss", ctxMdw(ctx, rssHandler))
95 http.HandleFunc("GET /ps/{id}", ctxMdw(ctx, createPrDetail("ps")))
96+ http.HandleFunc("GET /rd/{id}", ctxMdw(ctx, createPrDetail("rd")))
97 http.HandleFunc("GET /r/{user}/{repo}/rss", ctxMdw(ctx, rssHandler))
98 http.HandleFunc("GET /r/{user}/{repo}", ctxMdw(ctx, repoDetailHandler))
99 http.HandleFunc("GET /r/{user}", ctxMdw(ctx, userDetailHandler))