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
92 lines (76 loc) · 2.99 KB
/
Copy pathscript.js
File metadata and controls
92 lines (76 loc) · 2.99 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
const USER = `Ajliin`
const REPOS_URL = `https://api.github.com/users/${USER}/repos`
const firstContainer = document.getElementById('first')
const projectContainer = document.getElementById('projects')
// ------------FIRST FETCH FUNCTION------------
const fetchRepos =() => {
fetch(REPOS_URL)
.then ((response) => {
return response.json()
})
.then ((data) => {
repoInfo(data)
})
}
fetchRepos()
// ------------function for first lines inside FIRST FETCH FUNCTION------------
const repoInfo = ((data) =>{
first.innerHTML = `
<div>
<h1>Welcome to ${data[0].owner.login}s GitHub Tracker</h1>
<img class='profile-img' src='https://avatars.githubusercontent.com/u/84288114?v=4' alt='profile pic Ajliin'>
</div>
<div class=info-square>
<h2>Elin Diczfalusy</h2>
<p>User name: ${data[0].owner.login}</p>
<p>GitHub page: <a href='${data[0].owner.html_url}'>${data[0].owner.html_url}</a></p>
</div>`
// ------------function filters out the forked repos from Technigo
const forkedRepo = data.filter((repo) => repo.fork && repo.name.startsWith('project-'))
// ------------function to chart.js on how many repos
drawChart(forkedRepo.length)
// ------------forEach repo --> send to innerHTML
forkedRepo.forEach((repo) => {
let dateString = new Date(repo.pushed_at)
projectContainer.innerHTML += `<div class ='project'>
<p>Project name: ${repo.name}</p>
<p>Project url: <a href='${repo.html_url}'> ${repo.html_url}</a></p>
<p>Default branch: ${repo.default_branch}</p>
<p>Last push: ${dateString.toUTCString()}
<p id='commit-${repo.name}'>Commits amount: </p></div>`
})
getProjectInfo(forkedRepo)
})
getProjectInfo = (allRepositories) => {
allRepositories.forEach((project)=>{
const PULL_API = `https://api.github.com/repos/technigo/${project.name}/pulls?per_page=100`
// ------------SECOND FETCH FUNCTION------------
const fetchProjectinfo = (forkedRepo) => {
fetch(PULL_API)
.then ((response) => {
return response.json()
})
.then ((json) => {
const myPullRequest = json.find((pull) => (pull.user.login === project.owner.login))
// Första är alla användare, project.owner.login
if (myPullRequest) {
fetchCommits(myPullRequest.url, project.name)
}else{
console.log('else part in function works', myPullRequest)
document.getElementById(`commit-${project.name}`).innerHTML += 'No pull request done yet'
}
})
}
fetchProjectinfo()
})
}
// ------------THRID FETCH FUNCTION------------
const fetchCommits = ((commitUrl, projectName) => {
fetch(commitUrl)
.then ((response) => {
return response.json()
})
.then ((data) => {
document.getElementById(`commit-${projectName}`).innerHTML += `${data.commits}`
})
})