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
80 lines (70 loc) · 2.83 KB
/
Copy pathscript.js
File metadata and controls
80 lines (70 loc) · 2.83 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
const USER = 'lenisili'
const REPOS_URL = `https://api.github.com/users/${USER}/repos`;
const USER_URL = `https://api.github.com/users/${USER}`
const projectsContainer = document.getElementById('projects');
const profileContainer = document.getElementById('profile-container')
const userProfile = () => {
fetch (USER_URL)
.then (response => response.json())
.then (data => {
profileContainer.innerHTML+= `
<div class="profile-wrapper" id="profile-wrapper">
<div class="profile-photo" id=" profile-image">
<img src="https://avatars.githubusercontent.com/u/84474447?v=4" alt="Profile Picture of User" >
</div>
<div class="profile-username" id ="profile-username">
<div class="user-name">Username: <span class="space">${data.login}</span></div>
<div class="real-name">Name: <span class="space">${data.name}</span></div>
<div class="location">Living and working in: <span class="space">${data.location}, CH</span></div>
</div>
</div>
<div class="profile-text" id="profile-text">
<p> ${data.bio}</p>
</div>`
})
}
userProfile()
const fetchRepositories = () => {
fetch(REPOS_URL)
.then((res) => res.json())
.then((data) => {
const technigoRepositories =data.filter(repo =>
repo.name.includes('project-') && repo.fork === true
);
technigoRepositories.forEach(repo => {
projectsContainer.innerHTML += `
<div id ${repo.name} class="repo-card">
<h2>${repo.name}</h2>
<p>Branch: ${repo.default_branch}</p>
<p> Main Language: ${repo.language}</p>
<p>Last push: ${new Date(repo.pushed_at).toDateString()}</p>
<p id="commit-${repo.name}"> Number of commits: </p>
<p> <a href="${repo.html_url}"> See repo</a></p>
</div>
`;
});
fetchPullRequests(technigoRepositories);
drawChart(technigoRepositories.length);
});
};
const fetchPullRequests = (allRepositories) =>{
allRepositories.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 ((data) => {
const myPullRequest = data.find((pull) =>
pull.user.login === repo.owner.login
);
fetchCommits(myPullRequest.commits_url, repo.name);
});
});
};
const fetchCommits = (myCommitsUrl, myRepoName) => {
fetch(myCommitsUrl)
.then((response) => response.json())
.then (data => {
document.getElementById(`commit-${myRepoName}`).innerHTML += data.length
});
}
fetchRepositories();