Skip to content

Commit aca83a1

Browse files
authored
Merge pull request #4 from ready-to-review/user_switch2
Add --user flag
2 parents 3ace483 + d695e6c commit aca83a1

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

github.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ func (*App) githubToken(ctx context.Context) (string, error) {
119119

120120
// fetchPRs retrieves all PRs involving the current user.
121121
func (app *App) fetchPRs(ctx context.Context) (incoming []PR, outgoing []PR, err error) {
122+
// Use targetUser if specified, otherwise use authenticated user
122123
user := app.currentUser.GetLogin()
124+
if app.targetUser != "" {
125+
user = app.targetUser
126+
}
123127

124128
// Single query to get all PRs involving the user
125129
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
183187
}
184188

185189
// Categorize as incoming or outgoing
190+
// When viewing another user's PRs, we're looking at it from their perspective
186191
if issue.GetUser().GetLogin() == user {
187192
pr.IsBlocked = pr.NeedsReview
188193
outgoing = append(outgoing, pr)

main.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package main
66

77
import (
88
"context"
9+
"flag"
910
"fmt"
1011
"log"
1112
"os"
@@ -55,6 +56,7 @@ type App struct {
5556
lastSuccessfulFetch time.Time
5657
turnClient *turn.Client
5758
currentUser *github.User
59+
targetUser string // User to query PRs for (overrides currentUser if set)
5860
previousBlockedPRs map[string]bool
5961
client *github.Client
6062
cacheDir string
@@ -69,6 +71,11 @@ type App struct {
6971
}
7072

7173
func main() {
74+
// Parse command line flags
75+
var targetUser string
76+
flag.StringVar(&targetUser, "user", "", "GitHub user to query PRs for (defaults to authenticated user)")
77+
flag.Parse()
78+
7279
log.SetFlags(log.LstdFlags | log.Lshortfile)
7380
log.Printf("Starting GitHub PR Monitor (version=%s, commit=%s, date=%s)", version, commit, date)
7481

@@ -88,6 +95,7 @@ func main() {
8895
cacheDir: cacheDir,
8996
hideStaleIncoming: true,
9097
previousBlockedPRs: make(map[string]bool),
98+
targetUser: targetUser,
9199
}
92100

93101
log.Println("Initializing GitHub clients...")
@@ -103,6 +111,11 @@ func main() {
103111
}
104112
app.currentUser = user
105113

114+
// Log if we're using a different target user
115+
if app.targetUser != "" && app.targetUser != user.GetLogin() {
116+
log.Printf("Querying PRs for user '%s' instead of authenticated user '%s'", app.targetUser, user.GetLogin())
117+
}
118+
106119
log.Println("Starting systray...")
107120
// Create a cancellable context for the application
108121
appCtx, cancel := context.WithCancel(ctx)
@@ -118,7 +131,13 @@ func main() {
118131
func (app *App) onReady(ctx context.Context) {
119132
log.Println("System tray ready")
120133
systray.SetTitle("Loading PRs...")
121-
systray.SetTooltip("GitHub PR Monitor")
134+
135+
// Set tooltip based on whether we're using a custom user
136+
tooltip := "GitHub PR Monitor"
137+
if app.targetUser != "" {
138+
tooltip = fmt.Sprintf("GitHub PR Monitor - @%s", app.targetUser)
139+
}
140+
systray.SetTooltip(tooltip)
122141

123142
// Set up click handlers
124143
systray.SetOnClick(func(menu systray.IMenu) {
@@ -199,7 +218,13 @@ func (app *App) updatePRs(ctx context.Context) {
199218
if !app.lastSuccessfulFetch.IsZero() {
200219
timeSinceSuccess = time.Since(app.lastSuccessfulFetch).Round(time.Minute).String()
201220
}
202-
systray.SetTooltip(fmt.Sprintf("GitHub PR Monitor - Error: %v\nLast success: %s ago", err, timeSinceSuccess))
221+
222+
// Include user in error tooltip
223+
userInfo := ""
224+
if app.targetUser != "" {
225+
userInfo = fmt.Sprintf(" - @%s", app.targetUser)
226+
}
227+
systray.SetTooltip(fmt.Sprintf("GitHub PR Monitor%s - Error: %v\nLast success: %s ago", userInfo, err, timeSinceSuccess))
203228
return
204229
}
205230

ui.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,11 @@ func (app *App) addStaticMenuItems(ctx context.Context) {
260260
})
261261

262262
// About
263-
aboutItem := systray.AddMenuItem("About", "")
263+
aboutText := "About"
264+
if app.targetUser != "" {
265+
aboutText = fmt.Sprintf("About (viewing @%s)", app.targetUser)
266+
}
267+
aboutItem := systray.AddMenuItem(aboutText, "")
264268
app.menuItems = append(app.menuItems, aboutItem)
265269
aboutItem.Click(func() {
266270
log.Println("GitHub PR Monitor - A system tray app for tracking PR reviews")

0 commit comments

Comments
 (0)