~gitpocket/gitpocket

feat(basin): star counts on repository lists

commit
6f058f9bc3c7bcc24f5b8a904a4320b4a689c830 browse tree
parent
8ac79ee6c8dcaa43c77480b839f407194ffdc33e
author
james <j@cpl0.zip>
signature
Verified ~james signed with a key registered by ~james
date
2026-11-13 02:45 UTC

6 files changed, +10 −6

static/style.css modified

@@ -265,3 +265,6 @@ table.blame tr.first td{border-top:1px solid var(--line)}
265265 table.blame td.l{white-space:pre-wrap;overflow-wrap:anywhere;width:100%}
266266 table.blame td.n{border-right:1px solid var(--bar)}
267267 .actions a.muted{margin-right:auto;align-self:center}
268+.event h4{display:flex;align-items:baseline}
269+.event h4 .tag{margin-left:.4rem}
270+.event h4 .starcount{margin-left:auto;color:var(--muted);font-size:.85rem;font-weight:400}

store.go modified

@@ -162,6 +162,7 @@ type Repo struct {
162162 Tags []string
163163 Parent int64
164164 Archived bool
165+ Stars int
165166 Created time.Time
166167 Updated time.Time
167168 }
@@ -517,7 +518,7 @@ func scanRepos(rows *sql.Rows) ([]Repo, error) {
517518 var private, archived int
518519 var tags string
519520 var created, ucreated int64
520- if err := rows.Scan(&r.ID, &r.Name, &r.Description, &private, &tags, &r.Parent, &archived, &created, &r.Owner.ID, &r.Owner.Name, &ucreated); err != nil {
521+ if err := rows.Scan(&r.ID, &r.Name, &r.Description, &private, &tags, &r.Parent, &archived, &r.Stars, &created, &r.Owner.ID, &r.Owner.Name, &ucreated); err != nil {
521522 return nil, err
522523 }
523524 r.Archived = archived != 0
@@ -531,7 +532,7 @@ func scanRepos(rows *sql.Rows) ([]Repo, error) {
531532 return repos, rows.Err()
532533 }
533534
534-const repoColumns = `r.id, r.name, r.description, r.private, r.tags, r.parent, r.archived, r.created, u.id, u.name, u.created from repos r join users u on u.id = r.owner`
535+const repoColumns = `r.id, r.name, r.description, r.private, r.tags, r.parent, r.archived, (select count(*) from stars st where st.repo = r.id), r.created, u.id, u.name, u.created from repos r join users u on u.id = r.owner`
535536
536537 func (s *Store) RepoByID(id int64) (Repo, error) {
537538 rows, err := s.db.Query(`select `+repoColumns+` where r.id = ?`, id)

templates/index.html modified

@@ -26,5 +26,5 @@
2626 </section>
2727 {{end}}
2828 {{define "repolist"}}
29-{{if .}}<div class="events">{{range .}}<div class="event"><h4><a href="/{{.Path}}">{{.Path}}</a>{{if .Private}} <span class="tag">private</span>{{else if .Unlisted}} <span class="tag">unlisted</span>{{end}}</h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="muted">Nothing here yet.</p>{{end}}
29+{{if .}}<div class="events">{{range .}}<div class="event"><h4><a href="/{{.Path}}">{{.Path}}</a>{{if .Private}} <span class="tag">private</span>{{else if .Unlisted}} <span class="tag">unlisted</span>{{end}}{{if .Stars}}<span class="starcount" title="{{.Stars}} stars">☆ {{.Stars}}</span>{{end}}</h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="muted">Nothing here yet.</p>{{end}}
3030 {{end}}

templates/projects.html modified

@@ -13,7 +13,7 @@
1313 </div>
1414 </form>
1515 {{if .Data.Tag}}<p class="muted">Showing projects tagged <a href="/projects?tag={{.Data.Tag}}">#{{.Data.Tag}}</a> · <a href="/projects">clear</a></p>{{end}}
16-{{if .Data.Repos}}<div class="events">{{range .Data.Repos}}<div class="event"><h4><a href="/~{{.Owner.Name}}">~{{.Owner.Name}}</a>/<a href="/{{.Path}}">{{.Name}}</a></h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="info">No projects match.</p>{{end}}
16+{{if .Data.Repos}}<div class="events">{{range .Data.Repos}}<div class="event"><h4><a href="/~{{.Owner.Name}}">~{{.Owner.Name}}</a>/<a href="/{{.Path}}">{{.Name}}</a>{{if .Stars}}<span class="starcount" title="{{.Stars}} stars">☆ {{.Stars}}</span>{{end}}</h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="info">No projects match.</p>{{end}}
1717 </div>
1818 <aside>
1919 <h3 class="plain">About</h3>

templates/stars.html modified

@@ -3,5 +3,5 @@
33 <h2>~{{.Data.Owner.Name}}</h2>
44 <nav class="tabs small"><a href="/~{{.Data.Owner.Name}}">about</a><a class="active" href="/~{{.Data.Owner.Name}}/stars">stars{{if .Data.Count}} <span class="count">{{.Data.Count}}</span>{{end}}</a></nav>
55 </div>
6-{{if .Data.Starred}}<div class="events">{{range .Data.Starred}}<div class="event"><h4><a href="/~{{.Owner.Name}}">~{{.Owner.Name}}</a>/<a href="/{{.Path}}">{{.Name}}</a></h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="info">~{{.Data.Owner.Name}} has not starred anything yet.</p>{{end}}
6+{{if .Data.Starred}}<div class="events">{{range .Data.Starred}}<div class="event"><h4><a href="/~{{.Owner.Name}}">~{{.Owner.Name}}</a>/<a href="/{{.Path}}">{{.Name}}</a>{{if .Stars}}<span class="starcount" title="{{.Stars}} stars">☆ {{.Stars}}</span>{{end}}</h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="info">~{{.Data.Owner.Name}} has not starred anything yet.</p>{{end}}
77 {{end}}

templates/user.html modified

@@ -16,7 +16,7 @@
1616 {{if $own}}<a class="btn primary block" href="/create">Create a new repository ▸</a><a class="btn block" href="/settings">Edit your profile ▸</a>{{end}}
1717 </aside>
1818 <div class="main">
19-{{if .Data.Repos}}<div class="events">{{range .Data.Repos}}<div class="event"><h4><a href="/{{.Path}}">{{.Name}}</a>{{if .Private}} <span class="tag">private</span>{{else if .Unlisted}} <span class="tag">unlisted</span>{{end}}</h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="info">This user does not have any repositories.</p>{{end}}
19+{{if .Data.Repos}}<div class="events">{{range .Data.Repos}}<div class="event"><h4><a href="/{{.Path}}">{{.Name}}</a>{{if .Private}} <span class="tag">private</span>{{else if .Unlisted}} <span class="tag">unlisted</span>{{end}}{{if .Stars}}<span class="starcount" title="{{.Stars}} stars">☆ {{.Stars}}</span>{{end}}</h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="info">This user does not have any repositories.</p>{{end}}
2020 </div>
2121 </div>
2222 {{end}}