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 (74 loc) · 2.65 KB
/
script.js
File metadata and controls
85 lines (74 loc) · 2.65 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 = "ruruahn";
const REPOS_URL = `https://api.github.com/users/${USER}/repos`;
const projectsContainer = document.getElementById("projects-container");
const userContainer = document.getElementById("user-container");
const getUser = () => {
fetch(`https://api.github.com/users/${USER}`)
.then((response) => response.json())
.then((data) => {
userContainer.innerHTML += /*html*/ `
<img class="user-image" src="${data.avatar_url}"/>
<h2 class="user-name">${data.login}</h2>
`;
});
};
getUser();
const getRepos = () => {
fetch(REPOS_URL)
.then((response) => response.json())
.then((data) => {
const technigoProjects = data.filter((repo) => repo.fork && repo.name.startsWith("project-"));
technigoProjects.sort((oldestRepo, newestRepo) => new Date(newestRepo.pushed_at) - new Date(oldestRepo.pushed_at));
technigoProjects.forEach((repo) => {
projectsContainer.innerHTML += /*html*/ `
<a class="project-link" href="${repo.html_url}" target="_blank">
<div class="project" id="${repo.name}-container">
<h3 class="project-name">${repo.name}</h3>
<p class="project-info">Default branch ${repo.default_branch}</p>
<p class="project-info">Recent push: ${new Date(repo.pushed_at).toDateString()}</p>
<p class="project-info" id="commits-${repo.name}">Amount of commits: </p>
</div>
</a>
<hr>
`;
});
getPullRequests(technigoProjects);
drawChart(technigoProjects.length);
});
};
getRepos();
const getPullRequests = (repos) => {
repos.forEach((repo) => {
fetch(`https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=100`)
.then((response) => response.json())
.then((data) => {
const filteredPull = data.find((pull) => pull.user.login === repo.owner.login);
if (filteredPull) {
getCommits(filteredPull.commits_url, repo.name);
getReview(filteredPull.review_comments_url, repo.name);
} else {
document.getElementById(`commits-${repo.name}`).innerHTML = "No pull request";
}
});
});
};
const getCommits = (url, repoName) => {
fetch(url)
.then((response) => response.json())
.then((data) => {
document.getElementById(`commits-${repoName}`).innerHTML += data.length;
});
};
const getReview = (url, repoName) => {
fetch(url)
.then((response) => response.json())
.then((data) => {
if (data.length === 0) {
document.getElementById(`${repoName}-container`).innerHTML += "";
} else {
document.getElementById(`${repoName}-container`).innerHTML += /*html*/ `
<p class="project-info">Reviewed by ${data[0].user.login}</p>
`;
}
});
};