-
-
Notifications
You must be signed in to change notification settings - Fork 313
Code Review leaderboard fix #4746
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
Code Review leaderboard fix #4746
Conversation
WalkthroughThis PR fixes PR review leaderboard tracking and improves data handling across leaderboard sections. Backend changes refine database queries for PR and review data with fallback handling and GitHub username extraction. Template updates improve styling, user avatar display logic, and presentation consistency with red accent colors. Changes
Sequence Diagram(s)sequenceDiagram
participant Backend as User.py<br/>(Leaderboard Query)
participant DB as Database
participant Template as leaderboard_global.html<br/>(Render)
participant Client as Browser
Backend->>DB: Query PR leaderboard<br/>(repo__isnull=False)
DB-->>Backend: PR data + user_profile
Backend->>Backend: extract_github_username()<br/>from user_profile.github_url
Backend->>Backend: Inject github_username<br/>into leaderboard entry
Backend->>Template: Context with enriched<br/>leaderboard data
Backend->>DB: Query code_review_leaderboard<br/>(reviewer__user__isnull=False)
DB-->>Backend: Review data + reviewer profile
Backend->>Backend: extract_github_username()<br/>from reviewer.github_url
Backend->>Backend: Inject github_username<br/>into entry
Backend->>Template: Context with enriched<br/>review data
Template->>Template: For each leaderboard entry:<br/>resolve avatar source
alt github_username available
Template->>Template: Use GitHub avatar URL
else no github_username
Template->>Template: Fallback to gravatar
else no email
Template->>Template: Use default avatar
end
Template->>Template: Render username or<br/>"Unknown User"
Template->>Client: Render leaderboard<br/>with red accent styling
Client-->>Client: Display final HTML
Estimated code review effortπ― 3 (Moderate) | β±οΈ ~20β28 minutes
Pre-merge checks and finishing touchesβ Failed checks (1 warning)
β Passed checks (4 passed)
β¨ Finishing touches
π§ͺ Generate unit tests (beta)
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 |
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.
Actionable comments posted: 0
π§Ή Nitpick comments (1)
website/views/user.py (1)
61-92: Validate GitHub host before deriving avatar handlesRight now any URL containing a slash (e.g., Twitter, LinkedIn, company blogs) passes through and we emit
https://github.com/<last-segment>.png, which produces broken or misleading avatars. Previously those entries fell back to Gravatar, so this regresses the display. Please bail out unless the netloc is really GitHub (includewww./api.variants) before we lift the final path component. Remember to add theurlparseimport alongside the existing ones.+from urllib.parse import urlparse + def extract_github_username(github_url): @@ - # Strip trailing slashes and whitespace - github_url = github_url.strip().rstrip("/") # Clean URL format - - # Remove query parameters and fragments if present - github_url = github_url.split("?")[0].split("#")[0] - - # Ensure URL contains at least one slash - if "/" not in github_url: - return None - - # Split on "/" and get the last segment - segments = github_url.split("/") - username = segments[-1] if segments else None - - # Return username only if it's non-empty and not domain parts or protocol prefixes - if username and username not in ["github.com", "www.github.com", "www", "http:", "https:"]: - return username - - return None + parsed = urlparse(github_url.strip()) + if parsed.netloc.lower() not in {"github.com", "www.github.com", "api.github.com"}: + return None + + path_segments = [segment for segment in parsed.path.split("/") if segment] + if not path_segments: + return None + + username = path_segments[-1] + if username in {"apps", "users", "orgs"}: + return None + + return username
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
π Files selected for processing (2)
website/templates/leaderboard_global.html(4 hunks)website/views/user.py(3 hunks)
PR Review Leaderboard Fix
Issue
Fixes #4569 & #4660 - PR review tracking for TOP BLT PRs leaderboard was broken - showed "No code review data available!" despite existing data.
Root Cause
Incorrect ORM query using wrong model and field relationships.
Files Changed
website/views/user.py- Fixed query logicwebsite/templates/leaderboard_global.html- Fixed template field names and stylingScreencast.from.2025-11-09.19-54-36.webm
Key Changes
1. Fixed ORM Query
2. Fixed Template Field Names
3. Updated Styling
Result
Leaderboard now displays actual review data with proper styling and complete borders.
The PR by copilot missed some of the edge cases and error handling. This is tested with hardcoded data for now, it functions correctly on my system.
Summary by CodeRabbit
Bug Fixes
Style Updates