Skip to content

Commit 85734bb

Browse files
committed
Add --dismiss-repos flag to pre-dismiss repos on startup
Accepts comma-separated repo names (e.g. --dismiss-repos repo1,repo2). Works in both plain and TUI modes. In the TUI, pre-dismissed repos can be supplemented with additional D key dismissals during the session.
1 parent 9c6ee00 commit 85734bb

3 files changed

Lines changed: 45 additions & 13 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pr-patrol --plain | wc -l
101101
| `--authored` | | Include PRs you authored (excluded by default) |
102102
| `--assigned` | | Only show PRs assigned to you for review |
103103
| `--author` | | Show your own PRs and their review status |
104+
| `--dismiss-repos` | | Repos to hide, comma-separated (e.g. `repo1,repo2`) |
104105
| `--limit` | | Maximum PRs to fetch (default 500) |
105106

106107
### TUI Keys

main.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"os"
6+
"strings"
67

78
tea "github.com/charmbracelet/bubbletea"
89
pflag "github.com/spf13/pflag"
@@ -15,6 +16,7 @@ func main() {
1516
mine := pflag.Bool("assigned", false, "Only show PRs assigned to you for review")
1617
author := pflag.Bool("author", false, "Show your own PRs and their review status")
1718
limit := pflag.Int("limit", 500, "Maximum number of PRs to fetch")
19+
dismissRepos := pflag.StringSlice("dismiss-repos", nil, "Repos to hide (comma-separated)")
1820
demo := pflag.Bool("demo", false, "Show demo data (for screenshots)")
1921
pflag.Parse()
2022

@@ -37,6 +39,14 @@ func main() {
3739
os.Exit(1)
3840
}
3941

42+
dismissedRepoSet := make(map[string]bool)
43+
for _, r := range *dismissRepos {
44+
r = strings.TrimSpace(r)
45+
if r != "" {
46+
dismissedRepoSet[r] = true
47+
}
48+
}
49+
4050
if *plain {
4151
fmt.Fprintf(os.Stderr, "Fetching PRs for %s...\n", *org)
4252

@@ -54,6 +64,7 @@ func main() {
5464

5565
if *author {
5666
classified := classifyAllAuthor(prs, me, SortPriority)
67+
classified = filterDismissedRepos(classified, dismissedRepoSet)
5768
if len(classified) == 0 {
5869
fmt.Fprintln(os.Stderr, "No open PRs authored by you.")
5970
return
@@ -74,6 +85,7 @@ func main() {
7485
}
7586
}
7687
classified := classifyAll(prs, me, *self, filter, SortPriority)
88+
classified = filterDismissedRepos(classified, dismissedRepoSet)
7789
if len(classified) == 0 {
7890
fmt.Fprintln(os.Stderr, "No PRs pending your review.")
7991
return
@@ -84,12 +96,13 @@ func main() {
8496

8597
// TUI path: start with loading spinner, fetch data async
8698
p := tea.NewProgram(newModel(modelConfig{
87-
loading: true,
88-
org: *org,
89-
limit: *limit,
99+
loading: true,
100+
org: *org,
101+
limit: *limit,
90102
showAuthored: *self,
91103
showAssigned: *mine,
92-
showAuthor: *author,
104+
showAuthor: *author,
105+
dismissedRepos: dismissedRepoSet,
93106
}), tea.WithAltScreen())
94107
if _, err := p.Run(); err != nil {
95108
fmt.Fprintf(os.Stderr, "error: %v\n", err)

tui.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,17 @@ type model struct {
7070
}
7171

7272
type modelConfig struct {
73-
rawPRs []PRNode
74-
me string
75-
myTeams map[string]bool
73+
rawPRs []PRNode
74+
me string
75+
myTeams map[string]bool
7676
showAuthored bool
7777
showAssigned bool
78-
showAuthor bool
79-
sortMode SortMode
80-
loading bool
81-
org string
82-
limit int
78+
showAuthor bool
79+
sortMode SortMode
80+
loading bool
81+
org string
82+
limit int
83+
dismissedRepos map[string]bool
8384
}
8485

8586
type dataLoadedMsg struct {
@@ -134,10 +135,27 @@ func fetchDataCmd(org string, limit int) tea.Cmd {
134135
}
135136
}
136137

138+
func filterDismissedRepos(prs []ClassifiedPR, repos map[string]bool) []ClassifiedPR {
139+
if len(repos) == 0 {
140+
return prs
141+
}
142+
var out []ClassifiedPR
143+
for _, pr := range prs {
144+
if !repos[pr.RepoName] {
145+
out = append(out, pr)
146+
}
147+
}
148+
return out
149+
}
150+
137151
func newModel(cfg modelConfig) model {
152+
dismissedRepos := cfg.dismissedRepos
153+
if dismissedRepos == nil {
154+
dismissedRepos = make(map[string]bool)
155+
}
138156
m := model{
139157
dismissed: make(map[string]bool),
140-
dismissedRepos: make(map[string]bool),
158+
dismissedRepos: dismissedRepos,
141159
rawPRs: cfg.rawPRs,
142160
me: cfg.me,
143161
myTeams: cfg.myTeams,

0 commit comments

Comments
 (0)