-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathscript.js
More file actions
72 lines (58 loc) · 2.22 KB
/
script.js
File metadata and controls
72 lines (58 loc) · 2.22 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//DOM selectors
const username = 'JensBergqvist'
const projects = document.getElementById("projects")
const API_REPOS = `https://api.github.com/users/${username}/repos`;
const API_PROFIL = `https://api.github.com/users/${username}`
//Picture and name
const profilePic = () => {
fetch(API_PROFIL)
.then(res => res.json())
.then(data => {
// console.log(data)
picture = data.avatar_url
let profilePicture = `<div class = "profile"><h1>${username}</h1> <img class = "photo" src="${picture}" />
</div>`;
return (projects.innerHTML = profilePicture)
})
}
profilePic()
const getRepos = () => {
fetch(API_REPOS)
.then(response => response.json())
.then(data => {
const forkedRepos = data.filter(repo => repo.fork && repo.name.startsWith('project'))
forkedRepos.forEach(repo => {
projects.innerHTML += `<div class='repo-card'>
<a href='${repo.html_url}'><p>Repo name: ${repo.name}</p></a>
<p>Default branch: ${repo.default_branch}</p>
<p>Last push: ${new Date(repo.pushed_at).toDateString()}
<p id =${repo.name}>Number of commits: </p>
</div>
`
})
getPullRequest(forkedRepos)
drawChart(forkedRepos.length)
})
}
const getPullRequest= (repos) => {
repos.forEach((repo)=> {
fetch(`https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=100`)
.then(response => response.json())
.then(data => {
const myPullRequest = data.find((pull)=> pull.user.login === repo.owner.login)
if (myPullRequest) {
getCommits(myPullRequest.commits_url, repo.name)
} else {
document.getElementById(`${repo.name}`).innerHTML=`No pullrequest `
}
})
})
}
const getCommits=(commits, myRepoName) => {
fetch(commits)
.then(response => response.json())
.then(data =>{
document.getElementById(`${myRepoName}`).innerHTML += data.length
})
}
getRepos()