- commit
- 0f000c7
- parent
- b023fc7
- author
- Eric Bower
- date
- 2024-12-27 22:39:31 -0500 EST
style: range-diff long-form patch descriptions
2 files changed,
+54,
-24
+27,
-7
1@@ -7,12 +7,32 @@
2 </h2>
3
4 {{range $diff := .PatchsetData.RangeDiff}}
5- <div>
6- <a href="#{{$diff.Header}}">
7- <code class='{{if eq $diff.Type "rm"}}pill-admin{{else if eq $diff.Type "add"}}pill-success{{else if eq $diff.Type "diff"}}pill-review{{end}}'>
8- {{$diff.Header}}
9- </code>
10- </a>
11+ <div class="box">
12+ <dl>
13+ <dt>title</dt>
14+ <dd><a href="#{{$diff.Header.OldIdx}}-{{$diff.Header.NewIdx}}">{{$diff.Header.Title}}</a></dd>
15+
16+ <dt>description</dt>
17+ <dd>
18+ <code class='{{if eq $diff.Type "rm"}}pill-admin{{else if eq $diff.Type "add"}}pill-success{{else if eq $diff.Type "diff"}}pill-review{{end}}'>
19+ {{if eq $diff.Header.NewSha ""}}
20+ Patch removed
21+ {{else if eq $diff.Header.OldSha ""}}
22+ Patch added
23+ {{else if $diff.Header.ContentEqual}}
24+ Patch equal
25+ {{else}}
26+ Patch changed
27+ {{end}}
28+ </code>
29+ </dd>
30+
31+ <dt>old #{{$diff.Header.OldIdx}}</dt>
32+ <dd><code>{{sha $diff.Header.OldSha}}</code></dd>
33+
34+ <dt>new #{{$diff.Header.NewIdx}}</dt>
35+ <dd><code>{{sha $diff.Header.NewSha}}</code></dd>
36+ </dl>
37 </div>
38 {{else}}
39 <div class="box">
40@@ -26,7 +46,7 @@
41 <div class="max-w flex-1">
42 <div class="group">
43 {{range .PatchsetData.RangeDiff}}
44- <div class="group" id="{{.Header}}">
45+ <div class="group" id="{{.Header.OldIdx}}-{{.Header.NewIdx}}">
46 <div>
47 <code class='{{if eq .Type "rm"}}pill-admin{{else if eq .Type "add"}}pill-success{{else if eq .Type "diff"}}pill-review{{end}}'>
48 {{.Header}}
M
web.go
+27,
-17
1@@ -76,21 +76,31 @@ func ctxMdw(ctx context.Context, handler http.HandlerFunc) http.HandlerFunc {
2 }
3 }
4
5+func shaFn(sha string) string {
6+ if sha == "" {
7+ return "(none)"
8+ }
9+ return truncateSha(sha)
10+}
11+
12 func getTemplate(file string) *template.Template {
13- tmpl := template.Must(
14- template.ParseFS(
15- tmplFS,
16- filepath.Join("tmpl", file),
17- filepath.Join("tmpl", "user-pill.html"),
18- filepath.Join("tmpl", "patchset.html"),
19- filepath.Join("tmpl", "range-diff.html"),
20- filepath.Join("tmpl", "pr-header.html"),
21- filepath.Join("tmpl", "pr-list-item.html"),
22- filepath.Join("tmpl", "pr-table.html"),
23- filepath.Join("tmpl", "pr-status.html"),
24- filepath.Join("tmpl", "base.html"),
25- ),
26+ tmpl, err := template.New("").Funcs(template.FuncMap{
27+ "sha": shaFn,
28+ }).ParseFS(
29+ tmplFS,
30+ filepath.Join("tmpl", file),
31+ filepath.Join("tmpl", "user-pill.html"),
32+ filepath.Join("tmpl", "patchset.html"),
33+ filepath.Join("tmpl", "range-diff.html"),
34+ filepath.Join("tmpl", "pr-header.html"),
35+ filepath.Join("tmpl", "pr-list-item.html"),
36+ filepath.Join("tmpl", "pr-table.html"),
37+ filepath.Join("tmpl", "pr-status.html"),
38+ filepath.Join("tmpl", "base.html"),
39 )
40+ if err != nil {
41+ panic(err)
42+ }
43 return tmpl
44 }
45
46@@ -271,7 +281,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
47
48 w.Header().Set("content-type", "text/html")
49 tmpl := getTemplate("index.html")
50- err = tmpl.Execute(w, PrTableData{
51+ err = tmpl.ExecuteTemplate(w, "base.html", PrTableData{
52 Prs: prdata,
53 MetaData: MetaData{
54 URL: web.Backend.Cfg.Url,
55@@ -350,7 +360,7 @@ func userDetailHandler(w http.ResponseWriter, r *http.Request) {
56
57 w.Header().Set("content-type", "text/html")
58 tmpl := getTemplate("user-detail.html")
59- err = tmpl.Execute(w, UserDetailData{
60+ err = tmpl.ExecuteTemplate(w, "base.html", UserDetailData{
61 Prs: prdata,
62 UserData: UserData{
63 UserID: user.ID,
64@@ -418,7 +428,7 @@ func repoDetailHandler(w http.ResponseWriter, r *http.Request) {
65
66 w.Header().Set("content-type", "text/html")
67 tmpl := getTemplate("repo-detail.html")
68- err = tmpl.Execute(w, RepoDetailData{
69+ err = tmpl.ExecuteTemplate(w, "base.html", RepoDetailData{
70 Name: repo.Name,
71 UserID: user.ID,
72 Username: userName,
73@@ -756,7 +766,7 @@ func createPrDetail(page string) http.HandlerFunc {
74
75 repoNs := web.Backend.CreateRepoNs(repoOwner.Name, repo.Name)
76 url := fmt.Sprintf("/r/%s/%s", repoOwner.Name, repo.Name)
77- err = tmpl.Execute(w, PrDetailData{
78+ err = tmpl.ExecuteTemplate(w, "pr-detail.html", PrDetailData{
79 Page: "pr",
80 Repo: LinkData{
81 Url: template.URL(url),