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
93 lines (85 loc) · 2.92 KB
/
script.js
File metadata and controls
93 lines (85 loc) · 2.92 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
const USER = "IdaAspen";
const REPOS_URL = `https://api.github.com/users/${USER}/repos`;
const USER_INFO_URL = `https://api.github.com/users/${USER}`;
const projectsContainer = document.getElementById("projects-container");
const userContainer = document.getElementById("user-container");
//get username and profile picture
const getUserInfo = () => {
fetch(USER_INFO_URL)
.then((response) => response.json())
.then((data) => {
userContainer.innerHTML = `
<div class="user-card">
<img src="https://avatars.githubusercontent.com/u/80949028?v=4"
alt="Profile picture"><h2>User name: <a href="https://github.com/IdaAspen">${data.name}</a></h2>
<p>${data.bio}</p>
</div>
`;
});
};
/////////////////////// GET REPOS /////////////////////////////////////////
//Get all repos w/ details
const getRepos = () => {
fetch(REPOS_URL)
.then((response) => response.json())
.then((data) => {
let forkedRepos = data.filter(
(repo) => repo.fork && repo.name.startsWith("project-")
);
//Sorts filtered repos after dates
forkedRepos.sort(
(a, b) => new Date(b.created_at) - new Date(a.created_at)
);
forkedRepos = forkedRepos.reverse();
forkedRepos.forEach(
(repo) =>
(projectsContainer.innerHTML += `
<div class="project-card">
<h3><a href=${repo.html_url} target="_blank">${repo.name.replace(
"-",
" "
)}</a></h3>
<p>Most recent push: ${repo.pushed_at.substring(0, 10)}</p>
<p>Name of default branch: ${repo.default_branch}</p>
<p id="commit-${repo.name}">No of commits: </p>
</div>`),
//pass along filtered repos as an argument when invoke getPullRequest
getPullRequests(forkedRepos)
);
drawChart(forkedRepos.length);
});
};
/////////////////////// GET PR /////////////////////////////////////////
//Get all PRs for each project
const getPullRequests = (repos) => {
repos.forEach((repo) => {
fetch(
`https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=100`
)
.then((res) => res.json())
.then((data) => {
const myPulls = data.find(
(pull) => pull.user.login === repo.owner.login
);
if (myPulls) {
fetchCommits(myPulls.commits_url, repo.name);
} else {
document.getElementById(`commit-${repo.name}`).innerHTML =
"No pull request done ✖️";
}
});
});
};
/////////////////////// GET COMMITS /////////////////////////////////////////
//Get commits for each project
const fetchCommits = (myCommitsUrl, myRepoName) => {
fetch(myCommitsUrl)
.then((response) => response.json())
.then((data) => {
//creating dynamic id
document.getElementById(`commit-${myRepoName}`).innerHTML += data.length;
});
};
//Invoke the functions
getUserInfo();
getRepos();