A CLI-first git forge.

cli forge git self-hosted

https://gitbay.org

Commit 3467efe33e

3467efe33e77598a1e70eba482953deac3dec989

parent: 160fc0ec2b

Verified · cmc ci/build: success

cmc <hello@cleberg.net> · 2026-08-27T19:52:06Z

control: align dashboard aggregate with web
e2e/dashboard_test.go +28 −2
@@ -120,8 +120,8 @@ func TestDashboard(t *testing.T) {
120120 }
121121
122122 // The dashboard control command returns the same aggregate as the web
123// dashboard — pinned repos, open MRs, assigned issues, recent builds — in
124// one read.
123// dashboard — review queue, assigned/open work, pins, and activity — in
124// one read. Builds remain for clients that already consume them.
125125 func TestDashboardCommand(t *testing.T) {
126126 inst := startInstance(t)
127127 aliceKey := inst.newKey(t, "alice")
@@ -175,6 +175,11 @@ func TestDashboardCommand(t *testing.T) {
175175 }
176176 var env2 struct {
177177 Data struct {
178 Reviews []struct {
179 Repo string `json:"repo"`
180 Number int64 `json:"number"`
181 Title string `json:"title"`
182 } `json:"review_queue"`
178183 Pinned []struct {
179184 Path string `json:"path"`
180185 } `json:"pinned"`
@@ -190,6 +195,16 @@ func TestDashboardCommand(t *testing.T) {
190195 Number int64 `json:"number"`
191196 Title string `json:"title"`
192197 } `json:"assigned_issues"`
198 Issues []struct {
199 Repo string `json:"repo"`
200 Number int64 `json:"number"`
201 Title string `json:"title"`
202 } `json:"open_issues"`
203 Activity []struct {
204 Repo string `json:"repo"`
205 Actor string `json:"actor"`
206 Kind string `json:"kind"`
207 } `json:"recent_activity"`
193208 Builds []struct {
194209 Repo string `json:"repo"`
195210 Job string `json:"job"`
@@ -209,10 +224,21 @@ func TestDashboardCommand(t *testing.T) {
209224 d.MRs[0].Title != "from bob" || d.MRs[0].Author != "bob" || d.MRs[0].State != "open" {
210225 t.Fatalf("open_mrs = %+v", d.MRs)
211226 }
227 if len(d.Reviews) != 1 || d.Reviews[0].Repo != "alice/app" || d.Reviews[0].Number != 1 ||
228 d.Reviews[0].Title != "from bob" {
229 t.Fatalf("review_queue = %+v", d.Reviews)
230 }
212231 if len(d.Assigned) != 1 || d.Assigned[0].Repo != "alice/app" || d.Assigned[0].Number != 1 ||
213232 d.Assigned[0].Title != "todo one" {
214233 t.Fatalf("assigned_issues = %+v", d.Assigned)
215234 }
235 if len(d.Issues) != 1 || d.Issues[0].Repo != "alice/app" || d.Issues[0].Number != 1 ||
236 d.Issues[0].Title != "todo one" {
237 t.Fatalf("open_issues = %+v", d.Issues)
238 }
239 if len(d.Activity) == 0 || d.Activity[0].Repo != "alice/app" {
240 t.Fatalf("recent_activity = %+v", d.Activity)
241 }
216242 // Both pushes hit main and feat; each queues the ci.yml job.
217243 if len(d.Builds) == 0 || d.Builds[0].Repo != "alice/app" || d.Builds[0].Job != "test" ||
218244 d.Builds[0].Status != "pending" {
internal/control/dashboard.go +71 −27
@@ -14,7 +14,7 @@ import (
1414
1515 func init() {
1616 register(Command{Path: []string{"dashboard"},
17 Summary: "one read for the account dashboard: pinned repos, open MRs, assigned issues, recent builds",
17 Summary: "one read for the account dashboard: review queue, assigned and open work, pins, activity, builds",
1818 ReadOnly: true, Run: runDashboard})
1919 register(Command{Path: []string{"feed"},
2020 Summary: "activity on repositories you can reach: feed [--limit <n>] [--cursor <c>]",
@@ -53,12 +53,18 @@ func runDashboard(c *Ctx, args []string) int {
5353 FinishedAt string `json:"finished_at,omitempty"`
5454 }
5555 type out struct {
56 Pinned []pinnedOut `json:"pinned"`
57 MRs []dashboardItem `json:"open_mrs"`
56 Reviews []dashboardItem `json:"review_queue"`
5857 Assigned []dashboardItem `json:"assigned_issues"`
58 MRs []dashboardItem `json:"open_mrs"`
59 Issues []dashboardItem `json:"open_issues"`
60 Pinned []pinnedOut `json:"pinned"`
61 Activity []feedOut `json:"recent_activity"`
5962 Builds []buildOut `json:"builds"`
6063 }
61 d := out{Pinned: []pinnedOut{}, MRs: []dashboardItem{}, Assigned: []dashboardItem{}, Builds: []buildOut{}}
64 d := out{
65 Reviews: []dashboardItem{}, Assigned: []dashboardItem{}, MRs: []dashboardItem{},
66 Issues: []dashboardItem{}, Pinned: []pinnedOut{}, Activity: []feedOut{}, Builds: []buildOut{},
67 }
6268
6369 pinned, err := c.Store.PinnedRepos(c.User.ID)
6470 if err != nil {
@@ -84,6 +90,14 @@ func runDashboard(c *Ctx, args []string) int {
8490 d.MRs = append(d.MRs, dashboardItem{m.RepoPath, m.Number, m.Title, m.Author, m.State, m.UpdatedAt})
8591 }
8692
93 reviews, err := c.Store.ReviewQueue(c.User.ID)
94 if err != nil {
95 return c.fail(protocol.ExitFailure, "%v", err)
96 }
97 for _, m := range reviews {
98 d.Reviews = append(d.Reviews, dashboardItem{m.RepoPath, m.Number, m.Title, m.Author, m.State, m.UpdatedAt})
99 }
100
87101 assigned, err := c.Store.AssignedIssues(c.User.ID)
88102 if err != nil {
89103 return c.fail(protocol.ExitFailure, "%v", err)
@@ -92,6 +106,20 @@ func runDashboard(c *Ctx, args []string) int {
92106 d.Assigned = append(d.Assigned, dashboardItem{i.RepoPath, i.Number, i.Title, i.Author, i.State, i.UpdatedAt})
93107 }
94108
109 issues, err := c.Store.DashboardIssues(c.User.ID)
110 if err != nil {
111 return c.fail(protocol.ExitFailure, "%v", err)
112 }
113 for _, i := range issues {
114 d.Issues = append(d.Issues, dashboardItem{i.RepoPath, i.Number, i.Title, i.Author, i.State, i.UpdatedAt})
115 }
116
117 events, err := c.Store.RecentEvents(c.User.ID, 20, 0)
118 if err != nil {
119 return c.fail(protocol.ExitFailure, "%v", err)
120 }
121 d.Activity = feedOutputs(events)
122
95123 builds, err := c.Store.RecentBuilds(c.User.ID, 20)
96124 if err != nil {
97125 return c.fail(protocol.ExitFailure, "%v", err)
@@ -101,6 +129,14 @@ func runDashboard(c *Ctx, args []string) int {
101129 }
102130
103131 return c.emit(d, func(w io.Writer) {
132 fmt.Fprintln(w, "waiting on your review:")
133 printDashboardItems(w, d.Reviews, "!")
134 fmt.Fprintln(w, "assigned to you:")
135 printDashboardItems(w, d.Assigned, "#")
136 fmt.Fprintln(w, "open merge requests:")
137 printDashboardItems(w, d.MRs, "!")
138 fmt.Fprintln(w, "open issues:")
139 printDashboardItems(w, d.Issues, "#")
104140 fmt.Fprintln(w, "pinned:")
105141 for _, p := range d.Pinned {
106142 mark := ""
@@ -109,13 +145,9 @@ func runDashboard(c *Ctx, args []string) int {
109145 }
110146 fmt.Fprintf(w, " %s\t%s\t%s%s\n", p.Path, p.Visibility, p.Description, mark)
111147 }
112 fmt.Fprintln(w, "open merge requests:")
113 for _, m := range d.MRs {
114 fmt.Fprintf(w, " %s!%d\t%s\t%s\n", m.Repo, m.Number, m.Title, m.Author)
115 }
116 fmt.Fprintln(w, "assigned issues:")
117 for _, i := range d.Assigned {
118 fmt.Fprintf(w, " %s#%d\t%s\t%s\n", i.Repo, i.Number, i.Title, i.Author)
148 fmt.Fprintln(w, "recent activity:")
149 for _, e := range d.Activity {
150 fmt.Fprintf(w, " %s\t%s\t%s\t%s\t%s\n", e.CreatedAt, e.Actor, e.Kind, e.Repo, string(e.Data))
119151 }
120152 fmt.Fprintln(w, "builds:")
121153 for _, b := range d.Builds {
@@ -124,10 +156,37 @@ func runDashboard(c *Ctx, args []string) int {
124156 })
125157 }
126158
159func printDashboardItems(w io.Writer, items []dashboardItem, marker string) {
160 for _, item := range items {
161 fmt.Fprintf(w, " %s%s%d\t%s\t%s\n", item.Repo, marker, item.Number, item.Title, item.Author)
162 }
163}
164
127165 // feedDefaultLimit caps a bare `feed` call; pagination reaches further
128166 // back.
129167 const feedDefaultLimit = 50
130168
169type feedOut struct {
170 ID int64 `json:"id"`
171 Repo string `json:"repo"`
172 Actor string `json:"actor,omitempty"`
173 Kind string `json:"kind"`
174 Data json.RawMessage `json:"data,omitempty"`
175 CreatedAt string `json:"created_at"`
176}
177
178func feedOutputs(events []store.FeedEvent) []feedOut {
179 ds := make([]feedOut, 0, len(events))
180 for _, e := range events {
181 d := feedOut{ID: e.ID, Repo: e.RepoPath, Actor: e.Actor, Kind: e.Kind, CreatedAt: e.CreatedAt}
182 if json.Valid([]byte(e.Data)) {
183 d.Data = json.RawMessage(e.Data)
184 }
185 ds = append(ds, d)
186 }
187 return ds
188}
189
131190 func runFeed(c *Ctx, args []string) int {
132191 rest, p, code := parsePageFlags(c, args, "feed", true)
133192 if code >= 0 {
@@ -146,22 +205,7 @@ func runFeed(c *Ctx, args []string) int {
146205 events, next := trimPage(p, events, "feed", func(e store.FeedEvent) string {
147206 return strconv.FormatInt(e.ID, 10)
148207 })
149 type feedOut struct {
150 ID int64 `json:"id"`
151 Repo string `json:"repo"`
152 Actor string `json:"actor,omitempty"`
153 Kind string `json:"kind"`
154 Data json.RawMessage `json:"data,omitempty"`
155 CreatedAt string `json:"created_at"`
156 }
157 var ds []feedOut
158 for _, e := range events {
159 d := feedOut{ID: e.ID, Repo: e.RepoPath, Actor: e.Actor, Kind: e.Kind, CreatedAt: e.CreatedAt}
160 if json.Valid([]byte(e.Data)) {
161 d.Data = json.RawMessage(e.Data)
162 }
163 ds = append(ds, d)
164 }
208 ds := feedOutputs(events)
165209 return c.emitPage(p, ds, next, func(w io.Writer) {
166210 for _, d := range ds {
167211 fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", d.CreatedAt, d.Actor, d.Kind, d.Repo, string(d.Data))