git-pr

created pr with 72.1 on 2025-08-11T12:17:33Z · by 964fa508
added 72.2 on 2025-08-21T03:06:11Z · by c8ef7d19
-: ------- > 1: 9b6aea8 lgtm
1: 5dafb29 = 2: 9b6aea8 restructure web assets
cmds
checkout latest patchset:
ssh pr.pico.sh print 72 | git am -3
checkout any patchset in a patch request:
ssh pr.pico.sh print 72.[rev] | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 72

Patchset 72.1 on 2025-08-11T12:17:33Z · commit 5dafb29

restructure web assets
jolheiser 2025-08-11T12:12:40Z
- Move component (non-page) assets into a components sub-directory
  - This makes parsing all of them simpler without needing to add to the list in-code
- Move pages into their own subdirectory
  - Allows simplifying their name and distinguishes which files are the "actual" pages
- Move parsing to vars
  - Cleans up some overhead by not having to parse the templates on *every* page load while also simplifying the callsite

Signed-off-by: jolheiser <git@jolheiser.com>
Semantic diff summary
1 added, 4 modified, 0 signature changed, 0 removed across 1 analyzed file (11 files skipped: unsupported file type)
+0 -0 tmpl/components/patchset.html #
+0 -0 tmpl/components/pr-header.html #
+0 -0 tmpl/components/pr-list-item.html #
+0 -0 tmpl/components/pr-status.html #
+0 -0 tmpl/components/pr-table.html #
+0 -0 tmpl/components/range-diff.html #
+0 -0 tmpl/components/user-pill.html #
+0 -0 tmpl/pages/index.html #
+0 -0 tmpl/pages/pr.html #
+0 -0 tmpl/pages/repo.html #
+0 -0 tmpl/pages/user.html #
+27 -31 web.go #
......@@ -27,8 +27,29 @@ import (
2727 "github.com/gorilla/feeds"
2828 )
2929
30-//go:embed tmpl/*
31-var tmplFS embed.FS
30+var (
31+ //go:embed tmpl/*
32+ tmplFS embed.FS
33+ indexTmpl = getTemplate("index.html")
34+ prTmpl = getTemplate("pr.html")
35+ userTmpl = getTemplate("user.html")
36+ repoTmpl = getTemplate("repo.html")
37+)
38+
39+func getTemplate(page string) *template.Template {
40+ tmpl, err := template.New("").Funcs(template.FuncMap{
41+ "sha": shaFn,
42+ }).ParseFS(
43+ tmplFS,
44+ filepath.Join("tmpl", "pages", page),
45+ filepath.Join("tmpl", "components", "*.html"),
46+ filepath.Join("tmpl", "base.html"),
47+ )
48+ if err != nil {
49+ panic(err)
50+ }
51+ return tmpl.Lookup(page)
52+}
3253
3354 //go:embed static/*
3455 var embedStaticFS embed.FS
......@@ -83,27 +104,6 @@ func shaFn(sha string) string {
83104 return truncateSha(sha)
84105 }
85106
86-func getTemplate(file string) *template.Template {
87- tmpl, err := template.New("").Funcs(template.FuncMap{
88- "sha": shaFn,
89- }).ParseFS(
90- tmplFS,
91- filepath.Join("tmpl", file),
92- filepath.Join("tmpl", "user-pill.html"),
93- filepath.Join("tmpl", "patchset.html"),
94- filepath.Join("tmpl", "range-diff.html"),
95- filepath.Join("tmpl", "pr-header.html"),
96- filepath.Join("tmpl", "pr-list-item.html"),
97- filepath.Join("tmpl", "pr-table.html"),
98- filepath.Join("tmpl", "pr-status.html"),
99- filepath.Join("tmpl", "base.html"),
100- )
101- if err != nil {
102- panic(err)
103- }
104- return tmpl
105-}
106-
107107 type LinkData struct {
108108 Url template.URL
109109 Text string
......@@ -323,8 +323,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
323323 }
324324
325325 w.Header().Set("content-type", "text/html")
326- tmpl := getTemplate("index.html")
327- err = tmpl.ExecuteTemplate(w, "index.html", PrTableData{
326+ err = indexTmpl.Execute(w, PrTableData{
328327 NumOpen: numOpen,
329328 NumAccepted: numAccepted,
330329 NumClosed: numClosed,
......@@ -422,8 +421,7 @@ func userDetailHandler(w http.ResponseWriter, r *http.Request) {
422421 }
423422
424423 w.Header().Set("content-type", "text/html")
425- tmpl := getTemplate("user-detail.html")
426- err = tmpl.ExecuteTemplate(w, "user-detail.html", UserDetailData{
424+ err = userTmpl.Execute(w, UserDetailData{
427425 Prs: prdata,
428426 NumOpen: numOpen,
429427 NumAccepted: numAccepted,
......@@ -498,8 +496,7 @@ func repoDetailHandler(w http.ResponseWriter, r *http.Request) {
498496 }
499497
500498 w.Header().Set("content-type", "text/html")
501- tmpl := getTemplate("repo-detail.html")
502- err = tmpl.ExecuteTemplate(w, "repo-detail.html", RepoDetailData{
499+ err = repoTmpl.Execute(w, RepoDetailData{
503500 Name: repo.Name,
504501 UserID: user.ID,
505502 Username: userName,
......@@ -772,7 +769,6 @@ func createPrDetail(page string) http.HandlerFunc {
772769 }
773770
774771 w.Header().Set("content-type", "text/html")
775- tmpl := getTemplate("pr-detail.html")
776772 pk, err := web.Backend.PubkeyToPublicKey(user.Pubkey)
777773 if err != nil {
778774 web.Logger.Error("cannot parse pubkey for pr user", "err", err)
......@@ -840,7 +836,7 @@ func createPrDetail(page string) http.HandlerFunc {
840836
841837 repoNs := web.Backend.CreateRepoNs(repoOwner.Name, repo.Name)
842838 url := fmt.Sprintf("/r/%s/%s", repoOwner.Name, repo.Name)
843- err = tmpl.ExecuteTemplate(w, "pr-detail.html", PrDetailData{
839+ err = prTmpl.Execute(w, PrDetailData{
844840 Page: "pr",
845841 Repo: LinkData{
846842 Url: template.URL(url),
Back to top