Skip to content

Commit 7f2b0cb

Browse files
committed
fetched github Api, filtered projects from technigo and added a doughnut
1 parent ded93a5 commit 7f2b0cb

4 files changed

Lines changed: 99 additions & 18 deletions

File tree

TODO

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
1) fetch the repos and console log them
2+
2) get them in the browser
3+
3) filter out the technigo repos
4+
4) test chart library
5+
//Remember to pass along your filtered repos as an argument when
6+
//you are calling this function
7+
8+
const getPullRequests = (repos) => {
9+
//Get all the PRs for each project.
10+
repos.forEach((repo) => {
11+
fetch('https://api.github.com/users/MT-dotse/repos' + repo.name + PULLS)
12+
.then((res) => res.json())
13+
.then((data) => {
14+
//TODO
15+
let keep;
16+
if (pull.user.login === repo.owner.login) {
17+
keep = pull.user.login;
18+
commitsURL(keep);
19+
}
20+
console.log('Hello from script js');
21+
22+
//1. Find only the PR that you made by comparing pull.user.login
23+
// with either USER or repo.owner.login
24+
//2. Now you're able to get the commits for each repo by using
25+
// the commits_url as an argument to call another function
26+
//3. You can also get the comments for each PR by calling
27+
// another function with the review_comments_url as argument
28+
});
29+
});
30+
};

code/chart.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
//DOM-selector for the canvas 👇
2-
const ctx = document.getElementById('chart').getContext('2d')
2+
const ctx = document.getElementById('chart').getContext('2d');
33

44
//"Draw" the chart here 👇
5+
6+
const drawChart = (amount) => {
7+
const config = {
8+
type: 'doughnut',
9+
data: {
10+
labels: ['Finished Projects', 'Projects left'],
11+
datasets: [
12+
{
13+
label: 'My First Dataset',
14+
data: [amount, 20 - amount], // 5 finished projects and 15 projects remaining
15+
backgroundColor: ['rgb(255, 99, 132)', 'rgb(54, 162, 235)'],
16+
hoverOffset: 4,
17+
},
18+
],
19+
},
20+
};
21+
const myProjects = new Chart(ctx, config); //Taking two arguments: 1) where to put 'ctx' and 2) what to put 'config'
22+
};

code/index.html

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
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+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
10+
</head>
11+
<body>
12+
<h1>GitHub Tracker</h1>
13+
<h2>Projects:</h2>
14+
<main id="projects"></main>
1415

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

18-
<script src="./script.js"></script>
19-
<script src="./chart.js"></script>
20-
</body>
21-
</html>
19+
<script src="./script.js"></script>
20+
<!-- Links to the js file -->
21+
<script src="./chart.js"></script>
22+
<!-- Links to the chart -->
23+
</body>
24+
</html>

code/script.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// The DOM selectors
2+
const projectContainer = document.getElementById('projects');
3+
4+
// URLs stored in variables
5+
const USER = 'MT-dotse'; //my github name stored in the variable USER
6+
const REPOS_URL = `https://api.github.com/users/${USER}/repos`;
7+
8+
//Wapping the fetch REPOS_URL in a function
9+
const getRepos = () => {
10+
fetch(REPOS_URL)
11+
.then((response) => response.json()) //a placeholder waiting for the information
12+
.then((data) => {
13+
console.log(data);
14+
//data.forEach((repo) => console.log(repo.name));
15+
16+
//Filtering out the projects that are both forked and starting with the name "project - "
17+
const forkedRepos = data.filter(
18+
(repo) => repo.fork && repo.name.startsWith('project-')
19+
);
20+
21+
// printing out the filtered projects stored in forkedRepos
22+
// Adding += to show all the projects and not only just one
23+
forkedRepos.forEach(
24+
(repo) => (projectContainer.innerHTML += `<h3> ${repo.name} </h3>`)
25+
);
26+
27+
drawChart(forkedRepos.length);
28+
});
29+
};
30+
getRepos();

0 commit comments

Comments
 (0)