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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
code/secret.js
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# 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.
The assignment was to create a GitHub tracker of all my Technigo-repos using GitHub API.

## 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?
Problem description and code comments will be added soon...

## 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://lisen-github-tracker.netlify.app/
30 changes: 30 additions & 0 deletions code/chart.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
//Font-family for the chart
Chart.defaults.font.family = 'Source Code Pro, monospace';

Choose a reason for hiding this comment

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

Love that you looked into and added the charts font - it makes the whole site very cohesive.


//DOM-selector for the canvas 👇
const ctx = document.getElementById('chart').getContext('2d')

//"Draw" the chart here 👇
const activateChart = (projects) => {
const labels = [
'Projects done',
'Projects to do'
]

const data = {
labels: labels,
datasets: [{

data: [projects, 19-projects],
label: 'Projects',
backgroundColor: ['rgb(244, 132, 95)', 'rgb(220, 220, 220)']
}]
}

const config = {
type: 'doughnut',
data: data,
options: {}
}
Comment on lines +24 to +28

Choose a reason for hiding this comment

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

Doughnuts are some of my favourite charts! I used to work a lot with big data in my old job, and make dashboards for our clients, and I just think doughnuts are superior. Hehe.


const myChart = new Chart(document.getElementById('chart'),config);
}



18 changes: 13 additions & 5 deletions code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Project GitHub Tracker</title>
<link rel="stylesheet" href="./style.css" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<h1>GitHub Tracker</h1>
<h2>Projects:</h2>
<main id="projects"></main>
<!-- <h1>GitHub Tracker</h1> -->
<main id="projects" class="projects">
<div id="userSection" class="user-container"></div>
<div id="repoSection" class="repo-container"></div>
</main>

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

<div class="chart-container">
<canvas id="chart"></canvas>
</div>
<script src="./secret.js"></script>
<script src="./script.js"></script>
<script src="./chart.js"></script>
Comment on lines 8 to 27

Choose a reason for hiding this comment

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

Really nice HTML file! Super clean and impressed that everything was added via javascript.

The only tiny suggestion I have is adding a Favicon to your project - it helps the website look a little less "anonymous" when looking at it next to other tabs.

I like to use https://favicon.io/ to either find or create my own Favicons :) It's super easy to implement in the header,, they provide you with the code. If you do choose to use favicons in the future, remember to drop the files and images in the same folder as your index.html file.

</body>
Expand Down
79 changes: 79 additions & 0 deletions code/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const userSection = document.getElementById ('userSection')
const repoSection = document.getElementById ('repoSection')

const username = 'mistscale'
const API_USER_URL = `https://api.github.com/users/${username}`
const API_REPOS_URL = `https://api.github.com/users/${username}/repos`

const options = {
method: 'GET',
headers: {
Authorization: 'API_TOKEN'
}
}
Comment on lines +1 to +13

Choose a reason for hiding this comment

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

Super clear, beautiful declarations. A pleasure to see!


// Display profile picture and username from user api
const getUser = () => {
fetch(API_USER_URL, options)
.then(res => res.json())
.then(data => {
userSection.innerHTML = `
<img src='${data.avatar_url}' class='profile-img'/>
<h1>${data.login}</h1>`
})
getRepos()
}
Comment on lines +15 to +25

Choose a reason for hiding this comment

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

Again, great commenting and also elegant, great use of calling functions.


