forked from Technigo/project-github-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
87 lines (82 loc) · 4.13 KB
/
script.js
File metadata and controls
87 lines (82 loc) · 4.13 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
79
80
81
82
83
84
85
86
87
// Github profile
fetch('https://api.github.com/users/rawisou')
.then((res) => res.json())
.then((data) => {
const profile = document.getElementById('profile')
profile.innerHTML = `
<h1>GitHub Tracker</h1>
<h2>${data.name}</h2>
<img class="profile-image" id="profileImage" src="${data.avatar_url}" alt="Github Profile Image">
<p><img class="ghlogo" src=./github.png><a href="${data.html_url}"> Github account: ${data.login}</a></p>
`
})
.catch((err) => console.log(err))
// Repos forked from Technigo
fetch('https://api.github.com/users/rawisou/repos')
.then((res) => res.json())
.then((data) => {
const technigoRepos = data.filter(
(repos) => repos.fork && repos.full_name.includes('project-')
)
getPullRequests(technigoRepos)
drawChart(technigoRepos.length)
})
.catch((err) => console.log(err))
const getPullRequests = (repos) => {
const projectCard = document.getElementById('projectCard')
repos.forEach(repo => {
fetch(`https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`)
.then((res) => res.json())
.then((pull) => {
const myPullRequests = pull.find(
(pull) => pull.user.login === repo.owner.login
)
fetch(`https://api.github.com/repos/rawisou/${repo.name}/commits?per_page=100`)
.then((res) => res.json())
.then((myCommits) => {
let num = myCommits.length
if (myPullRequests != undefined) {
projectCard.innerHTML += `
<div class="card">
<h3><a href="${repo.html_url}"><span>${repo.full_name.replace('rawisou/project-', '').replace('-', ' ')}</span></a></h3>
<p><span class ="bolded"> Default branch: </span> ${repo.default_branch}</p>
<p><span class ="bolded"> Pushed at:</span> ${new Date(repo.pushed_at).toDateString()}</p>
<p><span class ="bolded"> Number of commits:</span> ${num}</p>
<p><a href="${myPullRequests.html_url}"><img class="pointing-right" src=./pointing-right.png> View the pull request</a></p>
</div>
`
} else if (repo.name === 'project-weather-app') {
projectCard.innerHTML += `
<div class="card">
<h3><a href="${repo.html_url}"><span>${repo.full_name.replace('rawisou/project-', '').replace('-', ' ')}</span></a></h3>
<p><span class ="bolded"> Default branch: </span> ${repo.default_branch}</p>
<p><span class ="bolded"> Pushed at:</span> ${new Date(repo.pushed_at).toDateString()}</p>
<p><span class ="bolded"> Number of commits:</span> ${num}</p>
<p><a href="https://github.com/Technigo/project-weather-app/pull/215"><img class="pointing-right" src=./pointing-right.png> View the pull request</a></p>
</div>
`
} else if (repo.name === 'project-music-releases') {
projectCard.innerHTML += `
<div class="card">
<h3><a href="${repo.html_url}"><span>${repo.full_name.replace('rawisou/project-', '').replace('-', ' ')}</span></a></h3>
<p><span class ="bolded"> Default branch: </span> ${repo.default_branch}</p>
<p><span class ="bolded"> Pushed at:</span> ${new Date(repo.pushed_at).toDateString()}</p>
<p><span class ="bolded"> Number of commits:</span> ${num}</p>
<p><a href="https://github.com/Technigo/project-music-releases/pull/185"><img class="pointing-right" src=./pointing-right.png> View the pull request</a></p>
</div>
`
} else {
projectCard.innerHTML += `
<div class="card">
<h3><a href="${repo.html_url}"><span>${repo.full_name.replace('rawisou/project-', '').replace('-', ' ')}</span></a></h3>
<p><span class ="bolded"> Default branch: </span> ${repo.default_branch}</p>
<p><span class ="bolded"> Pushed at:</span> ${new Date(repo.pushed_at).toDateString()}</p>
<p><span class ="bolded"> Number of commits:</span> ${num}</p>
<p><span class ="bolded"> Pull Request:</span> No pull request </p>
</div>
`
}
})
})
})
}