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
111 lines (100 loc) · 3.25 KB
/
script.js
File metadata and controls
111 lines (100 loc) · 3.25 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const username = "Mimmisen";
const API_URL = `https://api.github.com/users/${username}`;
const REPOS_URL = `https://api.github.com/users/${username}/repos`;
// function for token
const options = {
method: "GET",
headers: {
Authorization: `token ${API_TOKEN}`,
},
};
//----------------------------------FETCH 1-------------------------------------
// getting profile pic,user name and link to my github
fetch(API_URL, options)
.then((res) => res.json())
.then((data) => {
headerBox.innerHTML += `
<div>
<a href="${API_URL}">
<img src="${data.avatar_url}" alt="Avatar of ${data.login}">
</a>
</div>
<a href="https://github.com/Mimmisen"><h1 class="username">${data.login}<h1></a>
<div class="my-name">Mimmi Fordal Uddin</div>
`;
});
//----------------------------------FETCH 2-------------------------------------
fetch(REPOS_URL, options)
.then((res) => res.json())
.then((data) => {
//To get my projects and filter them so only the ones starting with projects are displayed
const technigoProjects = data.filter(
(repo) => repo.name.startsWith("project-") && repo.fork
);
showChart(technigoProjects.length);
technigoProjects.forEach((repo) => {
const reponame = repo.name;
fetchTechnigo(reponame);
const projectUrl = repo.html_url;
const defaultBranch = repo.default_branch;
const latestPushRepo = new Date(repo.updated_at).toLocaleDateString(
"sv-SE",
{
year: "numeric",
month: "long",
day: "numeric",
}
);
//displaying project url, name and latest push
document.getElementById("section-projects").innerHTML += `
<div class="section-projects__card box-style">
<div>
<h3 class="repo-title bold-text"><a class="nav-link" href='${projectUrl}'>${reponame}</a></h3>
<p><span class="bold-text">Latest update:</span> ${latestPushRepo}</p>
<p id="commits-${reponame}"></p>
<p> default branch: ${defaultBranch}</p>
</div>
</div>
`;
});
});
// function for the commits url and name
const displayCommits = (commitsUrl, reponame) => {
fetch(commitsUrl, options)
.then((res) => res.json())
.then((data) => {
document.getElementById(`commits-${reponame}`).innerHTML = `
<p class="bold-text">Amount of commits: ${data.length}
</p>
`;
});
};
//function to get the latest push to repo
const fetchTechnigo = (reponame) => {
fetch(
`https://api.github.com/repos/Technigo/${reponame}/pulls?per_page=100`,
options
)
.then((res) => res.json())
.then((data) => {
data.forEach((repo) => {
const commitsUrl = repo.commits_url;
if (repo.user.login === username) {
displayCommits(commitsUrl, reponame);
} else if (
repo.user.login === "sukiphan97" &&
reponame === "project-chatbot"
) {
displayCommits(repo.commits_url, reponame);
} else if (
repo.user.login === "kolkri" &&
reponame === "project-weather-app"
) {
displayCommits(repo.commits_url, reponame);
} else {
document.getElementById(`commits-${reponame}`).innerHTML =
"No commits for this repo";
}
});
});
};