internal/httpd/dashpins.go

v1.39.0
gitbay/internal/httpd/dashpins.go history · blame · raw

38 lines · 1100 bytes

 1package httpd
 2
 3import (
 4	"gitbay.org/gitbay/internal/policy"
 5	"gitbay.org/gitbay/internal/store"
 6)
 7
 8// pinnedRow is one pinned repository on the dashboard with the counts
 9// that say whether it wants attention: open issues, open merge requests
10// and the newest build's status ("" when it has none).
11type pinnedRow struct {
12	Owner  string
13	Name   string
14	Issues int
15	MRs    int
16	Build  string
17}
18
19// pinnedRows reads the viewer's pinned repositories the way railFor does,
20// then adds the counts. Three reads per pinned repository, on the
21// dashboard only.
22func (s *Server) pinnedRows(viewer store.User) []pinnedRow {
23	pinned, _ := s.st.PinnedRepos(viewer.ID)
24	var rows []pinnedRow
25	for _, rp := range pinned {
26		grant, _ := s.st.AccessRole(rp.ID, viewer.ID)
27		if !policy.CanRead(viewer, rp, grant) {
28			continue
29		}
30		row := pinnedRow{Owner: rp.OwnerName, Name: rp.Name}
31		row.Issues, row.MRs = s.st.OpenCounts(rp.ID)
32		if builds, err := s.st.ListBuilds(rp.ID, store.BuildFilter{}, 1); err == nil && len(builds) > 0 {
33			row.Build = builds[0].Status
34		}
35		rows = append(rows, row)
36	}
37	return rows
38}