Skip to content
Open
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
41 changes: 24 additions & 17 deletions js/contributors.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,55 @@
const cont = document.getElementById('contributor');
const repoUrl = 'https://api.github.com/repos/sahil-sagwekar2652/GitHub-Automation-scripts/contributors';

async function fetchContributors(pageNumber) {
const perPage = 100;
const url = `https://api.github.com/repos/sahil-sagwekar2652/GitHub-Automation-scripts/contributors?page=${pageNumber}&per_page=${perPage}`;
const url = `${repoUrl}?page=${pageNumber}&per_page=${perPage}`;

const response = await fetch(url);

if (!response.ok) {
throw new Error(`Failed to fetch contributors data. Status code: ${response.status}`);
}

const contributorsData = await response.json();
return contributorsData;
return response.json();
}

function createContributorCard(contributor) {
const contributorCard = document.createElement('div');
contributorCard.classList.add('contributor-card');

const avatarImg = document.createElement('img');
avatarImg.src = contributor.avatar_url;
avatarImg.alt = `${contributor.login}'s Picture`;

const loginLink = document.createElement('a');
loginLink.href = contributor.html_url;
loginLink.appendChild(avatarImg);

contributorCard.appendChild(loginLink);

return contributorCard;
}

// Function to fetch all contributors
async function fetchAllContributors() {
let allContributors = [];
let pageNumber = 1;

try {
while (true) {
const contributorsData = await fetchContributors(pageNumber);

if (contributorsData.length === 0) {
break;
}

allContributors = allContributors.concat(contributorsData);
pageNumber++;
}

// Display contributors in the honeycomb-like layout
allContributors.forEach((contributor) => {
const contributorCard = document.createElement('div');
contributorCard.classList.add('contributor-card');

const avatarImg = document.createElement('img');
avatarImg.src = contributor.avatar_url;
avatarImg.alt = `${contributor.login}'s Picture`;

const loginLink = document.createElement('a');
loginLink.href = contributor.html_url;
loginLink.appendChild(avatarImg);

contributorCard.appendChild(loginLink);

const contributorCard = createContributorCard(contributor);
cont.appendChild(contributorCard);
});
} catch (error) {
Expand Down