middleware
middleware copied to clipboard
feat: Backend API for PRs Merged Without Review
Linked Issue(s)
Closes #207
Acceptance Criteria Fulfillment
- [x] Added a Python backend API to fetch a team’s pull requests merged without any review.
Proposed Changes
- Introduced a new API endpoint:
/teams/<team_id>/prs/merged_without_review— retrieves all pull requests merged without any review activity. - Implemented the backend query logic to accurately identify PRs with no associated review events within the specified time interval.
API Response Example
Below is an example response from the new API:
UI Reference (For Context Only)
The following screenshots illustrate how this data could be visualized in the UI.
Note: This PR only includes backend API changes the UI is shown for reference.
Summary by CodeRabbit
- New Features
- Added new analytics capability to retrieve and analyze merged pull requests that were not reviewed. Supports filtering by team, time intervals, and optional criteria to provide insights into unreviewed merged code and code review processes.
Walkthrough
A new backend API endpoint is added to fetch merged pull requests without review for a team within a specified time interval. The implementation spans three layers: the HTTP API endpoint, the analytics service, and the repository data access layer with filtering logic.
Changes
| Cohort / File(s) | Summary |
|---|---|
API Layer backend/analytics_server/mhq/api/pull_requests.py |
New GET endpoint /teams/<team_id>/prs/merged_without_review with query parameters from_time, to_time (ISO datetime), and optional pr_filter; validates interval, fetches team repositories, collects merged PRs without review, and returns non-paginated response. |
Service Layer backend/analytics_server/mhq/service/code/pr_analytics.py |
New method get_prs_merged_without_review() on PullRequestAnalyticsService that delegates to CodeRepoService; adds imports for PRFilter, Team, and Interval. |
Data Access Layer backend/analytics_server/mhq/store/repos/code.py |
New method get_prs_merged_without_review() on CodeRepoService using NOT EXISTS subquery to exclude PRs with REVIEW events; applies repo/interval/PR filters; adds imports for PullRequestEventType and SQLAlchemy predicates (not_, exists). |
Sequence Diagram(s)
sequenceDiagram
participant Client
participant API as API Endpoint
participant Service as Analytics Service
participant Repo as Code Repo Service
participant DB as Database
Client->>API: GET /teams/{team_id}/prs/merged_without_review<br/>(from_time, to_time, pr_filter)
API->>API: Validate interval<br/>Fetch team & repos
API->>Service: get_prs_merged_without_review<br/>(repo_ids, interval, pr_filter)
Service->>Repo: get_prs_merged_without_review<br/>(repo_ids, interval, pr_filter)
Repo->>DB: Query PRs merged without REVIEW events<br/>within interval & repos
DB-->>Repo: PullRequest records
Repo-->>Service: List[PullRequest]
Service-->>API: List[PullRequest]
API-->>Client: Non-paginated PR response (JSON)
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~12 minutes
- Database query logic: The NOT EXISTS subquery pattern for filtering PRs without REVIEW events requires verification of correctness and performance implications.
- Filter application: Ensure PR filters and interval constraints are correctly applied in combination with the NOT EXISTS logic.
Poem
🐰 Through layers we hop, from web to store, Merged requests bare—no reviews before! NOT EXISTS whispers through SQL's night, Teams glimpse their process, oh what insight! Merged without guardians, now brought to light. ✨
Pre-merge checks and finishing touches
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The PR title 'feat: Backend API for PRs Merged Without Review' directly and clearly summarizes the main change in the pull request. It accurately reflects the primary objective of adding a new backend API endpoint to retrieve pull requests merged without review, which is the core focus of all the code changes across the three modified files. |
| Description check | ✅ Passed | The PR description is well-structured and mostly complete. It includes the linked issue (Closes #207), fulfills the acceptance criteria with a checked checkbox for the first task (adding the Python backend API), and provides clear proposed changes with an explanation of the new API endpoint and backend query logic. The description also includes helpful visual context with screenshots. The template sections 'Linked Issue(s)', 'Acceptance Criteria fulfillment', and 'Proposed changes' are all appropriately filled out. |
| Linked Issues check | ✅ Passed | The code changes directly address the first acceptance criterion from issue #207: adding a Python backend API to fetch teams' PRs merged without review. The implementation includes a new GET endpoint at /teams/<team_id>/prs/merged_without_review, backend query logic in the CodeRepoService class to identify PRs without associated review events, and supporting service layer methods. All coding requirements for the first task are met. The second and third tasks (BFF/Next.js and UI components) are appropriately deferred to separate PRs as noted in the issue. |
| Out of Scope Changes check | ✅ Passed | All code changes in the pull request are directly scoped to the first acceptance criterion of issue #207: implementing the Python backend API for fetching PRs merged without review. The three modified files (pull_requests.py, pr_analytics.py, and code.py) contain only changes necessary to support the new API endpoint and its underlying query logic. No unrelated modifications or scope creep is evident. |
✨ Finishing touches
- [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.