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
78 lines (73 loc) · 2.29 KB
/
script.js
File metadata and controls
78 lines (73 loc) · 2.29 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
// DOM selectors:
const repoGrid = document.getElementById("repoGrid");
const profile = document.getElementById("profile");
// Global variables:
const userName = "JustineZwiazek";
const API_USER = `https://api.github.com/users/${userName}`;
const API_REPOS = `https://api.github.com/users/${userName}/repos`;
// Profile information function:
const getProfile = () => {
fetch(API_USER)
.then((res) => res.json())
.then((data) => {
profile.innerHTML = `
<img src="${data.avatar_url}" class="user-img">
<div class="profile-info">
<h2>${data.name}</h2>
<p>Front End Development student 👩🏻💻</p>
<p>Stockholm, Sweden 🇸🇪</p></div>
`;
});
getRepos();
};
// Fetch repositories function:
const getRepos = () => {
fetch(API_REPOS)
.then((res) => res.json())
.then((data) => {
// Filtering out not forked repositories:
const forkedRepos = data.filter(
(repo) => repo.name.startsWith("project") && repo.fork === true
);
forkedRepos.forEach((repo) => {
repoGrid.innerHTML += `
<div class='repos' id="${repo.name}">
<h3>${repo.name}</h3>
<p>Default branch: ${repo.default_branch}</p>
<p>Recent Push: ${new Date(repo.pushed_at).toDateString()}</p>
<a href="${repo.html_url}">Link to repo</a>
`;
});
getPullRequests(forkedRepos);
drawChart(forkedRepos.length);
});
};
// Fetch pull requests function:
const getPullRequests = (forkedRepos) => {
forkedRepos.forEach((repo) => {
fetch(
`https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=100`
)
.then((res) => res.json())
.then((data) => {
const myPullsOnly = data.find(
(pull) => pull.user.login === repo.owner.login
);
const myCommitsURL = myPullsOnly.commits_url;
const repoName = repo.name;
getCommits(myCommitsURL, repoName);
});
});
};
// Fetch number of commits function:
const getCommits = (myCommitsURL, repoName) => {
fetch(myCommitsURL)
.then((res) => res.json())
.then((data) => {
// Count the number of commits:
document.getElementById(repoName).innerHTML += `
<p># of Commits: ${data.length}</p>`;
});
};
// Initiate the first function
getProfile();