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
85 lines (71 loc) · 2.76 KB
/
script.js
File metadata and controls
85 lines (71 loc) · 2.76 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
const USER = 'eyahya-khan'
const userContainer = document.getElementById('myProfile')
const searchField = document.getElementById('search-field')
const searchForm = document.getElementById('search-form')
const REPOS_URL = `https://api.github.com/users/${USER}/repos?per_page=100`
const USER_URL = `https://api.github.com/users/${USER}`
const projectsContainer = document.getElementById('projects')
const ldsripple = document.getElementById('loading')
const Auth = {
method: 'GET',
headers: {
Authorization: `${API_TOKEN}`
}
}
let repos;
//profile image and info
const userProfile = () => {
fetch(USER_URL, Auth)
.then(res => res.json())
.then(data => {
userContainer.innerHTML = `
<div class="profileinfo">
<h2>${data.name}</h2>
<a href="https://github.com/eyahya-khan">@${data.login}</a>
<p>${data.location}</p>
</div>
<div class="profileimg"><img src="${data.avatar_url}"/></div>
</div>`
})
}
userProfile()
const getRepos = () => {
fetch(REPOS_URL, Auth)
.then(response => response.json())
.then(data => {
const forkedRepos = data.filter(repo => repo.fork && repo.name.startsWith('project-'))
getPullRequests(forkedRepos)
drawChart(forkedRepos.length)
})
}
getRepos()
//function to get the repos
const getPullRequests = (repos) => {
projectsContainer.innerHTML = '';
repos.forEach(repo => {
fetch(`https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`, Auth)
.then(res => res.json())
.then(data => {
const myPullRequest = data.filter((pull) => { return pull.user.login === repo.owner.login })
const commitUrl = myPullRequest[0].commits_url
fetch(commitUrl)
.then(res => res.json())
.then(data => {
const numberCommit = data.length
//added function so the DOM do not self close tags
let boxHtml = `<div class="box-repo ${repo.name}">`;
boxHtml += `<h3>${repo.name}</h3>`
boxHtml += `<p id="commit-${repo.name}">Number of commits: ${numberCommit}</p>`
boxHtml += `<p>Created at: ${new Date(repo.created_at).toDateString()}</p>`
boxHtml += `<p>Last update: ${new Date(repo.pushed_at).toDateString()}</p>`
boxHtml += `<p>Default branch: ${repo.default_branch}</p>`
boxHtml += `<p>First comment: ${data[0].commit.message}</p>`
boxHtml += `<p>Last comment: ${data[numberCommit-1].commit.message}</p>`
boxHtml += `<p><a href="${repo.html_url}" target="_blank">Go to repo</a></p>`
boxHtml += '</div>'
projectsContainer.innerHTML += boxHtml; //closing the div tag
ldsripple.style.display = 'none' //loading icon
})
})
})
}