Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# GitHub Tracker

Replace this readme with your own information about your project.

Start by briefly describing the assignment in a sentence or two. Keep it short and to the point.
Github tracker uses various parts of the Github REST api to reproduce some data from different github projects.

## The problem

Describe how you approached to problem, and what tools and techniques you used to solve it. How did you plan? What technologies did you use? If you had more time, what would be next?
This week I began by reading and reviewing the learning materials before starting the project. I found it quite hard to plan this week as I didn't know exacly what information would be found in each endpoint and so what I would want to display. So I found that both the HTML and CSS were hard to write or plan beforehand. If I were to do this project again I would look through the api first so that I could plan how my HTML and CSS would look, then go back to the javascript after this.

## View it live

Every project should be deployed somewhere. Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about.
https://sarah-mottram-github-tracker.netlify.app/
Binary file added code/Images/GitHub-headpic.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/Images/icons8-code-24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/Images/icons8-css-filetype-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/Images/icons8-github-24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/Images/icons8-html-50.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/Images/icons8-javascript-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 31 additions & 1 deletion code/chart.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
//DOM-selector for the canvas 👇
const ctx = document.getElementById('chart').getContext('2d')
const ctx = document.getElementById('chart').getContext('2d');

//"Draw" the chart here 👇
const drawChart = (repos) => {
const labels = ["Projects completed", "Projects to go"];
const data = [repos.length, 19-repos.length];

new Chart(ctx, {
type: "doughnut",
data: {
labels,
datasets: [
{
data,
backgroundColor: ['#0b293f', '#459ec6'],
},
],
},
options: {
responsive: true,
plugins: {
legend: {
position: "top",
},
title: {
display: true,
text: "Technigo Bootcamp Projects",
},
},
}
});
};

64 changes: 47 additions & 17 deletions code/index.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Project GitHub Tracker</title>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<h1>GitHub Tracker</h1>
<h2>Projects:</h2>
<main id="projects"></main>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Project GitHub Tracker</title>
<link rel="stylesheet" href="./style.css" />
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet"
/>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<header>
<div class="hero-image">
<div class="hero-text">
<h1>GitHub Tracker</h1>
</div>
</div>
<div class="user-info" id="user-info">
</div>
</header>
<hr />
<h2>Projects</h2>
<div>
<p class="dark">Filter Repos by main language:</p>
<button id="HTML-button">HTML</button>
<button id="CSS-button">CSS</button>
<button id="Javascript-button">Javascript</button>
</div>

<!-- This will be used to draw the chart 👇 -->
<canvas id="chart"></canvas>
<main id="projects"></main>

<!-- This will be used to draw the chart 👇 -->
<section class="chart-container">
<canvas class="chart" id="chart"></canvas>
</section>

<footer>
<div class = "icon-link">
<a target="_blank" href="https://icons8.com/icon/87310/code">Code</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
</div>
</footer>

<script src="./script.js"></script>
<script src="./chart.js"></script>
</body>
</html>

<script src="./script.js"></script>
<script src="./chart.js"></script>
</body>
</html>
79 changes: 79 additions & 0 deletions code/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// DOM selectors

// HTML sections to inject into
const main = document.getElementById("projects");
const userInfo = document.getElementById("user-info");

const username = "Smelbows";
const USERS_REPOS_API = `https://api.github.com/users/${username}/repos`;

const fetchUserRepos = (userUrl) => {
fetch(userUrl)
.then((res) => res.json())
.then(filterForTechnigoRepos)
.then((repos) => {
userInfo.innerHTML = createHTMLForUser(repos[0]);
repos.forEach((repo) => {
main.innerHTML += createHTMLForRepo(repo);
fetchPullRequests(repo);
});
drawChart(repos);
});
};

const filterForTechnigoRepos = (data) => {
return data.filter((repo) => repo.name.startsWith("project"));
};

const createHTMLForUser = (repo) => {
return `<img class="avatar" src=${repo.owner.avatar_url} alt="github avatar"/><p class="name">${repo.owner.login}</p>`;
};

const createHTMLForRepo = (repo) => {
return `<a target="blank" href="${repo.html_url}" class="repo-container ${
repo.language

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I ask what does this <repo. language> do in the code? Maybe I am missing something that is actually quite obvious, but was curious what this code means.

}" id="${repo.name}"><p class="repo-name">${
repo.name
}</p><p>Default branch: ${repo.default_branch}</p><p>Last pushed: ${new Date(
repo.pushed_at
).toDateString()}</p><div id="commit-${repo.name}"></div></a>`;
};

const fetchPullRequests = (repo) => {
fetch(`https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`)
.then((res) => res.json())
.then((data) => {
myPullRequest = findMyPullRequest(data, repo.name);
// Only continues to fetch commit data if there is a pull request there
if (myPullRequest === undefined) {
document.getElementById(`commit-${repo.name}`).innerHTML +=
"<p>No pull request made yet</p>";
} else {
fetchCommits(myPullRequest.commits_url, repo.name);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your 'if/ else' code usage throughout the whole code is so clear and easy to read, thanks! I get really clumsy when I write if or else statement, so I find these so satisfying and skillful.

});
};

const findMyPullRequest = (pullsData, repoName) => {
// this project was pulled from Anna's fork
if (repoName === "project-weather-app") {
return pullsData.find((pull) => pull.user.login === "anndimi");
} else {
return pullsData.find((pull) => pull.user.login === username);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever way to distinguish the repos that were forked from certain id's repository!

};

const fetchCommits = (url, name) => {
fetch(url)
.then((res) => res.json())
.then((data) => {
document.getElementById(
`commit-${name}`
).innerHTML += `<p>Number of commits: ${
data.length
}</p><p>Last commit message: ${data[data.length - 1].commit.message}</p>`;
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why is it index number -1?

};

fetchUserRepos(USERS_REPOS_API);

Loading