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
97 lines (87 loc) · 2.8 KB
/
script.js
File metadata and controls
97 lines (87 loc) · 2.8 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
// main fetch and function and put the DOM here
const projectsContainer = document.getElementById('projects');
const headerContainer = document.getElementById('header');
const USER = 'DALA746';
const ALL_MY_REPOS = `https://api.github.com/users/${USER}/repos`;
const button = document.getElementById('button');
const searchProject = () => {
let input = document.getElementById('searchbar').value;
input = input.toLowerCase();
let repo = document.getElementsByClassName('repo');
for (i = 0; i < repo.length; i++) {
if (!repo[i].innerHTML.toLowerCase().includes(input)) {
repo[i].style.display = 'none';
} else {
repo[i].style.display = 'block';
}
}
};
const renderHTML = (repos) => {
console.log(repos);
repos.forEach((repo) => {
headerContainer.innerHTML = `
<div class="info-about-user">
<img class="profile-img"src="${repo.owner.avatar_url}" />
</div>
<h3>${repo.owner.login}</h3>
<div>SOME STATS</div>
`;
projectsContainer.innerHTML += `
<div class="repo">
<a href="${
repo.clone_url
}" target="_blank"><div class="icon-container"><i class="fal fa-book" style="font-size:25px;color:var(--grey);"></i><h3>${
repo.name
}</h3></div> </a>
<p id="commit-${repo.name}"><span class="bold">Commits amount: </span></p>
<p><span class="bold">Language:</span> ${repo.language}</p>
<p><span class="bold">Latest push update:</span> ${new Date(
repo.pushed_at
).toDateString()}</p>
<p><span class="bold">Default branch:</span> ${repo.default_branch}</p>
</div>
`;
});
};
const getRepos = () => {
fetch(ALL_MY_REPOS)
.then((res) => res.json())
.then((json) => {
console.log(json);
const forkedRepos = json.filter(
(repo) => repo.fork && repo.name.startsWith('project-')
);
drawChart(forkedRepos.length);
renderHTML(forkedRepos);
// getPullRequests(forkedRepos);
});
};
getRepos();
// GETTING ALL MY PULL REQUESTS
// const getPullRequests = (forkedRepos) => {
// forkedRepos.forEach((repo) => {
// fetch(`https://api.github.com/repos/Technigo/${repo.name}/pulls`)
// .then((res) => res.json())
// .then((data) => {
// console.log(data);
// const myPullRequests = data.find(
// (pull) => pull.user.login === repo.owner.login
// );
// console.log(myPullRequests, 'data');
// getCommits(myPullRequests.commits_url, repo.name);
// });
// });
// };
const getCommits = (url, myRepoName) => {
fetch(url)
.then((res) => res.json())
.then((data) => {
const numberOfCommits = data.length;
document.getElementById(`commit-${myRepoName}`).innerHTML +=
numberOfCommits;
});
};
button.addEventListener('click', (e) => {
e.preventDefault();
searchProject();
});