Skip to content
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

💥FIX : Missing Total Contributions number on Contributors page #720

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all 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
17 changes: 9 additions & 8 deletions contributor/contributor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Fetch data from GitHub API
async function fetchData() {
try {
Expand Down Expand Up @@ -27,13 +26,13 @@ async function fetchData() {
}

// Render stats
function renderStats(repoStats, contributorsCount) {
function renderStats(repoStats, contributorsCount, totalContributions) {
const statsGrid = document.getElementById('statsGrid');
const stats = [
{ label: 'Contributors', value: contributorsCount, icon: 'users' },
{ label: 'Total Contributions', value: repoStats.contributors?.reduce((sum, contributor) => sum + contributor.contributions, 0) || 0, icon: 'git-commit' },
{ label: 'GitHub Stars', value: repoStats.stargazers_count || 0, icon: 'star' },
{ label: 'Forks', value: repoStats.forks_count || 0, icon: 'git-branch' }
{ label: 'Contributors', value: contributorsCount, icon: 'users' },
{ label: 'Total Contributions', value: totalContributions, icon: 'git-commit' },
{ label: 'GitHub Stars', value: repoStats.stargazers_count || 0, icon: 'star' },
{ label: 'Forks', value: repoStats.forks_count || 0, icon: 'git-branch' }
];

statsGrid.innerHTML = stats.map(stat => `
Expand Down Expand Up @@ -88,7 +87,10 @@ async function init() {

const { contributors, repoStats } = await fetchData();

renderStats(repoStats, contributors.length);
// Calculate total contributions
const totalContributions = contributors.reduce((sum, contributor) => sum + contributor.contributions, 0);

renderStats(repoStats, contributors.length, totalContributions);
renderContributors(contributors);

loading.style.display = 'none';
Expand Down Expand Up @@ -118,4 +120,3 @@ function scrollToContribute() {

// Initialize the page when the DOM is loaded
document.addEventListener('DOMContentLoaded', init);

Loading