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
68 lines (58 loc) · 2.15 KB
/
Copy pathscript.js
File metadata and controls
68 lines (58 loc) · 2.15 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
const USER = "AschwinSiaila";
const REPOS_URL = `https://api.github.com/users/${USER}/repos`;
const nameAndPicture = document.getElementById("nameandpicture");
const projectsContainer = document.getElementById("projects");
const NameandPicture = () => {
const personal_ID = `https://api.github.com/users/${USER}`;
fetch(personal_ID)
.then((res) => res.json())
.then((data) => {
global__UserData = data;
})
.then(() => NameAndPicture());
};
const NameAndPicture = () => {
const picture = global__UserData.avatar_url;
nameAndPicture.innerHTML += `
<img class="profile-pic" src="${picture}" alt="Picture of gitHub-user"/>
<div class="profile-name">${USER}</div>
`;
};
const fetchRepositories = () => {
fetch(REPOS_URL)
.then((res) => res.json())
.then((data) => {
const technigoRepositories = data.filter((repo) => repo.name.includes("project-") && repo.fork);
console.log(technigoRepositories);
technigoRepositories.forEach((repo) => {
projectsContainer.innerHTML += `
<div class="project-info">
<a class="project-links" href="${repo.html_url}">${repo.name} with default branch ${repo.default_branch}</a>
<p class="push">Recent push: ${new Date(repo.pushed_at).toDateString()}</p>
<a href="${repo.html_url}"><p class="commits" id="commit-${repo.name}">Commits amount: </p></a>
</div>
`;
});
fetchPullRequestArray(technigoRepositories);
drawProgressChart(technigoRepositories);
});
};
const fetchPullRequestArray = (allrepositories) => {
allrepositories.forEach((repo) => {
fetch(`https://api.github.com/repos/Technigo/${repo.name}/pulls`)
.then((res) => res.json())
.then((data) => {
const myPullRequest = data.find((pull) => pull.user.login === repo.owner.login);
fetchCommits(myPullRequest.commits_url, repo.name);
});
});
};
const fetchCommits = (myCommitsUrl, myRepoName) => {
fetch(myCommitsUrl)
.then((res) => res.json())
.then((data) => {
document.getElementById(`commit-${myRepoName}`).innerHTML += data.length;
});
};
NameandPicture();
fetchRepositories();