From bbfb3a7ad82c2fb5feec3061fa05a5f992eb0282 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Tue, 5 Aug 2025 19:59:41 -0400 Subject: [PATCH] lint cleanup --- github.go | 15 +++------------ main.go | 14 ++++++++++---- ui.go | 57 +++++++++++++++++++++++++++---------------------------- 3 files changed, 41 insertions(+), 45 deletions(-) diff --git a/github.go b/github.go index 4cc8309..6c924fa 100644 --- a/github.go +++ b/github.go @@ -119,18 +119,9 @@ func (*App) githubToken(ctx context.Context) (string, error) { return token, nil } -// fetchPRs retrieves all PRs involving the current user. -// It returns GitHub data immediately and starts Turn API queries in the background. -func (app *App) fetchPRs(ctx context.Context) (incoming []PR, outgoing []PR, err error) { - return app.fetchPRsInternal(ctx, false) -} - -// fetchPRsWithWait fetches PRs and waits for Turn data to complete. -func (app *App) fetchPRsWithWait(ctx context.Context) (incoming []PR, outgoing []PR, err error) { - return app.fetchPRsInternal(ctx, true) -} - -// fetchPRsInternal is the common implementation for PR fetching. +// fetchPRsInternal is the implementation for PR fetching. +// It returns GitHub data immediately and starts Turn API queries in the background (when waitForTurn=false), +// or waits for Turn data to complete (when waitForTurn=true). func (app *App) fetchPRsInternal(ctx context.Context, waitForTurn bool) (incoming []PR, outgoing []PR, err error) { // Use targetUser if specified, otherwise use authenticated user user := app.currentUser.GetLogin() diff --git a/main.go b/main.go index 65a5e6d..1bcd6d9 100644 --- a/main.go +++ b/main.go @@ -280,7 +280,7 @@ func (app *App) updateLoop(ctx context.Context) { } func (app *App) updatePRs(ctx context.Context) { - incoming, outgoing, err := app.fetchPRs(ctx) + incoming, outgoing, err := app.fetchPRsInternal(ctx, false) if err != nil { log.Printf("Error fetching PRs: %v", err) app.mu.Lock() @@ -531,7 +531,7 @@ func (app *App) updateMenuIfChanged(ctx context.Context) { // updatePRsWithWait fetches PRs and waits for Turn data before building initial menu. func (app *App) updatePRsWithWait(ctx context.Context) { - incoming, outgoing, err := app.fetchPRsWithWait(ctx) + incoming, outgoing, err := app.fetchPRsInternal(ctx, true) if err != nil { log.Printf("Error fetching PRs: %v", err) app.mu.Lock() @@ -566,7 +566,10 @@ func (app *App) updatePRsWithWait(ctx context.Context) { // Still create initial menu even on error if !app.menuInitialized { log.Println("Creating initial menu despite error") - app.initializeMenu(ctx) + log.Print("[MENU] Initializing menu structure") + app.rebuildMenu(ctx) + app.menuInitialized = true + log.Print("[MENU] Menu initialization complete") } return } @@ -645,7 +648,10 @@ func (app *App) updatePRsWithWait(ctx context.Context) { // Create initial menu after first successful data load if !app.menuInitialized { log.Println("Creating initial menu with Turn data") - app.initializeMenu(ctx) + log.Print("[MENU] Initializing menu structure") + app.rebuildMenu(ctx) + app.menuInitialized = true + log.Print("[MENU] Menu initialization complete") } else { app.updateMenuIfChanged(ctx) } diff --git a/ui.go b/ui.go index 1e7d2e5..8821f28 100644 --- a/ui.go +++ b/ui.go @@ -91,11 +91,16 @@ func openURL(ctx context.Context, rawURL string) error { return nil } +// PRCounts represents PR count information. +type PRCounts struct { + IncomingTotal int + IncomingBlocked int + OutgoingTotal int + OutgoingBlocked int +} + // countPRs counts the number of PRs that need review/are blocked. -// Returns: incomingCount, incomingBlocked, outgoingCount, outgoingBlocked -// -//nolint:revive,gocritic // 4 return values is clearer than a struct here -func (app *App) countPRs() (int, int, int, int) { +func (app *App) countPRs() PRCounts { app.mu.RLock() defer app.mu.RUnlock() @@ -122,23 +127,28 @@ func (app *App) countPRs() (int, int, int, int) { } } } - return incomingCount, incomingBlocked, outgoingCount, outgoingBlocked + return PRCounts{ + IncomingTotal: incomingCount, + IncomingBlocked: incomingBlocked, + OutgoingTotal: outgoingCount, + OutgoingBlocked: outgoingBlocked, + } } // setTrayTitle updates the system tray title based on PR counts. func (app *App) setTrayTitle() { - _, incomingBlocked, _, outgoingBlocked := app.countPRs() + counts := app.countPRs() // Set title based on PR state switch { - case incomingBlocked == 0 && outgoingBlocked == 0: + case counts.IncomingBlocked == 0 && counts.OutgoingBlocked == 0: systray.SetTitle("😊") - case incomingBlocked > 0 && outgoingBlocked > 0: - systray.SetTitle(fmt.Sprintf("👀 %d 🎉 %d", incomingBlocked, outgoingBlocked)) - case incomingBlocked > 0: - systray.SetTitle(fmt.Sprintf("👀 %d", incomingBlocked)) + case counts.IncomingBlocked > 0 && counts.OutgoingBlocked > 0: + systray.SetTitle(fmt.Sprintf("👀 %d 🎉 %d", counts.IncomingBlocked, counts.OutgoingBlocked)) + case counts.IncomingBlocked > 0: + systray.SetTitle(fmt.Sprintf("👀 %d", counts.IncomingBlocked)) default: - systray.SetTitle(fmt.Sprintf("🎉 %d", outgoingBlocked)) + systray.SetTitle(fmt.Sprintf("🎉 %d", counts.OutgoingBlocked)) } } @@ -213,17 +223,6 @@ func (app *App) addPRSection(ctx context.Context, prs []PR, sectionTitle string, } } -// initializeMenu creates the initial menu structure. -func (app *App) initializeMenu(ctx context.Context) { - log.Print("[MENU] Initializing menu structure") - - // Build the entire menu - app.rebuildMenu(ctx) - - app.menuInitialized = true - log.Print("[MENU] Menu initialization complete") -} - // rebuildMenu completely rebuilds the menu from scratch. func (app *App) rebuildMenu(ctx context.Context) { log.Print("[MENU] Rebuilding entire menu") @@ -246,30 +245,30 @@ func (app *App) rebuildMenu(ctx context.Context) { systray.AddSeparator() // Get PR counts - incomingCount, incomingBlocked, outgoingCount, outgoingBlocked := app.countPRs() + counts := app.countPRs() // Handle "No pull requests" case - if incomingCount == 0 && outgoingCount == 0 { + if counts.IncomingTotal == 0 && counts.OutgoingTotal == 0 { log.Print("[MENU] Creating 'No pull requests' item") noPRs := systray.AddMenuItem("No pull requests", "") noPRs.Disable() } else { // Incoming section - if incomingCount > 0 { + if counts.IncomingTotal > 0 { app.mu.RLock() incoming := app.incoming app.mu.RUnlock() - app.addPRSection(ctx, incoming, "Incoming", incomingBlocked) + app.addPRSection(ctx, incoming, "Incoming", counts.IncomingBlocked) } systray.AddSeparator() // Outgoing section - if outgoingCount > 0 { + if counts.OutgoingTotal > 0 { app.mu.RLock() outgoing := app.outgoing app.mu.RUnlock() - app.addPRSection(ctx, outgoing, "Outgoing", outgoingBlocked) + app.addPRSection(ctx, outgoing, "Outgoing", counts.OutgoingBlocked) } }