Skip to content

Commit 4810d3c

Browse files
authored
Merge pull request #7 from ready-to-review/parallel2
Add block reason to tooltips + --no-cache flag
2 parents e07bb02 + 23426bf commit 4810d3c

File tree

4 files changed

+86
-38
lines changed

4 files changed

+86
-38
lines changed

cache.go

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,30 @@ func (app *App) turnData(ctx context.Context, url string, updatedAt time.Time) (
2929
hash := sha256.Sum256([]byte(key))
3030
cacheFile := filepath.Join(app.cacheDir, hex.EncodeToString(hash[:])[:16]+".json")
3131

32-
// Try to read from cache (gracefully handle all cache errors)
33-
if data, readErr := os.ReadFile(cacheFile); readErr == nil {
34-
var entry cacheEntry
35-
if unmarshalErr := json.Unmarshal(data, &entry); unmarshalErr != nil {
36-
log.Printf("Failed to unmarshal cache data for %s: %v", url, unmarshalErr)
37-
// Remove corrupted cache file
38-
if removeErr := os.Remove(cacheFile); removeErr != nil {
39-
log.Printf("Failed to remove corrupted cache file: %v", removeErr)
32+
// Skip cache if --no-cache flag is set
33+
if !app.noCache {
34+
// Try to read from cache (gracefully handle all cache errors)
35+
if data, readErr := os.ReadFile(cacheFile); readErr == nil {
36+
var entry cacheEntry
37+
if unmarshalErr := json.Unmarshal(data, &entry); unmarshalErr != nil {
38+
log.Printf("Failed to unmarshal cache data for %s: %v", url, unmarshalErr)
39+
// Remove corrupted cache file
40+
if removeErr := os.Remove(cacheFile); removeErr != nil {
41+
log.Printf("Failed to remove corrupted cache file: %v", removeErr)
42+
}
43+
} else if time.Since(entry.CachedAt) < cacheTTL && entry.UpdatedAt.Equal(updatedAt) {
44+
// Check if cache is still valid (2 hour TTL)
45+
return entry.Data, nil
4046
}
41-
} else if time.Since(entry.CachedAt) < cacheTTL && entry.UpdatedAt.Equal(updatedAt) {
42-
// Check if cache is still valid (2 hour TTL)
43-
return entry.Data, nil
4447
}
4548
}
4649

4750
// Cache miss, fetch from API
48-
log.Printf("Cache miss for %s, fetching from Turn API", url)
51+
if app.noCache {
52+
log.Printf("Cache bypassed for %s (--no-cache), fetching from Turn API", url)
53+
} else {
54+
log.Printf("Cache miss for %s, fetching from Turn API", url)
55+
}
4956

5057
// Just try once with timeout - if Turn API fails, it's not critical
5158
turnCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
@@ -57,20 +64,22 @@ func (app *App) turnData(ctx context.Context, url string, updatedAt time.Time) (
5764
return nil, err
5865
}
5966

60-
// Save to cache (don't fail if caching fails)
61-
entry := cacheEntry{
62-
Data: data,
63-
CachedAt: time.Now(),
64-
UpdatedAt: updatedAt,
65-
}
66-
if cacheData, marshalErr := json.Marshal(entry); marshalErr != nil {
67-
log.Printf("Failed to marshal cache data for %s: %v", url, marshalErr)
68-
} else {
69-
// Ensure cache directory exists
70-
if dirErr := os.MkdirAll(filepath.Dir(cacheFile), 0o700); dirErr != nil {
71-
log.Printf("Failed to create cache directory: %v", dirErr)
72-
} else if writeErr := os.WriteFile(cacheFile, cacheData, 0o600); writeErr != nil {
73-
log.Printf("Failed to write cache file for %s: %v", url, writeErr)
67+
// Save to cache (don't fail if caching fails) - skip if --no-cache is set
68+
if !app.noCache {
69+
entry := cacheEntry{
70+
Data: data,
71+
CachedAt: time.Now(),
72+
UpdatedAt: updatedAt,
73+
}
74+
if cacheData, marshalErr := json.Marshal(entry); marshalErr != nil {
75+
log.Printf("Failed to marshal cache data for %s: %v", url, marshalErr)
76+
} else {
77+
// Ensure cache directory exists
78+
if dirErr := os.MkdirAll(filepath.Dir(cacheFile), 0o700); dirErr != nil {
79+
log.Printf("Failed to create cache directory: %v", dirErr)
80+
} else if writeErr := os.WriteFile(cacheFile, cacheData, 0o600); writeErr != nil {
81+
log.Printf("Failed to write cache file for %s: %v", url, writeErr)
82+
}
7483
}
7584
}
7685

github.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func (app *App) fetchPRs(ctx context.Context) (incoming []PR, outgoing []PR, err
226226
}
227227

228228
// updatePRData updates PR data with Turn API results.
229-
func (app *App) updatePRData(url string, needsReview bool, isOwner bool) *PR {
229+
func (app *App) updatePRData(url string, needsReview bool, isOwner bool, actionReason string) *PR {
230230
app.mu.Lock()
231231
defer app.mu.Unlock()
232232

@@ -236,6 +236,7 @@ func (app *App) updatePRData(url string, needsReview bool, isOwner bool) *PR {
236236
if app.outgoing[i].URL == url {
237237
app.outgoing[i].NeedsReview = needsReview
238238
app.outgoing[i].IsBlocked = needsReview
239+
app.outgoing[i].ActionReason = actionReason
239240
return &app.outgoing[i]
240241
}
241242
}
@@ -244,6 +245,7 @@ func (app *App) updatePRData(url string, needsReview bool, isOwner bool) *PR {
244245
for i := range app.incoming {
245246
if app.incoming[i].URL == url {
246247
app.incoming[i].NeedsReview = needsReview
248+
app.incoming[i].ActionReason = actionReason
247249
return &app.incoming[i]
248250
}
249251
}
@@ -338,22 +340,40 @@ func (app *App) fetchTurnDataAsync(ctx context.Context, issues []*github.Issue,
338340
const minUpdateInterval = 500 * time.Millisecond
339341

340342
for result := range results {
343+
// Debug logging for PR #1203 - check all responses
344+
if strings.Contains(result.url, "1203") {
345+
log.Printf("[TURN] DEBUG PR #1203: result.err=%v, turnData=%v", result.err, result.turnData != nil)
346+
if result.turnData != nil {
347+
log.Printf("[TURN] DEBUG PR #1203: PRState.UnblockAction=%v", result.turnData.PRState.UnblockAction != nil)
348+
}
349+
}
350+
341351
if result.err == nil && result.turnData != nil && result.turnData.PRState.UnblockAction != nil {
342352
turnSuccesses++
343353

344-
// Check if user needs to review
354+
// Debug logging for PR #1203
355+
if strings.Contains(result.url, "1203") {
356+
log.Printf("[TURN] DEBUG PR #1203: UnblockAction keys: %+v", result.turnData.PRState.UnblockAction)
357+
}
358+
359+
// Check if user needs to review and get action reason
345360
needsReview := false
346-
if _, exists := result.turnData.PRState.UnblockAction[user]; exists {
361+
actionReason := ""
362+
if action, exists := result.turnData.PRState.UnblockAction[user]; exists {
347363
needsReview = true
364+
actionReason = action.Reason
365+
log.Printf("[TURN] UnblockAction for %s: Reason=%q, Kind=%q", result.url, action.Reason, action.Kind)
366+
} else {
367+
log.Printf("[TURN] No UnblockAction found for user %s on %s", user, result.url)
348368
}
349369

350370
// Update the PR in our lists
351-
pr := app.updatePRData(result.url, needsReview, result.isOwner)
371+
pr := app.updatePRData(result.url, needsReview, result.isOwner, actionReason)
352372

353373
if pr != nil {
354374
updatesApplied++
355375
updateBatch++
356-
log.Printf("[TURN] Turn data received for %s (needsReview=%v)", result.url, needsReview)
376+
log.Printf("[TURN] Turn data received for %s (needsReview=%v, actionReason=%q)", result.url, needsReview, actionReason)
357377
// Update the specific menu item immediately
358378
app.updatePRMenuItem(*pr)
359379

main.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ const (
4343

4444
// PR represents a pull request with metadata.
4545
type PR struct {
46-
UpdatedAt time.Time
47-
Title string
48-
URL string
49-
Repository string
50-
Number int
51-
IsBlocked bool
52-
NeedsReview bool
46+
UpdatedAt time.Time
47+
Title string
48+
URL string
49+
Repository string
50+
ActionReason string // Action reason from Turn API when blocked
51+
Number int
52+
IsBlocked bool
53+
NeedsReview bool
5354
}
5455

5556
// App holds the application state.
@@ -74,12 +75,15 @@ type App struct {
7475
turnDataLoading bool
7576
turnDataLoaded bool
7677
menuInitialized bool
78+
noCache bool
7779
}
7880

7981
func main() {
8082
// Parse command line flags
8183
var targetUser string
84+
var noCache bool
8285
flag.StringVar(&targetUser, "user", "", "GitHub user to query PRs for (defaults to authenticated user)")
86+
flag.BoolVar(&noCache, "no-cache", false, "Bypass cache for debugging")
8387
flag.Parse()
8488

8589
log.SetFlags(log.LstdFlags | log.Lshortfile)
@@ -104,6 +108,7 @@ func main() {
104108
targetUser: targetUser,
105109
prMenuItems: make(map[string]*systray.MenuItem),
106110
sectionHeaders: make(map[string]*systray.MenuItem),
111+
noCache: noCache,
107112
}
108113

109114
log.Println("Initializing GitHub clients...")

ui.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,17 @@ func (app *App) updatePRMenuItem(pr PR) {
197197
if pr.NeedsReview {
198198
title = fmt.Sprintf("• %s", title)
199199
}
200+
201+
// Update tooltip with action reason
202+
tooltip := fmt.Sprintf("%s (%s)", pr.Title, formatAge(pr.UpdatedAt))
203+
if (pr.NeedsReview || pr.IsBlocked) && pr.ActionReason != "" {
204+
tooltip = fmt.Sprintf("%s - %s", tooltip, pr.ActionReason)
205+
log.Printf("[MENU] DEBUG: Updating tooltip for %s with actionReason: %q -> %q", pr.URL, pr.ActionReason, tooltip)
206+
}
207+
200208
log.Printf("[MENU] Updating PR menu item for %s: '%s' -> '%s'", pr.URL, oldTitle, title)
201209
item.SetTitle(title)
210+
item.SetTooltip(tooltip)
202211
} else {
203212
log.Printf("[MENU] WARNING: Tried to update non-existent PR menu item for %s", pr.URL)
204213
}
@@ -213,6 +222,11 @@ func (app *App) addPRMenuItem(ctx context.Context, pr PR, _ bool) {
213222
title = fmt.Sprintf("• %s", title)
214223
}
215224
tooltip := fmt.Sprintf("%s (%s)", pr.Title, formatAge(pr.UpdatedAt))
225+
// Add action reason for blocked PRs
226+
if (pr.NeedsReview || pr.IsBlocked) && pr.ActionReason != "" {
227+
tooltip = fmt.Sprintf("%s - %s", tooltip, pr.ActionReason)
228+
log.Printf("[MENU] DEBUG: Setting tooltip for %s with actionReason: %q -> %q", pr.URL, pr.ActionReason, tooltip)
229+
}
216230

217231
// Check if menu item already exists
218232
if existingItem, exists := app.prMenuItems[pr.URL]; exists {

0 commit comments

Comments
 (0)