diff --git a/github.go b/github.go index 9f3b6f0..593fea6 100644 --- a/github.go +++ b/github.go @@ -119,7 +119,11 @@ func (*App) githubToken(ctx context.Context) (string, error) { // fetchPRs retrieves all PRs involving the current user. func (app *App) fetchPRs(ctx context.Context) (incoming []PR, outgoing []PR, err error) { + // Use targetUser if specified, otherwise use authenticated user user := app.currentUser.GetLogin() + if app.targetUser != "" { + user = app.targetUser + } // Single query to get all PRs involving the user query := fmt.Sprintf("is:open is:pr involves:%s archived:false", user) @@ -183,6 +187,7 @@ func (app *App) fetchPRs(ctx context.Context) (incoming []PR, outgoing []PR, err } // Categorize as incoming or outgoing + // When viewing another user's PRs, we're looking at it from their perspective if issue.GetUser().GetLogin() == user { pr.IsBlocked = pr.NeedsReview outgoing = append(outgoing, pr) diff --git a/main.go b/main.go index bf577b3..e8dbc82 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ package main import ( "context" + "flag" "fmt" "log" "os" @@ -55,6 +56,7 @@ type App struct { lastSuccessfulFetch time.Time turnClient *turn.Client currentUser *github.User + targetUser string // User to query PRs for (overrides currentUser if set) previousBlockedPRs map[string]bool client *github.Client cacheDir string @@ -69,6 +71,11 @@ type App struct { } func main() { + // Parse command line flags + var targetUser string + flag.StringVar(&targetUser, "user", "", "GitHub user to query PRs for (defaults to authenticated user)") + flag.Parse() + log.SetFlags(log.LstdFlags | log.Lshortfile) log.Printf("Starting GitHub PR Monitor (version=%s, commit=%s, date=%s)", version, commit, date) @@ -88,6 +95,7 @@ func main() { cacheDir: cacheDir, hideStaleIncoming: true, previousBlockedPRs: make(map[string]bool), + targetUser: targetUser, } log.Println("Initializing GitHub clients...") @@ -103,6 +111,11 @@ func main() { } app.currentUser = user + // Log if we're using a different target user + if app.targetUser != "" && app.targetUser != user.GetLogin() { + log.Printf("Querying PRs for user '%s' instead of authenticated user '%s'", app.targetUser, user.GetLogin()) + } + log.Println("Starting systray...") // Create a cancellable context for the application appCtx, cancel := context.WithCancel(ctx) @@ -118,7 +131,13 @@ func main() { func (app *App) onReady(ctx context.Context) { log.Println("System tray ready") systray.SetTitle("Loading PRs...") - systray.SetTooltip("GitHub PR Monitor") + + // Set tooltip based on whether we're using a custom user + tooltip := "GitHub PR Monitor" + if app.targetUser != "" { + tooltip = fmt.Sprintf("GitHub PR Monitor - @%s", app.targetUser) + } + systray.SetTooltip(tooltip) // Set up click handlers systray.SetOnClick(func(menu systray.IMenu) { @@ -199,7 +218,13 @@ func (app *App) updatePRs(ctx context.Context) { if !app.lastSuccessfulFetch.IsZero() { timeSinceSuccess = time.Since(app.lastSuccessfulFetch).Round(time.Minute).String() } - systray.SetTooltip(fmt.Sprintf("GitHub PR Monitor - Error: %v\nLast success: %s ago", err, timeSinceSuccess)) + + // Include user in error tooltip + userInfo := "" + if app.targetUser != "" { + userInfo = fmt.Sprintf(" - @%s", app.targetUser) + } + systray.SetTooltip(fmt.Sprintf("GitHub PR Monitor%s - Error: %v\nLast success: %s ago", userInfo, err, timeSinceSuccess)) return } diff --git a/ui.go b/ui.go index e11b265..dbf6938 100644 --- a/ui.go +++ b/ui.go @@ -260,7 +260,11 @@ func (app *App) addStaticMenuItems(ctx context.Context) { }) // About - aboutItem := systray.AddMenuItem("About", "") + aboutText := "About" + if app.targetUser != "" { + aboutText = fmt.Sprintf("About (viewing @%s)", app.targetUser) + } + aboutItem := systray.AddMenuItem(aboutText, "") app.menuItems = append(app.menuItems, aboutItem) aboutItem.Click(func() { log.Println("GitHub PR Monitor - A system tray app for tracking PR reviews")