tenseleyflow/shithub / e263bc7

Browse files

web/handlers/repo: render verified badge on tag list

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
e263bc74bdb42260b804b063ee13da2f1578d71d
Parents
b01b43c
Tree
dfd02e4

2 changed files

StatusFile+-
M internal/web/handlers/repo/branches.go 28 6
M internal/web/templates/repo/tags.html 4 1
internal/web/handlers/repo/branches.gomodified
@@ -13,6 +13,7 @@ import (
1313
 
1414
 	"github.com/tenseleyFlow/shithub/internal/auth/policy"
1515
 	repogit "github.com/tenseleyFlow/shithub/internal/repos/git"
16
+	"github.com/tenseleyFlow/shithub/internal/repos/sigverify"
1617
 	reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc"
1718
 	"github.com/tenseleyFlow/shithub/internal/web/middleware"
1819
 )
@@ -159,12 +160,13 @@ func (h *Handlers) tagsList(w http.ResponseWriter, r *http.Request) {
159160
 	refs, _ := repogit.ListRefs(r.Context(), gitDir)
160161
 
161162
 	type tagRow struct {
162
-		Name       string
163
-		OID        string
164
-		ShortOID   string
165
-		Subject    string
166
-		AuthorName string
167
-		AuthorWhen time.Time
163
+		Name         string
164
+		OID          string
165
+		ShortOID     string
166
+		Subject      string
167
+		AuthorName   string
168
+		AuthorWhen   time.Time
169
+		Verification sigverify.View
168170
 	}
169171
 	rows := make([]tagRow, 0, len(refs.Tags))
170172
 	for _, t := range refs.Tags {
@@ -183,6 +185,26 @@ func (h *Handlers) tagsList(w http.ResponseWriter, r *http.Request) {
183185
 		return rows[i].AuthorWhen.After(rows[j].AuthorWhen)
184186
 	})
185187
 
188
+	// Batch-load tag-object verifications for the page. Cache misses
189
+	// fall through to UnsignedView; the badge partial renders nothing
190
+	// for unsigned, so unannotated/unsigned tags simply have no badge.
191
+	oids := make([]string, 0, len(rows))
192
+	for _, tr := range rows {
193
+		if tr.OID != "" {
194
+			oids = append(oids, tr.OID)
195
+		}
196
+	}
197
+	if len(oids) > 0 {
198
+		verifications, vErr := sigverify.LoadViewsForOIDs(r.Context(), h.d.Pool, row.ID, oids)
199
+		if vErr != nil {
200
+			h.d.Logger.WarnContext(r.Context(), "tagsList: load verifications", "error", vErr, "repo_id", row.ID)
201
+			verifications = map[string]sigverify.View{}
202
+		}
203
+		for i := range rows {
204
+			rows[i].Verification = sigverify.LookupView(verifications, rows[i].OID)
205
+		}
206
+	}
207
+
186208
 	h.d.Render.RenderPage(w, r, "repo/tags", map[string]any{
187209
 		"Title":     "Tags · " + row.Name,
188210
 		"CSRFToken": middleware.CSRFTokenForRequest(r),
internal/web/templates/repo/tags.htmlmodified
@@ -15,7 +15,10 @@
1515
     <tbody>
1616
       {{ range .Rows }}
1717
       <tr>
18
-        <td><a href="/{{ $.Owner }}/{{ $.Repo.Name }}/tree/{{ .Name }}"><code>{{ .Name }}</code></a></td>
18
+        <td>
19
+          <a href="/{{ $.Owner }}/{{ $.Repo.Name }}/tree/{{ .Name }}"><code>{{ .Name }}</code></a>
20
+          {{ template "verified-badge" .Verification }}
21
+        </td>
1922
         <td><a href="/{{ $.Owner }}/{{ $.Repo.Name }}/commit/{{ .OID }}"><code>{{ .ShortOID }}</code></a></td>
2023
         <td>{{ .Subject }}</td>
2124
         <td>{{ if not .AuthorWhen.IsZero }}<time datetime="{{ .AuthorWhen.Format "2006-01-02T15:04:05Z" }}">{{ relativeTime .AuthorWhen }}</time>{{ end }}</td>