-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathcontributor.js
32 lines (31 loc) · 1.16 KB
/
contributor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
async function fetchContributors(owner,repo){
try{
const response = await fetch(`https://api.github.com/repos/${owner}/${repo}/contributors`);
const data = await response.json();
return data;
if(!response.ok){
throw new Error('Request Failed!');
}
const contributors= await response.json();
return contributors;
}catch(error){
console.log(error.message);
}
return[];
}
async function displayContributors(contributors){
const contributorsList = document.getElementById('contributors-list');
for (const contributor of contributors){
const li = document.createElement('li');
li.innerHTML = `
<img class="contributor-image" src="${contributor.avatar_url}" alt="${contributor.login}" width="100" height="100">
<a href="https://github.com/${contributor.login}" target="_blank">${contributor.login}</a>
`;
contributorsList.append(li);
}
}
const owner='Priyanshi662';
const repo='FunFusion';
fetchContributors(owner,repo)
.then(contributors => displayContributors(contributors))
.catch(error => console.log(error.message));