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
82 lines (65 loc) · 2.31 KB
/
script.js
File metadata and controls
82 lines (65 loc) · 2.31 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 USER = 'silvertejp89'
const REPOS_URL = `https://api.github.com/users/${USER}/repos`
const PROFILE_URL = `https://api.github.com/users/${USER}`
const projectContainer = document.getElementById('projects')
const profileInfo = document.getElementById("profile");
const getProfile = () => {
fetch(PROFILE_URL)
.then(Response => Response.json())
.then(data => {
// console.log('Profiluris', data)
profileInfo.innerHTML += `
<img src=${data.avatar_url}></img>
<h5>${USER}</h5>
`
})
}
getProfile() //invoking
const getRepos = () => {
fetch(REPOS_URL)
.then(response => response.json())
.then(data => {
// console.log("Here we are!", data)
const forkedRepos = data.filter(
(repo) => repo.name.includes('project-') && repo.fork
);
forkedRepos.forEach(repo => projectContainer.innerHTML += `
<div class='card'>
<a href="${repo.html_url}"><h3>${repo.name}</h3></a>
<p> Default branch: ${repo.default_branch}</p>
<p> Recent push: ${new Date(repo.pushed_at).toDateString()}</p>
<p id='commit-${repo.name}'> Number of commits:</p>
</div>
`)
fetchPullRequestsArray(forkedRepos);
drawChart(forkedRepos.length)
})
}
const fetchPullRequestsArray = (allRepositories) => {
allRepositories.forEach((repo) => {
const PULL_URL = `https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`;
fetch(PULL_URL)
.then(response => response.json())
.then(data => {
console.log(data)
const myPullRequest = data.find(
(pull) => pull.user.login === repo.owner.login
);
console.log('pull request', myPullRequest)
if (myPullRequest) {
fetchCommits(myPullRequest.commits_url, repo.name);
} else {
document.getElementById(`commit-${repo.name}`).innerHTML =
'No pull request done yet';
}
})
})
}
const fetchCommits = (myCommitsUrl, myRepoName) => {
fetch(myCommitsUrl)
.then(res => res.json())
.then(data => {
document.getElementById(`commit-${myRepoName}`).innerHTML += data.length;
});
};
getRepos() //invoking getRepos