Skip to content

Commit d994d02

Browse files
committed
better tada.wav
1 parent 123fc63 commit d994d02

File tree

5 files changed

+50
-65
lines changed

5 files changed

+50
-65
lines changed

.DS_Store

-2 KB
Binary file not shown.

cmd/goose/github.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@ import (
2424
// githubTokenRegex matches valid GitHub token formats.
2525
var githubTokenRegex = regexp.MustCompile(`^(ghp_[a-zA-Z0-9]{36}|gho_[a-zA-Z0-9]{36}|github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59})$`)
2626

27-
// validateGitHubToken validates a GitHub token format.
28-
func validateGitHubToken(token string) error {
29-
if token == "" {
30-
return errors.New("empty token")
31-
}
32-
if !githubTokenRegex.MatchString(token) {
33-
return errors.New("invalid GitHub token format")
34-
}
35-
return nil
36-
}
37-
3827
// initClients initializes GitHub and Turn API clients.
3928
func (app *App) initClients(ctx context.Context) error {
4029
token, err := app.token(ctx)
@@ -64,8 +53,12 @@ func (*App) token(ctx context.Context) (string, error) {
6453
// Check GITHUB_TOKEN environment variable first
6554
if token := os.Getenv("GITHUB_TOKEN"); token != "" {
6655
token = strings.TrimSpace(token)
67-
if err := validateGitHubToken(token); err != nil {
68-
return "", fmt.Errorf("invalid GITHUB_TOKEN: %w", err)
56+
// Validate token format inline
57+
if token == "" {
58+
return "", errors.New("GITHUB_TOKEN is empty")
59+
}
60+
if !githubTokenRegex.MatchString(token) {
61+
return "", errors.New("GITHUB_TOKEN has invalid format")
6962
}
7063
log.Println("Using GitHub token from GITHUB_TOKEN environment variable")
7164
return token, nil

cmd/goose/main.go

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ const (
3737
cacheCleanupInterval = 5 * 24 * time.Hour
3838

3939
// PR settings.
40-
stalePRThreshold = 90 * 24 * time.Hour
40+
dailyInterval = 24 * time.Hour
41+
stalePRThreshold = 90 * dailyInterval
4142
maxPRsToProcess = 200 // Limit for performance
4243

4344
// Update interval settings.
@@ -535,35 +536,6 @@ func (app *App) updatePRsWithWait(ctx context.Context) {
535536
app.checkForNewlyBlockedPRs(ctx)
536537
}
537538

538-
// shouldNotifyForPR determines if we should send a notification for a PR.
539-
func shouldNotifyForPR(
540-
_ string,
541-
isBlocked bool,
542-
prevState NotificationState,
543-
hasHistory bool,
544-
reminderInterval time.Duration,
545-
enableReminders bool,
546-
) (shouldNotify bool, reason string) {
547-
if !hasHistory && isBlocked {
548-
return true, "newly blocked"
549-
}
550-
551-
if !hasHistory {
552-
return false, ""
553-
}
554-
555-
switch {
556-
case isBlocked && !prevState.WasBlocked:
557-
return true, "became blocked"
558-
case !isBlocked && prevState.WasBlocked:
559-
return false, "unblocked"
560-
case isBlocked && prevState.WasBlocked && enableReminders && time.Since(prevState.LastNotified) > reminderInterval:
561-
return true, "reminder"
562-
default:
563-
return false, ""
564-
}
565-
}
566-
567539
// processPRNotifications handles notification logic for a single PR.
568540
func (app *App) processPRNotifications(
569541
ctx context.Context,
@@ -576,7 +548,30 @@ func (app *App) processPRNotifications(
576548
reminderInterval time.Duration,
577549
) {
578550
prevState, hasHistory := notificationHistory[pr.URL]
579-
shouldNotify, notifyReason := shouldNotifyForPR(pr.URL, isBlocked, prevState, hasHistory, reminderInterval, app.enableReminders)
551+
552+
// Inline notification decision logic
553+
var shouldNotify bool
554+
var notifyReason string
555+
switch {
556+
case !hasHistory && isBlocked:
557+
shouldNotify = true
558+
notifyReason = "newly blocked"
559+
case !hasHistory:
560+
shouldNotify = false
561+
notifyReason = ""
562+
case isBlocked && !prevState.WasBlocked:
563+
shouldNotify = true
564+
notifyReason = "became blocked"
565+
case !isBlocked && prevState.WasBlocked:
566+
shouldNotify = false
567+
notifyReason = "unblocked"
568+
case isBlocked && prevState.WasBlocked && app.enableReminders && time.Since(prevState.LastNotified) > reminderInterval:
569+
shouldNotify = true
570+
notifyReason = "reminder"
571+
default:
572+
shouldNotify = false
573+
notifyReason = ""
574+
}
580575

581576
// Update state for unblocked PRs
582577
if notifyReason == "unblocked" {

cmd/goose/sounds/tada.wav

0 Bytes
Binary file not shown.

cmd/goose/ui.go

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,6 @@ import (
1616
)
1717

1818
// formatAge formats a duration in human-readable form.
19-
func formatAge(updatedAt time.Time) string {
20-
duration := time.Since(updatedAt)
21-
22-
switch {
23-
case duration < time.Hour:
24-
return fmt.Sprintf("%dm", int(duration.Minutes()))
25-
case duration < 24*time.Hour:
26-
return fmt.Sprintf("%dh", int(duration.Hours()))
27-
case duration < 30*24*time.Hour:
28-
return fmt.Sprintf("%dd", int(duration.Hours()/24))
29-
case duration < 365*24*time.Hour:
30-
return fmt.Sprintf("%dmo", int(duration.Hours()/(24*30)))
31-
default:
32-
return updatedAt.Format("2006")
33-
}
34-
}
35-
3619
// openURL safely opens a URL in the default browser after validation.
3720
func openURL(ctx context.Context, rawURL string) error {
3821
// Parse and validate the URL
@@ -193,9 +176,8 @@ func (app *App) addPRSection(ctx context.Context, prs []PR, sectionTitle string,
193176
// Add PR items in sorted order
194177
for i := range sortedPRs {
195178
// Apply filters
196-
// Skip stale PRs if configured (older than 90 days)
197-
const stalePRDays = 90
198-
if app.hideStaleIncoming && sortedPRs[i].UpdatedAt.Before(time.Now().Add(-stalePRDays*24*time.Hour)) {
179+
// Skip stale PRs if configured
180+
if app.hideStaleIncoming && sortedPRs[i].UpdatedAt.Before(time.Now().Add(-stalePRThreshold)) {
199181
continue
200182
}
201183

@@ -204,7 +186,22 @@ func (app *App) addPRSection(ctx context.Context, prs []PR, sectionTitle string,
204186
if sortedPRs[i].NeedsReview {
205187
title = fmt.Sprintf("• %s", title)
206188
}
207-
tooltip := fmt.Sprintf("%s (%s)", sortedPRs[i].Title, formatAge(sortedPRs[i].UpdatedAt))
189+
// Format age inline for tooltip
190+
duration := time.Since(sortedPRs[i].UpdatedAt)
191+
var age string
192+
switch {
193+
case duration < time.Hour:
194+
age = fmt.Sprintf("%dm", int(duration.Minutes()))
195+
case duration < dailyInterval:
196+
age = fmt.Sprintf("%dh", int(duration.Hours()))
197+
case duration < 30*dailyInterval:
198+
age = fmt.Sprintf("%dd", int(duration.Hours()/24))
199+
case duration < 365*dailyInterval:
200+
age = fmt.Sprintf("%dmo", int(duration.Hours()/(24*30)))
201+
default:
202+
age = sortedPRs[i].UpdatedAt.Format("2006")
203+
}
204+
tooltip := fmt.Sprintf("%s (%s)", sortedPRs[i].Title, age)
208205
// Add action reason for blocked PRs
209206
if (sortedPRs[i].NeedsReview || sortedPRs[i].IsBlocked) && sortedPRs[i].ActionReason != "" {
210207
tooltip = fmt.Sprintf("%s - %s", tooltip, sortedPRs[i].ActionReason)

0 commit comments

Comments
 (0)