refactor: Switch to GitHub Search Issues API for PR queries#145
Merged
Conversation
Replace the /repos/{owner}/{repo}/pulls endpoint with the /search/issues
API to enable server-side date range filtering for more efficient queries.
## Changes
**API Endpoint Update:**
- Changed from `/repos/{owner}/{repo}/pulls` to `/search/issues`
- Added search query with date range: `repo:owner/repo is:pr created:YYYY-MM-DD..YYYY-MM-DD`
- Updated request parameters to use `q`, `sort`, and `order`
**Response Handling:**
- Parse Search API format `{"items": [...]}` instead of direct array
- Added type guard for safe dict access
- Updated `_make_pr_request_with_retry` return type to support both formats
**Code Simplification:**
- Removed client-side date filtering loop (API handles filtering)
- Set `reached_boundary = True` (Search API returns complete results)
**Test Updates:**
- Updated mocks to return Search API response format
- Fixed pagination test to use items array
- Adjusted assertions for server-side filtered results
## Benefits
- Native date filtering reduces data transfer
- Faster queries for large repositories
- Simpler code with ~20 fewer lines
- All 60 tests passing
## Trade-offs
- Search API limited to 1000 results (vs unlimited pagination)
- Lower rate limit (30/min vs 60/min)
- Potential slight indexing delays (typically < 1 minute)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the
/repos/{owner}/{repo}/pullsendpoint with the/search/issuesAPI to enable server-side date range filtering for more efficient PR queries.Changes
API Endpoint Update:
/repos/{owner}/{repo}/pullsto/search/issuesrepo:owner/repo is:pr created:YYYY-MM-DD..YYYY-MM-DDq,sort, andorderinstead ofstate,sort,directionResponse Handling:
{"items": [...]}instead of direct array responseisinstance) for safe dictionary access_make_pr_request_with_retry()return type todict[str, Any] | list[dict]Code Simplification:
reached_boundary = Truesince Search API always returns complete resultsTest Updates:
side_effectto simulate pagination properlyBenefits
✅ Server-side date filtering - GitHub API handles date range filtering, no client-side processing needed
✅ Reduced data transfer - Only relevant PRs returned, not all PRs
✅ Faster queries - More efficient for repositories with many PRs
✅ Simpler code - Removed ~20 lines of client-side filtering logic
✅ All tests passing - 60/60 tests pass
✅ Type safe - Full mypy compliance
Trade-offs
Test Plan
🤖 Generated with Claude Code