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
79 lines (70 loc) · 2.54 KB
/
script.js
File metadata and controls
79 lines (70 loc) · 2.54 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
const userSection = document.getElementById ('userSection')
const repoSection = document.getElementById ('repoSection')
const username = 'mistscale'
const API_USER_URL = `https://api.github.com/users/${username}`
const API_REPOS_URL = `https://api.github.com/users/${username}/repos`
const options = {
method: 'GET',
headers: {
Authorization: 'API_TOKEN'
}
}
// Display profile picture and username from user api
const getUser = () => {
fetch(API_USER_URL, options)
.then(res => res.json())
.then(data => {
userSection.innerHTML = `
<img src='${data.avatar_url}' class='profile-img'/>
<h1>${data.login}</h1>`
})
getRepos()
}
const getRepos = () => {
fetch(API_REPOS_URL, options)
.then(res => res.json())
.then(data => {
const forkedRepos = data.filter((repo) => repo.fork && repo.name.startsWith('project'))
forkedRepos.forEach((repo) => {
repoSection.innerHTML += `
<div class='repo-name' id='${repo.name}'>
<h2>${repo.name}</h2>
<p>Repo link: <a href='${repo.html_url}'>here</a></p>
<p>Default branch: ${repo.default_branch}</p>
<p>Recent update: ${new Date(repo.pushed_at).toLocaleDateString('sv-SE')}</p>
</div>`
})
getPullRequests(forkedRepos)
activateChart(forkedRepos.length)
})
const getPullRequests = (forkedRepos) => {
forkedRepos.forEach(repo => {
fetch(`https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=100`, options)
.then(res => res.json())
.then(data => {
const filterPullRequests = data.find((pull) => pull.user.login === repo.owner.login)
if (filterPullRequests) {
document.getElementById(`${repo.name}`).innerHTML += `
<p>Pull request: <a href='${filterPullRequests.html_url}'>here</a></p>`
} else {
document.getElementById(`${repo.name}`).innerHTML += `
<p>Pull request by team member</p>`
}
if (filterPullRequests) {
getCommits(filterPullRequests.commits_url, repo.name)
} else {
document.getElementById(`${repo.name}`).innerHTML += `
<p>Commits by team member</p>`
}
})
})
}
const getCommits = (commitsURL, repoName) => {
fetch(commitsURL)
.then((res) => res.json())
.then (data => {
document.getElementById(repoName).innerHTML += `
<p>Commits: ${data.length}</p>`
})
}}
getUser()