-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathscript.js
More file actions
78 lines (72 loc) · 2.4 KB
/
script.js
File metadata and controls
78 lines (72 loc) · 2.4 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
73
74
75
76
77
78
// USERNAME
let username = 'rijad90'
// API
const GITHUB_USER_API = `https://api.github.com/users/${username}`
const GITHUB_REPOS_API = `https://api.github.com/users/${username}/repos`
//FETCH API TO PROFILE. INJECTS PIC,USERNAME,BIO
const getProfile = () => {
fetch(GITHUB_USER_API)
.then((res) => res.json())
.then((data) => {
profile.innerHTML += `
<div class="profile">
<h1> Github Tracker </h1>
<img class="profile_picture" src ="${data.avatar_url}"/>
<p>${username}</p>
<p>${data.bio}</p>
</div>
`
})
}
getProfile()
//DOM SELECTOR
const projects = document.getElementById('projects-container')
//FETCH API AND FILTERS REPO. INJECTS REPO URL, NAME, DEF BRANCH, PUSHED DATE AND COMMIT
const fetchRepo = () => {
fetch(GITHUB_REPOS_API)
.then((res) => res.json())
.then((data) => {
const technigoRepo = data.filter(
// FILTERS MY FORKED REPOS ONLY TO DESPLAY THE ONES NAMNED "project-"
(repo) => repo.name.includes('project-') && repo.fork
)
technigoRepo.forEach((repo) => {
projects.innerHTML += `
<div class="projects">
<a href="${repo.html_url}" target="_blank" class="">${repo.name.toUpperCase()}</a>
<p>Default branch: ${repo.default_branch}</p>
<p>Most recent push: ${new Date(repo.pushed_at).toISOString().substring(0, 10)}</p>
<p id="commit-${repo.name}"> Number of commits: </p>
</div>
`
})
fetchPull(technigoRepo)
drawChart(technigoRepo.length)
})
}
// FETCH ALL REPO PULLS
const fetchPull = (allRepo) => {
allRepo.forEach((repo) => {
fetch(`https://api.github.com/repos/Technigo/${repo.name}/pulls`)
.then((res) => res.json())
.then((data) => {
const myPullRequests = data.find(
(pull) => pull.user.login === repo.owner.login
)
if (myPullRequests) {
fetchCommits(myPullRequests.commits_url, repo.name)
} else {
document.getElementById(`commit-${repo.name}`).innerHTML +=
'No pull request'
}
})
})
}
const fetchCommits = (myCommitsUrl, myRepoName) => {
fetch(myCommitsUrl)
.then((response) => response.json())
.then((data) => {
document.getElementById(`commit-${myRepoName}`).innerHTML += data.length
})
}
fetchRepo()