Skip to content

Conversation

@ghinks
Copy link
Owner

@ghinks ghinks commented Oct 19, 2025

Summary

Replace the /repos/{owner}/{repo}/pulls endpoint with the /search/issues API to enable server-side date range filtering for more efficient PR 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 instead of state, sort, direction

Response Handling:

  • Parse Search API format {"items": [...]} instead of direct array response
  • Added type guard (isinstance) for safe dictionary access
  • Updated _make_pr_request_with_retry() return type to dict[str, Any] | list[dict]

Code Simplification:

  • Removed client-side date filtering loop (lines 142-147) - API now handles filtering
  • Set reached_boundary = True since Search API always returns complete results
  • Eliminated unnecessary datetime parsing and comparison logic

Test Updates:

  • Updated test mocks to return Search API response format
  • Added side_effect to simulate pagination properly
  • Adjusted assertions to expect server-side filtered results (2 PRs instead of 3)
  • Added mock headers to prevent rate limiting test issues

Benefits

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

⚠️ Result limit - Search API capped at 1000 results (10 pages × 100/page) vs unlimited pagination
⚠️ Lower rate limit - 30 requests/min vs 60 requests/min for standard API
⚠️ Indexing delay - Potential slight delays (typically < 1 minute) for very recent PRs

Test Plan

  • All 60 unit tests passing
  • Ruff linting passed
  • Mypy type checking passed (24 source files)
  • Verified mock responses match Search API format
  • Confirmed pagination error handling works correctly

🤖 Generated with Claude Code

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 <[email protected]>
@ghinks ghinks merged commit 44a3a08 into main Oct 21, 2025
9 checks passed
@ghinks ghinks deleted the feat/efficient-pr-metadata-query branch October 21, 2025 10:33
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.

2 participants