refactor: consolidate duplicate date-utility and repo-analytics-utili…#2731
refactor: consolidate duplicate date-utility and repo-analytics-utili…#2731harshitanagpal05 wants to merge 4 commits into
Conversation
GSSoC Label Checklist 🏷️@Umbrella-io — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
|
Great refactoring work — consolidating duplicated code is exactly what we need right now. Net -270 lines is solid. A few issues to address before merge:
Fix these and this is merge-ready. The consolidation itself is well done. |
|
Hi, I’ve addressed all the requested review changes in PR #2731.
The branch has been updated and the original behavior is preserved. Could you please review it again whenever you get a chance? |
Priyanshu-byte-coder
left a comment
There was a problem hiding this comment.
Good DRY refactoring — extracts shared fetchActiveDates to reduce duplication across streak/consistency-score routes.
|
Approved — has merge conflicts. Please rebase on main. |
|
This has merge conflicts with main. Please rebase/resolve conflicts and make sure CI is green — then it'll get a fresh review. |
Related Issue
Closes #2567
Type of Change
Summary
This PR removes duplicated helper logic across multiple Next.js API endpoints by consolidating date range calculations, commit streak processing, and repository analytics into shared utility modules.
Previously, several routes maintained their own versions of the same fetch and aggregation logic, increasing maintenance overhead and the risk of inconsistent results.
This refactor creates single sources of truth while preserving existing behavior.
What Changed
1. Centralized Date & Streak Utilities
Created shared logic in:
src/lib/streak.tsAdded:
fetchActiveDatesFeatures:
Refactored:
src/app/api/metrics/streak/route.tsfetchActiveDatessrc/app/api/metrics/consistency-score/route.tssrc/app/api/metrics/weekly-summary/route.tsRemoved duplicate:
getCurrentWeekStartUtccalculateCurrentStreakfetchActiveDatessrc/app/api/badge/streak-shield/route.tssrc/lib/public-profile-data.ts2. Shared Week Calculation Helper
Updated:
src/lib/date-utils.tsChanges:
getUtcWeekStartRefactored:
src/app/api/metrics/weekly-summary/route.tssrc/app/api/metrics/pr-review-time/route.tsRemoved duplicate week-start implementations.
3. Consolidated Repository Analytics
Created:
src/lib/repo-analytics-utils.tsAdded:
fetchTopReposSupports:
Refactored:
src/lib/public-profile-data.tssrc/app/api/metrics/repo-health/route.tssrc/app/api/metrics/repos/route.tsCode Quality Impact
Changes:
Testing