Skip to content

Commit d7821ff

Browse files
julianknutsenclaude
andcommitted
Fix wl me to show PR-mode items on in-flight branches
wl me only queried the main branch, so items claimed via PR mode (living on wl/<handle>/* branches) were invisible. Now scans local branches using Dolt AS OF queries and shows them in a new "In-flight branches (not yet on main)" section. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 18df710 commit d7821ff

1 file changed

Lines changed: 81 additions & 2 deletions

File tree

cmd/wl/cmd_me.go

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"io"
6+
"strings"
67

78
"github.com/julianknutsen/wasteland/internal/commons"
89
"github.com/julianknutsen/wasteland/internal/style"
@@ -14,9 +15,10 @@ func newMeCmd(stdout, stderr io.Writer) *cobra.Command {
1415
Use: "me",
1516
Short: "Show your personal dashboard",
1617
Long: `Show your personal dashboard: claimed items, items awaiting your review,
17-
and recent completions.
18+
in-flight branch work (PR mode), and recent completions.
1819
1920
Syncs with upstream first, then queries your local clone.
21+
Also scans wl/<handle>/* branches for PR-mode items not yet on main.
2022
2123
Examples:
2224
wl me`,
@@ -45,7 +47,7 @@ func runMe(cmd *cobra.Command, stdout, _ io.Writer) error {
4547
handle := cfg.RigHandle
4648
printed := false
4749

48-
// My claimed items
50+
// My claimed items (on main)
4951
claimedCSV, err := commons.DoltSQLQuery(cfg.LocalDir, fmt.Sprintf(
5052
"SELECT id, title, status, priority, effort_level FROM wanted WHERE claimed_by = '%s' AND status IN ('claimed','in_review') ORDER BY priority ASC",
5153
commons.EscapeSQL(handle),
@@ -66,6 +68,17 @@ func runMe(cmd *cobra.Command, stdout, _ io.Writer) error {
6668
printed = true
6769
}
6870

71+
// In-flight branches (PR-mode items not yet on main)
72+
mainIDs := mainClaimedIDs(claimedRows)
73+
branchItems := listBranchItems(cfg.LocalDir, handle, mainIDs)
74+
if len(branchItems) > 0 {
75+
fmt.Fprintf(stdout, "\n%s\n", style.Bold.Render("In-flight branches (not yet on main):"))
76+
for _, bi := range branchItems {
77+
fmt.Fprintf(stdout, " %-12s %-30s %s\n", bi.id, bi.title, style.Dim.Render(bi.branch))
78+
}
79+
printed = true
80+
}
81+
6982
// Awaiting my review
7083
reviewCSV, err := commons.DoltSQLQuery(cfg.LocalDir, fmt.Sprintf(
7184
"SELECT id, title, claimed_by FROM wanted WHERE posted_by = '%s' AND status = 'in_review' ORDER BY priority ASC",
@@ -112,3 +125,69 @@ func runMe(cmd *cobra.Command, stdout, _ io.Writer) error {
112125

113126
return nil
114127
}
128+
129+
// branchItem represents a wanted item found on a wl/* branch.
130+
type branchItem struct {
131+
id string
132+
title string
133+
branch string
134+
}
135+
136+
// mainClaimedIDs extracts IDs already shown in the "My claimed items" section
137+
// so we can deduplicate against branch results.
138+
func mainClaimedIDs(claimedRows [][]string) map[string]bool {
139+
ids := make(map[string]bool)
140+
for i, row := range claimedRows {
141+
if i == 0 || len(row) < 1 { // skip header
142+
continue
143+
}
144+
ids[row[0]] = true
145+
}
146+
return ids
147+
}
148+
149+
// listBranchItems scans wl/<handle>/* branches and returns items that differ
150+
// from main — i.e., PR-mode work not yet merged.
151+
func listBranchItems(dbDir, handle string, skipIDs map[string]bool) []branchItem {
152+
prefix := fmt.Sprintf("wl/%s/", handle)
153+
branches, err := commons.ListBranches(dbDir, prefix)
154+
if err != nil || len(branches) == 0 {
155+
return nil
156+
}
157+
158+
var items []branchItem
159+
for _, branch := range branches {
160+
wantedID := extractBranchWantedID(branch)
161+
if wantedID == "" || skipIDs[wantedID] {
162+
continue
163+
}
164+
// Query the wanted table AS OF this branch to get the item state.
165+
query := fmt.Sprintf(
166+
"SELECT id, title, status FROM wanted AS OF '%s' WHERE id = '%s' LIMIT 1",
167+
commons.EscapeSQL(branch), commons.EscapeSQL(wantedID),
168+
)
169+
csv, err := commons.DoltSQLQuery(dbDir, query)
170+
if err != nil {
171+
continue
172+
}
173+
rows := wlParseCSV(csv)
174+
if len(rows) < 2 || len(rows[1]) < 3 {
175+
continue
176+
}
177+
items = append(items, branchItem{
178+
id: rows[1][0],
179+
title: rows[1][1],
180+
branch: branch,
181+
})
182+
}
183+
return items
184+
}
185+
186+
// extractBranchWantedID extracts the wanted ID from wl/<rig>/<id>.
187+
func extractBranchWantedID(branch string) string {
188+
parts := strings.SplitN(branch, "/", 3)
189+
if len(parts) < 3 {
190+
return ""
191+
}
192+
return parts[2]
193+
}

0 commit comments

Comments
 (0)