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
99 lines (77 loc) · 2.63 KB
/
script.js
File metadata and controls
99 lines (77 loc) · 2.63 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
88
89
90
91
92
93
94
95
96
97
98
const username = 'id4h4lling'
let reponame = ''
const API_GIT_URL = `https://api.github.com/users/${username}/repos`
const API_GIT_USER = `https://api.github.com/users/${username}` //to get a hold of profilepicture
const userInfo = document.getElementById('userInfo')
const projects = document.getElementById('projects')
// paus for now, try token another time.
const options = {
method: 'GET',
headers: {
// Authorization: `token ${API_TOKEN}`
}
}
//User info
fetch (API_GIT_USER, options)
.then(res => res.json())
.then(user => {
console.log(user)
userInfo.innerHTML += `
<div class="user-info">
<img class="profile-img" src="${user.avatar_url}">
<h2> ${username}</h2>
<p> ${user.bio}</p>
</div>
`
})
//fetch repos
const getRepos = () =>{
fetch (API_GIT_URL, options)
.then(res => res.json())
.then(data => {
console.log(data)
//filter out and only show the forked ones, filter out Technigo projects
const forkedRepos = data.filter((repo) => repo.fork && repo.name.startsWith("project-"))
console.log(forkedRepos)
forkedRepos.forEach((repo) => {
projects.innerHTML+=
` <div class="card" id=${repo.id}>
<h2><a href="${repo.html_url}">${repo.name}</a></h2>
<p>Default branch: ${repo.default_branch}</p>
<p class = "repo"id="commit-${repo.name}"">Commits Done: </p>
<p>Recent push: ${new Date (repo.pushed_at).toDateString()}</p>
</div> `
})
fetchPullRequests(forkedRepos)
drawChart(forkedRepos.length)
})
}
getRepos()
const fetchPullRequests = (repos) => {
repos.forEach((repo => {
fetch (`https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`)
.then(res => res.json())
.then(data =>
{
//filter out pr
const pulls = data.find((pull) => pull.user.login === repo.owner.login);
if (pulls) {
fetchCommits(pulls.commits_url, repo.name)
}
else {
document.getElementById(`commit-${repo.name}`).innerHTML =
'Commits Done: (Pull request unavailable)'
}
})
})
)}
const fetchCommits = (myCommitsUrl, myRepoName) => {
fetch(myCommitsUrl, options)
.then((res) => {
return res.json()
})
.then((data) => {
document.getElementById(`commit-${myRepoName}`).innerHTML += data.length
console.log("data", data)
})
}