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
89 lines (77 loc) · 2.7 KB
/
Copy pathscript.js
File metadata and controls
89 lines (77 loc) · 2.7 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
let username = 'A1eksa';
const userPicture = `https://api.github.com/users/${username}`;
const REPOS_URL = `https://api.github.com/users/${username}/repos`;
const getUserPicture = () => {
fetch(userPicture)
.then((res) => res.json())
.then((data) => {
const picture = data.avatar_url;
const location = data.location;
const userBio = data.bio;
const url = data.followers_url;
userInfo.innerHTML += `
<img class="user-info_picture" src="${picture}" alt="Picture of gitHub user"/>
<div class="user-info_username">${username}</div>
<div class="user-whole_name"> Aleksandra Safranko</div>
<div class="user-info_location">Location: ${location} 🇸🇪 </div>
<div class="user-info_bio">${userBio} 🐒</div>
`;
});
};
getUserPicture();
const projectsContainer = document.getElementById('projects');
const fetchRepo = () => {
fetch(REPOS_URL)
.then((res) => res.json())
.then((data) => {
const technigoRepo = data.filter(
(repo) => repo.name.includes('project-') && repo.fork
);
technigoRepo.forEach((repo) => {
projectsContainer.innerHTML += `
<div class="repo-card">
<div class="link">
<a href="${repo.html_url}" class="repo-name">${repo.name}</a>
</div>
<div class="branch">
<p class="default-branch">Default branch:${
repo.default_branch
}</p>
</div>
<div class="push">
<h4>Recent push:${new Date(repo.pushed_at).toDateString()}</h4>
</div>
<p class="commits" id="commit-${repo.name}">Number of commits:</p>
`;
});
fetchPull(technigoRepo);
drawChart(technigoRepo.length);
});
};
const fetchPull = (allRepo) => {
allRepo.forEach((repo) => {
fetch(`https://api.github.com/repos/Technigo/${repo.name}/pulls`)
.then((res) => res.json())
.then((data) => {
const myPullRequests = data.find(
(pull) => pull.user.login === repo.owner.login
);
console.log('My Pull requests', myPullRequests);
if (myPullRequests) {
fetchCommits(myPullRequests.commits_url, repo.name);
} else {
document.getElementById(`commit-${repo.name}`).innerHTML +=
'No pull request';
}
});
});
};
const fetchCommits = (myCommitsUrl, myRepoName) => {
fetch(myCommitsUrl)
.then((response) => response.json())
.then((data) => {
console.log('My commits', data);
document.getElementById(`commit-${myRepoName}`).innerHTML += data.length;
});
};
fetchRepo();