Skip to content

fix: smart filter inside repo#769

Merged
dlvhdr merged 9 commits intodlvhdr:mainfrom
iperzic:fix/smart-filter-inside-repo
Feb 22, 2026
Merged

fix: smart filter inside repo#769
dlvhdr merged 9 commits intodlvhdr:mainfrom
iperzic:fix/smart-filter-inside-repo

Conversation

@iperzic
Copy link
Contributor

@iperzic iperzic commented Feb 11, 2026

Summary

When running gh-dash inside a git repo with smart filtering enabled, removing the repo: filter from the search bar and pressing Enter had no effect, the filter was silently re-added behind the scenes on every query. This happened because IsFilteredByCurrentRemote was never cleared when the user edited the search value.

This PR adds SyncSmartFilterWithSearchValue() which detects that the user removed the repo filter and clears the flag, so the search respects the user's edit.

Note

The issue is only reproducible when filters is removed from "Mine" PR section in .gh-dash.yml

How did you test this change?

Unit tests covering: smart filter active with repo filter present, smart filter toggled off, user manually removing the repo filter, user replacing with a different repo, and config already containing a repo filter.

Images/Videos

Before After
CleanShot 2026-02-11 at 10 20 38@2x CleanShot 2026-02-11 at 10 18 34@2x

@iperzic iperzic changed the title Fix/smart filter inside repo fix: smart filter inside repo Feb 11, 2026
@dlvhdr
Copy link
Owner

dlvhdr commented Feb 13, 2026

Hey @iperzic. I always disliked how smart filtering behaved.
I've pushed some more fixes on top of yours - let me know what you think.

This is how I want it to behave, when toggling smart filtering:

  • if we're filtering by the current repo, remove that filter
  • if we're filtering by another repo - do nothing
  • if we're not filtering by any repo - add the current repo as filter
  • auto add the current repo as filter on launch if it's missing and smartFilteringAtLaunch is set to true (which is the default).

Let me know if my fixes make sense and I would love for more tests are that.
I kept your fix working, just broken it into a function.

CC @sideshowbarker

@sideshowbarker
Copy link
Contributor

There’s certainly always been a huge amount of room for improvement in the smart-filtering feature. So it’s great to see it getting some attention and fixes/refinements.

sideshowbarker@2112c16 has some further fixes, plus tests.

I don’t have push/write perms to this repo, nor to PR branches here like this one — so that commit is at my own repo. But it could be fetched and cherry-picked into this branch.

@iperzic
Copy link
Contributor Author

iperzic commented Feb 16, 2026

@dlvhdr Thanks for the review, and the follow-up. I included @sideshowbarker commit in this PR as well.

As far as I'm concerned, this looks good. Though, I must caveat that I'm not that experienced with golang, so take my review with a bucket of salt.

dlvhdr
dlvhdr previously approved these changes Feb 21, 2026
iperzic and others added 7 commits February 21, 2026 19:32
- Fix HasPrefix false-positive on similar repo names:
  HasCurrentRepoNameInConfiguredFilter() and GetSearchValue() used
  strings.HasPrefix, so repo:owner/repo would falsely match
  repo:owner/repo-extra. Changed to exact token equality.

- Fix inconsistent toggle logic in issues and notifications sections:
  both still used the old !HasRepoNameInConfiguredFilter() guard, which
  prevented toggling when any repo: filter was present (including the
  current repo). Updated both to match the PR section's
  HasCurrentRepoNameInConfiguredFilter() ||
  !HasRepoNameInConfiguredFilter() logic.

- Fix NewModel initialization using strings.Contains instead of
  token-level matching, which could false-positive on substring matches.
  Changed to iterate tokens with strings.FieldsSeq and exact equality.

- Change log.Info to log.Debug for the toggle state message in
  prssection.go, since it fires on every keypress and is only useful
  for debugging.

- Add 28 test cases across 7 test functions covering
  HasRepoNameInConfiguredFilter, HasCurrentRepoNameInConfiguredFilter,
  SyncSmartFilterWithSearchValue, GetSearchValue (including the prefix
  false-positive regression), and GetConfigFiltersWithCurrentRemoteAdded.

- Update Smart Filtering docs to document that manually editing the
  search bar and pressing Enter syncs the smart filter state to match.
@dlvhdr dlvhdr force-pushed the fix/smart-filter-inside-repo branch from 0a4fc19 to 1b842e7 Compare February 21, 2026 17:33
@dlvhdr
Copy link
Owner

dlvhdr commented Feb 21, 2026

@sideshowbarker seems like the tests fail due to not running inside a git repo or something along those lines. Should we mock the currentRepoFilter func?

Copy link
Owner

@dlvhdr dlvhdr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks again everyone!

@dlvhdr dlvhdr merged commit 44dc841 into dlvhdr:main Feb 22, 2026
4 checks passed
@sideshowbarker
Copy link
Contributor

@sideshowbarker seems like the tests fail due to not running inside a git repo or something along those lines.

To fix that, I see you made this change:

 func currentRepoFilter(t *testing.T) string {
 	t.Helper()
+	t.Setenv("GH_REPO", "https://github.com/dlvhdr/gh-dash")
 	repo, err := repository.Current()
 	if err != nil {
 		t.Fatal("failed to resolve current repository:", err)

So yeah I hadn’t considered how that CI might not (wouldn’t) have a remote configured.

But in hindsight: I can see that, because the test as currently written isn’t testing across multiple repos anyway, then for the current scope of the test, the test didn’t need currentRepoFilter to begin with. We could just do this:

const testRepoFilter = "repo:dlvhdr/gh-dash"

…and then just have the test use that constant everywhere it’s calling currentRepoFilter now.

Should we mock the currentRepoFilter func?

No, I think the fix you made is sufficient for now. The actual app code doesn’t call currentRepoFilter anywhere. It’s just a test-only thing.

I had imagined the test needed to handle testing across multiple repos, and so we’d need some way for the test to know what the current repo is. But… the test as currently written isn’t testing across multiple repos — and even if it were, we could anyway actually just be using strings.

So when (if) we next have need to go back in and touch that section_test.go test, then we should refactor it to replace the currentRepoFilter function and calls.

But otherwise, I think the fix you made is fine for now, and we don’t need to fiddle with it further right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants