Skip to content

Commit 9004ea4

Browse files
committed
finished getting data from API
1 parent ded93a5 commit 9004ea4

3 files changed

Lines changed: 117 additions & 19 deletions

File tree

code/index.html

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8">
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<title>Project GitHub Tracker</title>
8-
<link rel="stylesheet" href="./style.css" />
9-
</head>
10-
<body>
11-
<h1>GitHub Tracker</h1>
12-
<h2>Projects:</h2>
13-
<main id="projects"></main>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Project GitHub Tracker</title>
8+
<link rel="stylesheet" href="./style.css" />
9+
</head>
10+
<body>
11+
<h1>GitHub Tracker</h1>
12+
<h2>Projects:</h2>
13+
<main id="projects"></main>
14+
<div class="profile-container" id="profileContainer">
15+
<img id="profileImage" class="profile-image" alt="profile-image" />
16+
<p id="userName"></p>
17+
</div>
1418

15-
<!-- This will be used to draw the chart 👇 -->
16-
<canvas id="chart"></canvas>
19+
<!-- This will be used to draw the chart 👇 -->
20+
<canvas id="chart"></canvas>
1721

18-
<script src="./script.js"></script>
19-
<script src="./chart.js"></script>
20-
</body>
21-
</html>
22+
<script src="./script.js"></script>
23+
<script src="./chart.js"></script>
24+
</body>
25+
</html>

code/script.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
const REPOS_URL = "https://api.github.com/users/themisk84/repos";
2+
const NEWS_SITE_COMMITS =
3+
"https://api.github.com/repos/Technigo/project-news-site/pulls/214/commits";
4+
const projects = document.getElementById("projects");
5+
const profileImage = document.getElementById("profileImage");
6+
const userName = document.getElementById("userName");
7+
8+
// const forkedRepos = (data) => {
9+
// const Reposforked = data.filter(
10+
// (repo) => repo.fork && repo.name.startsWith("project")
11+
// );
12+
// Reposforked.forEach(
13+
// (repo) =>
14+
// (projects.innerHTML += `<div class="repo" id="${repo.name}">
15+
// <h3><a href="${repo.html_url}" target="_blank">${repo.name}</a></h3>
16+
// </div>`)
17+
// );
18+
// };
19+
20+
const getRepos = () => {
21+
fetch(REPOS_URL)
22+
.then((response) => response.json())
23+
.then((data) => {
24+
console.log(data);
25+
26+
const forkedRepos = data.filter(
27+
(repo) => repo.fork && repo.name.startsWith("project")
28+
);
29+
forkedRepos.forEach(
30+
(repo) =>
31+
(projects.innerHTML += `<div class="repo" id="${repo.name}">
32+
<h3><a href="${repo.html_url}" target="_blank">${
33+
repo.name
34+
}</a></h3>
35+
<h4>${repo.default_branch}</h4>
36+
<ha>Last updated: ${new Date(
37+
repo.updated_at
38+
).toLocaleString()}</h4>
39+
</div>`)
40+
);
41+
const profileImg = data.forEach(
42+
(profile) => (profileImage.src = profile.owner.avatar_url)
43+
);
44+
const profileName = data.forEach(
45+
(nickname) => (userName.innerHTML = nickname.owner.login)
46+
);
47+
getPullRequest(forkedRepos);
48+
});
49+
};
50+
51+
const getPullRequest = (forkedRepos) => {
52+
forkedRepos.forEach((repo) => {
53+
fetch(
54+
`https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=100`
55+
)
56+
.then((response) => response.json())
57+
.then((data) => {
58+
// console.log(data);
59+
const myPulls = data.filter(
60+
(pulls) => pulls.user.login === repo.owner.login
61+
);
62+
console.log(myPulls);
63+
const commitsURL = myPulls[0].commits_url;
64+
// console.log(commitsURL);
65+
getCommits(commitsURL, repo);
66+
67+
// const myComments =
68+
});
69+
});
70+
};
71+
72+
const getCommits = (commitsURL, repo) => {
73+
fetch(commitsURL)
74+
.then((response) => response.json())
75+
.then((data) => {
76+
// console.log(data.length);
77+
document.getElementById(
78+
`${repo.name}`
79+
).innerHTML += `<h4> Number of commits: ${data.length}</h4>`;
80+
});
81+
};
82+
83+
getRepos();

code/style.css

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
body {
2-
background: #FFECE9;
3-
}
2+
background: white;
3+
}
4+
5+
.profile-container {
6+
width: 70px;
7+
height: 70px;
8+
}
9+
10+
.profile-image {
11+
width: 100%;
12+
height: 100%;
13+
border-radius: 50%;
14+
}

0 commit comments

Comments
 (0)