Skip to content

Commit 23156f7

Browse files
authored
Merge pull request #37 from codeGROOVE-dev/correct-highlighting
Fix bugs in how we highlight recently notified PRs
2 parents d283c10 + ee2c17d commit 23156f7

File tree

3 files changed

+55
-20
lines changed

3 files changed

+55
-20
lines changed

cmd/goose/github.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -634,16 +634,12 @@ func (app *App) fetchTurnDataAsync(ctx context.Context, issues []*github.Issue,
634634
}
635635

636636
// Only check for newly blocked PRs if there were actual changes
637+
// checkForNewlyBlockedPRs will handle UI updates internally if needed
637638
if actualChanges > 0 {
638639
app.checkForNewlyBlockedPRs(ctx)
639-
}
640-
641-
// Update tray title and menu with final Turn data if menu is already initialized
642-
app.setTrayTitle()
643-
if app.menuInitialized {
644-
// Only trigger menu update if PR data actually changed
645-
if actualChanges > 0 {
646-
app.updateMenu(ctx)
647-
}
640+
// UI updates are handled inside checkForNewlyBlockedPRs
641+
} else {
642+
// No changes, but still update tray title in case of initial load
643+
app.setTrayTitle()
648644
}
649645
}

cmd/goose/main.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,15 +568,26 @@ func (app *App) notifyWithSound(ctx context.Context, pr PR, isIncoming bool, pla
568568

569569
// checkForNewlyBlockedPRs sends notifications for blocked PRs.
570570
func (app *App) checkForNewlyBlockedPRs(ctx context.Context) {
571-
app.mu.RLock()
572-
incoming := app.incoming
573-
outgoing := app.outgoing
571+
// Check for context cancellation early
572+
select {
573+
case <-ctx.Done():
574+
log.Print("[BLOCKED] Context cancelled, skipping newly blocked PR check")
575+
return
576+
default:
577+
}
578+
579+
app.mu.Lock()
580+
// Make deep copies to work with while holding the lock
581+
incoming := make([]PR, len(app.incoming))
582+
copy(incoming, app.incoming)
583+
outgoing := make([]PR, len(app.outgoing))
584+
copy(outgoing, app.outgoing)
574585
previousBlocked := app.previousBlockedPRs
575586
blockedTimes := app.blockedPRTimes
576587
autoBrowserEnabled := app.enableAutoBrowser
577588
startTime := app.startTime
578589
hideStaleIncoming := app.hideStaleIncoming
579-
app.mu.RUnlock()
590+
app.mu.Unlock()
580591

581592
currentBlocked := make(map[string]bool)
582593
newBlockedTimes := make(map[string]time.Time)
@@ -597,6 +608,8 @@ func (app *App) checkForNewlyBlockedPRs(ctx context.Context) {
597608
// Newly blocked PR
598609
newBlockedTimes[incoming[i].URL] = now
599610
incoming[i].FirstBlockedAt = now
611+
log.Printf("[BLOCKED] Setting FirstBlockedAt for incoming PR: %s #%d at %v",
612+
incoming[i].Repository, incoming[i].Number, now)
600613

601614
// Skip sound and auto-open for stale PRs when hideStaleIncoming is enabled
602615
isStale := incoming[i].UpdatedAt.Before(staleThreshold)
@@ -625,6 +638,8 @@ func (app *App) checkForNewlyBlockedPRs(ctx context.Context) {
625638
// Newly blocked PR
626639
newBlockedTimes[outgoing[i].URL] = now
627640
outgoing[i].FirstBlockedAt = now
641+
log.Printf("[BLOCKED] Setting FirstBlockedAt for outgoing PR: %s #%d at %v",
642+
outgoing[i].Repository, outgoing[i].Number, now)
628643

629644
// Skip sound and auto-open for stale PRs when hideStaleIncoming is enabled
630645
isStale := outgoing[i].UpdatedAt.Before(staleThreshold)
@@ -645,11 +660,21 @@ func (app *App) checkForNewlyBlockedPRs(ctx context.Context) {
645660
}
646661
}
647662

663+
// Update state with a lock
648664
app.mu.Lock()
649665
app.previousBlockedPRs = currentBlocked
650666
app.blockedPRTimes = newBlockedTimes
651667
// Update the PR lists with FirstBlockedAt times
652668
app.incoming = incoming
653669
app.outgoing = outgoing
670+
menuInitialized := app.menuInitialized
654671
app.mu.Unlock()
672+
673+
// Update UI after releasing the lock
674+
// Only update if there are newly blocked PRs
675+
if menuInitialized && len(currentBlocked) > len(previousBlocked) {
676+
log.Print("[BLOCKED] Updating UI for newly blocked PRs")
677+
app.setTrayTitle()
678+
app.updateMenu(ctx)
679+
}
655680
}

cmd/goose/ui.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,21 @@ func (app *App) setTrayTitle() {
142142
counts := app.countPRs()
143143

144144
// Set title based on PR state
145+
var title string
145146
switch {
146147
case counts.IncomingBlocked == 0 && counts.OutgoingBlocked == 0:
147-
systray.SetTitle("😊")
148+
title = "😊"
148149
case counts.IncomingBlocked > 0 && counts.OutgoingBlocked > 0:
149-
systray.SetTitle(fmt.Sprintf("🪿 %d 🎉 %d", counts.IncomingBlocked, counts.OutgoingBlocked))
150+
title = fmt.Sprintf("🪿 %d 🎉 %d", counts.IncomingBlocked, counts.OutgoingBlocked)
150151
case counts.IncomingBlocked > 0:
151-
systray.SetTitle(fmt.Sprintf("🪿 %d", counts.IncomingBlocked))
152+
title = fmt.Sprintf("🪿 %d", counts.IncomingBlocked)
152153
default:
153-
systray.SetTitle(fmt.Sprintf("🎉 %d", counts.OutgoingBlocked))
154+
title = fmt.Sprintf("🎉 %d", counts.OutgoingBlocked)
154155
}
156+
157+
log.Printf("[TRAY] Setting title: %s (incoming_blocked=%d, outgoing_blocked=%d)",
158+
title, counts.IncomingBlocked, counts.OutgoingBlocked)
159+
systray.SetTitle(title)
155160
}
156161

157162
// sortPRsBlockedFirst creates a sorted copy of PRs with blocked ones first.
@@ -201,11 +206,20 @@ func (app *App) addPRSection(ctx context.Context, prs []PR, sectionTitle string,
201206
}
202207

203208
title := fmt.Sprintf("%s #%d", sortedPRs[i].Repository, sortedPRs[i].Number)
204-
// Add bullet point or goose for blocked PRs
209+
// Add bullet point or emoji for blocked PRs
205210
if sortedPRs[i].NeedsReview || sortedPRs[i].IsBlocked {
206-
// Show goose emoji for PRs blocked within the last hour
211+
// Show emoji for PRs blocked within the last hour
207212
if !sortedPRs[i].FirstBlockedAt.IsZero() && time.Since(sortedPRs[i].FirstBlockedAt) < time.Hour {
208-
title = fmt.Sprintf("🪿 %s", title)
213+
// Use party popper for outgoing PRs, goose for incoming PRs
214+
if sectionTitle == "Outgoing" {
215+
title = fmt.Sprintf("🎉 %s", title)
216+
log.Printf("[MENU] Adding party popper to outgoing PR: %s (blocked %v ago)",
217+
sortedPRs[i].URL, time.Since(sortedPRs[i].FirstBlockedAt))
218+
} else {
219+
title = fmt.Sprintf("🪿 %s", title)
220+
log.Printf("[MENU] Adding goose to incoming PR: %s (blocked %v ago)",
221+
sortedPRs[i].URL, time.Since(sortedPRs[i].FirstBlockedAt))
222+
}
209223
} else {
210224
title = fmt.Sprintf("• %s", title)
211225
}

0 commit comments

Comments
 (0)