Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/lib/statsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface PRDetails {
mergedAt: string;
repoName: string;
number: number;
points: number;
}

interface Contributor {
Expand Down Expand Up @@ -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)
Expand All @@ -96,6 +98,34 @@ 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,
};
for (const level of Object.keys(levelPointsMap)) {
if (labelNames.includes(level)) {
return levelPointsMap[level];
}
}

return 0; // No points if no level label
};

// Time filter utility functions
const getTimeFilterDate = (filter: TimeFilter): Date | null => {
const now = new Date();
Expand Down Expand Up @@ -163,11 +193,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
};
Expand Down Expand Up @@ -319,6 +352,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({
Expand All @@ -327,6 +363,7 @@ export function CommunityStatsProvider({ children }: CommunityStatsProviderProps
mergedAt: pr.merged_at,
repoName,
number: pr.number,
points: prPoints,
});
}
});
Expand Down
Loading