internal/httpd/dashpins.go

4a511e42574ead9c92dc73fd320f296cc4dbea07
gitbay/internal/httpd/dashpins.go

38 lines · 1100 bytes

2 symbols in this file
 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}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form