-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1144 from S-ishita/contri
contributors added
- Loading branch information
Showing
3 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const cont = document.getElementById('contributor'); | ||
|
||
// Replace these with the owner and repository name of the repository | ||
const owner = 'vikhyatsingh123'; | ||
const repoName = 'Naruto-Shippuden'; | ||
|
||
// Function to fetch contributors for a given page number | ||
async function fetchContributors(pageNumber) { | ||
const perPage = 100; // You can adjust this based on your needs | ||
const url = `https://api.github.com/repos/${owner}/${repoName}/contributors?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; | ||
} | ||
|
||
// 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); | ||
|
||
cont.appendChild(contributorCard); // Append the contributor card to the container | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
|
||
// Call the function to fetch all contributors and display them in the honeycomb-like layout | ||
fetchAllContributors(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters