diff --git a/src/lib/statsProvider.tsx b/src/lib/statsProvider.tsx index af910a8c..7ec17d4e 100644 --- a/src/lib/statsProvider.tsx +++ b/src/lib/statsProvider.tsx @@ -48,6 +48,7 @@ interface PRDetails { mergedAt: string; repoName: string; number: number; + points: number; } interface Contributor { @@ -75,6 +76,7 @@ interface PullRequestItem { title?: string; html_url?: string; number?: number; + labels?: Array<{ name: string }>; } // Enhanced contributor type for internal processing (stores all PRs) @@ -96,6 +98,33 @@ const MAX_CONCURRENT_REQUESTS = 8; const CACHE_DURATION = 5 * 60 * 1000; // 5 minutes cache const MAX_PAGES_PER_REPO = 20; +// Function to calculate points based on PR labels +const calculatePointsForPR = (labels?: Array<{ name: string }>): number => { + if (!labels || labels.length === 0) { + return 0; // No points if no labels + } + + const labelNames = labels.map(label => label.name.toLowerCase()); + + // Check if PR has the "recode" label + if (!labelNames.includes('recode')) { + return 0; // No points if "recode" label is missing + } + + // Check for level labels and assign points accordingly with new point system + const levelPointsMap: { [key: string]: number } = { + 'level 1': 10, + 'level 2': 30, + 'level 3': 50, + }; + const matchedLevel = labelNames.find(label => levelPointsMap.hasOwnProperty(label)); + if (matchedLevel) { + return levelPointsMap[matchedLevel]; + } + + return 0; // No points if no level label +}; + // Time filter utility functions const getTimeFilterDate = (filter: TimeFilter): Date | null => { const now = new Date(); @@ -163,11 +192,14 @@ export function CommunityStatsProvider({ children }: CommunityStatsProviderProps isPRInTimeRange(pr.mergedAt, currentTimeFilter) ); + // Calculate total points from all filtered PRs + const totalPoints = filteredPRs.reduce((sum, pr) => sum + pr.points, 0); + return { username: contributor.username, avatar: contributor.avatar, profile: contributor.profile, - points: filteredPRs.length * POINTS_PER_PR, + points: totalPoints, prs: filteredPRs.length, prDetails: filteredPRs, // For backward compatibility, though we'll use the new function }; @@ -319,6 +351,9 @@ export function CommunityStatsProvider({ children }: CommunityStatsProviderProps } const contributor = contributorMap.get(username)!; + // Calculate points for this PR based on labels + const prPoints = calculatePointsForPR(pr.labels); + // Add detailed PR information to the full list if (pr.title && pr.html_url && pr.merged_at && pr.number) { contributor.allPRDetails.push({ @@ -327,6 +362,7 @@ export function CommunityStatsProvider({ children }: CommunityStatsProviderProps mergedAt: pr.merged_at, repoName, number: pr.number, + points: prPoints, }); } });