-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix duplicate filter issues across all search tools #828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ions - Added multiple test cases for searching issues with various query filters in `issues_test.go`. - Introduced utility functions in `search_utils.go` to check for specific filters and extract repository information from queries. - Created comprehensive tests in `search_utils_test.go` to validate the new filtering logic and ensure accurate query parsing.
- Renamed `extractRepoFilter` to `hasRepoFilter` to simplify the function's purpose. - Updated test cases in `search_utils_test.go` to reflect the new function name and logic. - Adjusted tests to focus on the presence of the `repo:` filter rather than extracting owner and repo details.
Thanks @gokhanarkan for taking up my issue #817. This is a good approach to fixing the duplicate filter issue. I know this is still in draft. However, I've identified that the exact same pattern as the original bug also exists in the DUPLICATE FILTER ISSUE IN search.go
searchQuery := "type:" + accountType + " " + query
|
…y functions - Added new test cases for searching pull requests and users with various query filters in `pullrequests_test.go` and `search_test.go`. - Implemented a utility function `hasTypeFilter` in `search_utils.go` to check for the presence of `type:` filters in queries. - Updated the search handler to conditionally prepend the `type:` filter based on the presence of existing filters, improving query handling.
@shreyabaid007 I've fixed it using the same approach as the is: filter fix. What I fixed:
The fix:
This prevents duplicate type:user and type:org filters that were causing HTTP 422 errors. Same pattern as your original issue, same solution! Thanks for the thorough analysis - this will help a lot of users avoid those validation errors. 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes duplicate filter issues across all GitHub search tools by implementing comprehensive filter detection and prevention logic. The changes prevent GitHub API validation errors that occurred when users provided queries already containing filters that the tools would automatically add.
- Adds helper functions to detect existing filters in search queries using regex patterns
- Updates all search handlers to conditionally add filters only when not already present
- Includes extensive test coverage for both filter detection logic and search tool integration
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
pkg/github/search_utils.go |
Implements core filter detection functions using regex patterns |
pkg/github/search.go |
Updates user/org search handler to prevent duplicate type: filters |
pkg/github/search_utils_test.go |
Comprehensive unit tests for all filter detection helper functions |
pkg/github/search_test.go |
Integration tests for user/org search with existing type: filters |
pkg/github/issues_test.go |
Integration tests for issue search with existing is: and repo: filters |
pkg/github/pullrequests_test.go |
Integration tests for PR search with existing is: and repo: filters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!
One small thing: the regex currently expects the filter to be preceded by whitespace. So hasFilter
will fail on query="(label:bug OR owner:bob) is:issue"
, filterType="label"
. Unlikely to occur but perhaps worth fixing now so it doesn't fail quietly later.
Otherwise approach is great and I've tested the tools
@LuluBeatson Updated both regex patterns to handle this edge case! |
Fix duplicate filter issues across all search tools
Closes: #817
Problem
Multiple search tools were incorrectly adding duplicate filters to user queries, causing GitHub API validation errors when users provided queries that already contained these filters. This affected three main areas:
1. Search Issues & Pull Requests (
search_issues
,search_pull_requests
)is:
andrepo:
filters2. User & Organization Search (
search_users
,search_orgs
)type:
filters unconditionallytype:user
ortype:org
Example bugs:
"repo:github/repo is:issue"
→"is:issue repo:github/repo is:issue"
❌"type:user location:seattle"
→"type:user type:user location:seattle"
❌Solution
Implemented comprehensive duplicate filter prevention across all search tools with a unified approach:
Core Helper Functions
Fixed Search Handlers
Issues/Pull Requests (
searchHandler
):Users/Organizations (
userOrOrgHandler
):Enhanced Debugging & Observability
Added comprehensive logging to track filter logic and API interactions:
This helps diagnose issues and validates that our fixes are working correctly in production.
What This Fixes
✅
search_issues
: No more duplicateis:issue
orrepo:
filters✅
search_pull_requests
: No more duplicateis:pr
orrepo:
filters✅
search_users
: No more duplicatetype:user
filters✅
search_orgs
: No more duplicatetype:org
filters✅ Complex queries: OR operators and parentheses work without hitting API limits
✅ User experience: Existing filters in queries are always preserved
✅ Debugging: Clear logging shows exactly what's happening at each step
Testing
Added extensive test coverage across all affected areas:
Unit Tests:
Manual Validation:
Real-World Impact
This fix resolves the frustrating experience users had when their perfectly valid GitHub search queries would fail with cryptic API errors. Now users can:
"repo:owner/repo is:issue (label:bug OR label:enhancement OR label:feature)"
Alternatives Considered
API-level deduplication: Let GitHub handle duplicate filters
Query rewriting: Parse and reconstruct queries to remove conflicts
Per-tool fixes: Fix each search tool individually
User education: Document that users shouldn't include certain filters
The chosen approach provides a clean, maintainable solution that works consistently across all search tools while preserving user intent and providing excellent debugging capabilities.
Migration Notes
This is a backward-compatible fix. Existing queries will continue to work exactly as before, but queries that previously failed due to duplicate filters will now succeed.
No configuration changes or user action required - the fix is transparent and automatic.