From ac627ecf8f67978f169ee8a4131766e1e14753e9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 30 Sep 2025 18:23:11 +0000 Subject: [PATCH 1/6] Initial plan From 25c4c8fbcc9faed113e940440a3436f9aabd21a5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 30 Sep 2025 18:31:28 +0000 Subject: [PATCH 2/6] Implement label-based leaderboard points calculation Co-authored-by: Adez017 <142787780+Adez017@users.noreply.github.com> --- src/lib/statsProvider.tsx | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/lib/statsProvider.tsx b/src/lib/statsProvider.tsx index af910a8c..de0a4dd3 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,31 @@ 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 + if (labelNames.includes('level 1')) { + return 10; + } else if (labelNames.includes('level 2')) { + return 30; + } else if (labelNames.includes('level 3')) { + return 50; + } + + return 0; // No points if no level label +}; + // Time filter utility functions const getTimeFilterDate = (filter: TimeFilter): Date | null => { const now = new Date(); @@ -163,11 +190,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 +349,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 +360,7 @@ export function CommunityStatsProvider({ children }: CommunityStatsProviderProps mergedAt: pr.merged_at, repoName, number: pr.number, + points: prPoints, }); } }); From cbbfa735004c8f85df060aeca31f219a1630be14 Mon Sep 17 00:00:00 2001 From: aditya singh rathore Date: Wed, 1 Oct 2025 00:55:10 +0530 Subject: [PATCH 3/6] Update statsProvider.tsx Co-Authored-By: Sanjay Viswanathan --- src/lib/statsProvider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/statsProvider.tsx b/src/lib/statsProvider.tsx index de0a4dd3..f3549153 100644 --- a/src/lib/statsProvider.tsx +++ b/src/lib/statsProvider.tsx @@ -111,7 +111,7 @@ const calculatePointsForPR = (labels?: Array<{ name: string }>): number => { return 0; // No points if "recode" label is missing } - // Check for level labels and assign points accordingly + // Check for level labels and assign points accordingly wiht new point system if (labelNames.includes('level 1')) { return 10; } else if (labelNames.includes('level 2')) { From 3a85a77b3e1473cb8077676d108144dbc6d0fde3 Mon Sep 17 00:00:00 2001 From: aditya singh rathore <142787780+Adez017@users.noreply.github.com> Date: Wed, 1 Oct 2025 00:58:37 +0530 Subject: [PATCH 4/6] Update src/lib/statsProvider.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/lib/statsProvider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/statsProvider.tsx b/src/lib/statsProvider.tsx index f3549153..07f0dc1a 100644 --- a/src/lib/statsProvider.tsx +++ b/src/lib/statsProvider.tsx @@ -111,7 +111,7 @@ const calculatePointsForPR = (labels?: Array<{ name: string }>): number => { return 0; // No points if "recode" label is missing } - // Check for level labels and assign points accordingly wiht new point system + // Check for level labels and assign points accordingly with new point system if (labelNames.includes('level 1')) { return 10; } else if (labelNames.includes('level 2')) { From ac1d864dd168b096d44437ace368c0677c4703f1 Mon Sep 17 00:00:00 2001 From: aditya singh rathore <142787780+Adez017@users.noreply.github.com> Date: Wed, 1 Oct 2025 10:03:26 +0530 Subject: [PATCH 5/6] Update src/lib/statsProvider.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/lib/statsProvider.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib/statsProvider.tsx b/src/lib/statsProvider.tsx index 07f0dc1a..d723f500 100644 --- a/src/lib/statsProvider.tsx +++ b/src/lib/statsProvider.tsx @@ -112,12 +112,15 @@ const calculatePointsForPR = (labels?: Array<{ name: string }>): number => { } // Check for level labels and assign points accordingly with new point system - if (labelNames.includes('level 1')) { - return 10; - } else if (labelNames.includes('level 2')) { - return 30; - } else if (labelNames.includes('level 3')) { - return 50; + const levelPointsMap: { [key: string]: number } = { + 'level 1': 10, + 'level 2': 30, + 'level 3': 50, + }; + for (const level of Object.keys(levelPointsMap)) { + if (labelNames.includes(level)) { + return levelPointsMap[level]; + } } return 0; // No points if no level label From fdc5c9b45d7e2121143b7608da587d36698cad65 Mon Sep 17 00:00:00 2001 From: aditya singh rathore <142787780+Adez017@users.noreply.github.com> Date: Wed, 1 Oct 2025 10:05:03 +0530 Subject: [PATCH 6/6] Update src/lib/statsProvider.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/lib/statsProvider.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib/statsProvider.tsx b/src/lib/statsProvider.tsx index d723f500..7ec17d4e 100644 --- a/src/lib/statsProvider.tsx +++ b/src/lib/statsProvider.tsx @@ -117,10 +117,9 @@ const calculatePointsForPR = (labels?: Array<{ name: string }>): number => { 'level 2': 30, 'level 3': 50, }; - for (const level of Object.keys(levelPointsMap)) { - if (labelNames.includes(level)) { - return levelPointsMap[level]; - } + const matchedLevel = labelNames.find(label => levelPointsMap.hasOwnProperty(label)); + if (matchedLevel) { + return levelPointsMap[matchedLevel]; } return 0; // No points if no level label