Add repo names to heatmap tooltip
Extends the JSON response to include per-day repo names via array_agg on action.repo_name, and surfaces them in the hover tooltip below the contribution count. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
// Package main is a tiny HTTP service that exposes daily contribution counts
|
||||
// for a single allowlisted Gitea user, including activity from private repos.
|
||||
// and repo names for a single allowlisted Gitea user, including activity from
|
||||
// private repos.
|
||||
//
|
||||
// It reads directly from the Gitea database (the `action` table) using a
|
||||
// read-only DB user. Output is JSON: [{"date":"2026-05-04","count":3}, ...].
|
||||
// read-only DB user. Output is JSON:
|
||||
// [{"date":"2026-05-04","count":3,"repos":["myrepo"]}, ...].
|
||||
//
|
||||
// Pair with templates/profile-snippet.tmpl on the Gitea side to render a
|
||||
// GitHub-style heatmap with hover tooltips on a user profile page.
|
||||
@@ -22,7 +24,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
// ---- config ---------------------------------------------------------------
|
||||
@@ -90,8 +92,9 @@ type heatmapHandler struct {
|
||||
}
|
||||
|
||||
type dayCount struct {
|
||||
Date string `json:"date"`
|
||||
Count int `json:"count"`
|
||||
Date string `json:"date"`
|
||||
Count int `json:"count"`
|
||||
Repos []string `json:"repos"`
|
||||
}
|
||||
|
||||
func (h *heatmapHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -154,7 +157,12 @@ func (h *heatmapHandler) queryHeatmap(ctx context.Context, username string) ([]d
|
||||
// PostgreSQL doesn't accept lists as a single placeholder.
|
||||
query := fmt.Sprintf(`
|
||||
SELECT to_char(to_timestamp(created_unix) AT TIME ZONE 'UTC', 'YYYY-MM-DD') AS day,
|
||||
COUNT(*)::int
|
||||
COUNT(*)::int,
|
||||
COALESCE(
|
||||
array_agg(DISTINCT repo_name ORDER BY repo_name)
|
||||
FILTER (WHERE repo_name IS NOT NULL AND repo_name != ''),
|
||||
'{}'
|
||||
) AS repos
|
||||
FROM "action"
|
||||
WHERE act_user_id = $1
|
||||
AND created_unix >= $2
|
||||
@@ -172,7 +180,7 @@ func (h *heatmapHandler) queryHeatmap(ctx context.Context, username string) ([]d
|
||||
var out []dayCount
|
||||
for rows.Next() {
|
||||
var d dayCount
|
||||
if err := rows.Scan(&d.Date, &d.Count); err != nil {
|
||||
if err := rows.Scan(&d.Date, &d.Count, pq.Array(&d.Repos)); err != nil {
|
||||
return nil, fmt.Errorf("scan: %w", err)
|
||||
}
|
||||
out = append(out, d)
|
||||
|
||||
Reference in New Issue
Block a user