const getRepos = () => {
fetch(API_REPOS_URL, options)
.then(res => res.json())
.then(data => {
const forkedRepos = data.filter((repo) => repo.fork && repo.name.startsWith('project'))
forkedRepos.forEach((repo) => {
repoSection.innerHTML += `
<div class='repo-name' id='${repo.name}'>
<h2>${repo.name}</h2>
<p>Repo link: <a href='${repo.html_url}'>here</a></p>
<p>Default branch: ${repo.default_branch}</p>
<p>Recent update: ${new Date(repo.pushed_at).toLocaleDateString('sv-SE')}</p>
</div>`
})
getPullRequests(forkedRepos)
activateChart(forkedRepos.length)
})
Comment on lines +27 to +43

Choose a reason for hiding this comment

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

Love how you keep each function so elegant and use it to call the next functions. Your javascript is really gorgeous to read. You get precisely what you need and pass it on to the next functions. In my opinion, your javascript is a great example of perfect use of occam's razor (or the law of parsimony, the problem-solving principle that entities should not be multiplied beyond necessity).


const getPullRequests = (forkedRepos) => {
forkedRepos.forEach(repo => {
fetch(`https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=100`, options)
.then(res => res.json())
.then(data => {

const filterPullRequests = data.find((pull) => pull.user.login === repo.owner.login)

if (filterPullRequests) {
document.getElementById(`${repo.name}`).innerHTML += `
<p>Pull request: <a href='${filterPullRequests.html_url}'>here</a></p>`
} else {
document.getElementById(`${repo.name}`).innerHTML += `
<p>Pull request by team member</p>`
}
if (filterPullRequests) {
getCommits(filterPullRequests.commits_url, repo.name)
} else {
document.getElementById(`${repo.name}`).innerHTML += `
<p>Commits by team member</p>`
}
})
})
}
Comment on lines +45 to +68

Choose a reason for hiding this comment

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

Perfect - honestly there is not a single thing in your javascript I can critique. It does exactly what it is supposed to and does so beautifully. Really cool way of chaining your if / else statements twice in a row, I didn't know that was possible. I will definitely be remembering that and using it in the future myself.


const getCommits = (commitsURL, repoName) => {
fetch(commitsURL)
.then((res) => res.json())
.then (data => {
document.getElementById(repoName).innerHTML += `
<p>Commits: ${data.length}</p>`
})
}}
Comment on lines +70 to +77

Choose a reason for hiding this comment

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

Only tiny thing here is I noticed you forgot to add 'options' after your commitsURL in the fetch. Wow!! I can't believe I spotted something. It's miniscule. You should be really proud.


getUser()
63 changes: 61 additions & 2 deletions code/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
text-decoration: none;
}
Comment on lines +1 to +6

Choose a reason for hiding this comment

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

Love this - do this on all my projects as well. Makes it really easy to set all the margins and paddings from scratch. Tiny suggestion is to add these two lines if you're using border-box, it ensures that your settings work across multiple browsers:

-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;


body {
background: #FFECE9;
}
background: #EEE;
font-family: 'Source Code Pro', monospace;
}

.profile-img {
border-radius: 50%;
width: 10rem;
margin: 1rem;
}

.user-container {
display: flex;
flex-direction: column;
align-items: center;
}
Comment on lines +19 to +23

Choose a reason for hiding this comment

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

Nice use of flex here - your user-container looks really good and balanced on your site.


.repo-container {
display: flex;
justify-content: center;
flex-direction: column;
align-items: stretch;

Choose a reason for hiding this comment

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

I'm not sure what the align-items: stretch; line does - I tried deleting it from your code, and it didn't produce any visible changes that I noticed. So I think this line could possibly be deleted.

gap: 2rem;
padding: 2rem;
}

.repo-name {
background-color: #FFF;
padding: 1rem;
width: 20rem;
}
Comment on lines +34 to +38

Choose a reason for hiding this comment

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

I noticed on your mobile version that the .repo-name containers weren't centered horizontally. This can be fixed by adding the property align-self: center; to the .repo-name class. When you then expand to a larger viewport, you can change that (because if you don't, it "squishes" some of the containers so they aren't the same size) to align-self: auto; by adding a bit of code to line 55. (I'll add it below).


.repo-name a {
color: #F4845F;

Choose a reason for hiding this comment

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

Really nice color choice for the links - I think it works really well, pairing this slightly burnt orange with a light gray. Simple yet beautiful palette in my opinion!

}

.chart-container {
margin: auto;
width: 20rem;
padding: 1rem;
}

@media (min-width: 668px) {
.repo-container {
flex-direction: row;
flex-wrap: wrap;
}

Choose a reason for hiding this comment

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

If you add this to your @media (min-width: 668px), it'll fix the squishing of the containers that happens from the align-self: center on mobile.

.repo-name { align-self:auto; }

}

@media (min-width: 1025px) {
.repo-container {
flex-direction: row;
flex-wrap: wrap;
}
}