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
87 lines (79 loc) · 2.56 KB
/
script.js
File metadata and controls
87 lines (79 loc) · 2.56 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
//DOM selectors
const profileInfo = document.getElementById("profile");
const allProjects = document.getElementById("projects");
const username = "TereseClaesson";
const API_PROFILE = `https://api.github.com/users/${username}`;
const API_URL_REPOS = `https://api.github.com/users/${username}/repos`;
//Functions to get the username and profilepicture
const userProfile = () => {
fetch(API_PROFILE)
.then((res) => res.json())
.then((profileData) => {
profileInfo.innerHTML += `
<img src = "${profileData.avatar_url}">
<h3>${profileData.name}</h3>
<h4> <a href = ${profileData.html_url}> ${profileData.login}</h4>
`;
});
};
//Repos
const repositories = () => {
fetch(API_URL_REPOS)
.then((res) => res.json())
.then((allRepos) => {
const forkedRepos = allRepos.filter(
(repo) => repo.fork && repo.name.startsWith("project-")
);
forkedRepos.forEach((repo) => {
allProjects.innerHTML += `
<div>
<h3> Project name: ${repo.name} </h3>
<p> Latest push: ${new Date(repo.pushed_at).toLocaleString("en-GB", {
dateStyle: "short",
})} </p>
<p> Default branch: ${repo.default_branch}</p>
<a href = ${repo.html_url}>${repo.name}</a>
<p id ="pull-${repo.name}"></p>
<p id ="commit-${repo.name}">Commits:</p>
</div>
`;
commits(repo.commits_url, repo.name);
});
getPullRequest(forkedRepos);
drawChart(forkedRepos.length);
});
};
const getPullRequest = (forkedRepos) => {
forkedRepos.forEach((repo) => {
const PULL_URL = `https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`;
fetch(PULL_URL)
.then((res) => res.json())
.then((pullReqs) => {
let groupProject = true;
pullReqs.forEach((pull) => {
if (pull.user.login === username) {
groupProject = false;
document.getElementById(`pull-${repo.name}`).innerHTML = `
<a href = ${pull.html_url}> Go to pull request </a>
`;
}
});
if (groupProject === true) {
document.getElementById(`pull-${repo.name}`).innerHTML = `
<p> No pull request, group project </p>
`;
}
});
});
};
const commits = (myCommits, repoName) => {
let commitUrl = myCommits.replace("{/sha}", "");
fetch(commitUrl)
.then((res) => res.json())
.then((commitNumber) => {
document.getElementById(`commit-${repoName}`).innerHTML +=
commitNumber.length;
});
};
userProfile();
repositories();