Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# GitHub Tracker
Requirements:

Replace this readme with your own information about your project.
- A list of all repos that are forked from Technigo
- Your username and profile picture
- Most recent update (push) for each repo
- Name of your default branch for each repo
- URL to the actual GitHub repo
- Number of commits for each repo
- It should be responsive (mobile first)
- A visualisation, for example through a pie chart, of how many projects you've done so far, compared to how many you will do (in total it will be 19 weekly projects 🥳) using [Chart.js](https://www.chartjs.org/).

Start by briefly describing the assignment in a sentence or two. Keep it short and to the point.

## 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 project wasn't easy to get my head around. It took me a while to get all fetches to show. I also struggled a bit with the chart.

## 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://marianneardin-githubtracker.netlify.app/
1 change: 1 addition & 0 deletions code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
token.js
25 changes: 22 additions & 3 deletions code/chart.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
//DOM-selector for the canvas 👇
const ctx = document.getElementById('chart').getContext('2d')
//DOM-selector for the canvas

//"Draw" the chart here 👇
//Chart showing completed and remaining projects

const drawChart = (numberOfProjects) => {
const ctx = document.getElementById('chart').getContext('2d')
const config = {
type: "pie",
data: {
labels: ["Projects completed", "Projects remaining"],
datasets:[{
label: "Technigo Projects",
data: [numberOfProjects, 19 - numberOfProjects],
backgroundColor:["rgb(255,255,255)", "rgb(102,153,153)"],
hoverOffset: 4,
}]
}
}

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

}
36 changes: 32 additions & 4 deletions code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,43 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Project GitHub Tracker</title>
<link rel="stylesheet" href="./style.css" />
<!--Link to font-->
<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=Bebas+Neue&display=swap" rel="stylesheet">

</head>
<body>
<h1>GitHub Tracker</h1>
<h2>Projects:</h2>
<main id="projects"></main>
<header>
<h1>GitHub Tracker</h1>
<h3 id="username"></h3>
Copy link
Copy Markdown

@tiiliu tiiliu Mar 6, 2022

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 this title or id is referring to? I didn't notice that it would print anything to the page and I didn't see that it was used in the script file either. Maybe it can be removed if unnecessary? :)

</header>
<section class="profile" id="profile">
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I noticed that this section has the same class and id names as you have in your script.js file on row 26, where you are printing information about your profile, inside the userContainer element. Perhaps it is referring to those? If that is the case, it is enough that you have those elements in the script file. Using the DOM selector userContainer and then innerHTML you are printing the data inside the userContainer section (row 26 here in html file) and the content of the innerHTML doesn't need to be added here in html. :)

</section>

<main id="projects"></main>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm also not sure which element this id is referring to? I wasn't able to find it in the script file. Maybe also removable if not needed? The main tag you could for example use to expand around the main content of your page, semantically it is normally used for specifying the dominant content of a document.

<section id="userContainer">
</section>
<section id="projectContainer">
</section>
<div>
<div class="flex-box"></div>
<div class="flex-item"></div>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think these are also perhaps forgotten not used elements? I wasn't able to find them in the css file and they seem to be empty :)

</div>

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

<!-- This is a little footer -->
<footer>
Page by Marianne Ardin week 7 Technigo bootcamp 2022 marianne@ardin.se <a href="https://www.linkedin.com/in/marianneardin/">Marianne Ardin on linkedin</a>
</footer>

<!-- link to chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="./token.js"></script>
<script src="./script.js"></script>
<script src="./chart.js"></script>
</body>
Expand Down
92 changes: 92 additions & 0 deletions code/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//DOM selectors//
const userContainer = document.getElementById('userContainer')

//APIs to fetch from
const username = 'MarianneArdin'
const API_URL = `https://api.github.com/users/${username}`
const REPOS_URL = `https://api.github.com/users/${username}/repos`
//const API_TOKEN = TOKEN || process.env.API_TOKEN
//const API_MY_PROFILE = 'https://api.github.com/users/MarianneArdin'


//option for authorization
const options = {
method: 'GET',
headers: {
Authorization: `token ${API_TOKEN}`
}
}
//FETCHES PROFILE FROM GITHUB//
const fetchProfile = () => {
fetch(API_URL, options)
.then((response) => response.json())
.then((data) => {
console.log(data)
userContainer.innerHTML += `
<div id="profile" class="profile">
<div class="profile-image">
<a href="${API_URL}">
<img src="${data.avatar_url}" alt="Avatar of ${data.login}">
</a>
</div>
<a href="https://github.com/MarianneArdin"><h1 class="username">${data.login}<h1></a>
<h2>My projects</h2>
</div>
<div>
<p>Public repositories: ${data.public_repos}</p>
</div>
`
Comment on lines +26 to +38
Copy link
Copy Markdown

@tiiliu tiiliu Mar 6, 2022

Choose a reason for hiding this comment

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

Here I noticed that the last div containing the p tag public repositories is outside of the main div (starting from row 26). That means that the styling done with the class name profile isn't included into that div. Perhaps that was meant to be, just wanted to brought this up just in case :)

})
}
fetchProfile()

//GET REPOS FROM GITHUB//
const getRepos = () => {
fetch(REPOS_URL, options)
.then((res) => res.json())
.then((reposData) => {
console.log(reposData)
const forkedRepos = reposData.filter((repo) => repo.fork && repo.name.startsWith("project-"))
forkedRepos.forEach(repo => {
projectContainer.innerHTML +=
`
<a class="project-link" href="${repo.html_url}" target="_blank">
<div class="forkedrepo-div">
<h2 class="project-name"> ${repo.name}</h2>
<p class="project-info"> Default branch: ${repo.default_branch}</p>
<p class="project-info"> Recent push: ${new Date(repo.pushed_at).toDateString()}</p>
<p class="project-info" id="commits-${repo.name}"> Amount of commits: </p>
</div> `
})
getPullRequests(forkedRepos)

drawChart(forkedRepos.length)
})
}
getRepos()

//GETS REPOS FROM GITHUB//
const getPullRequests = (repos) => {
repos.forEach(repo => {
fetch(`https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`, options)
.then(res => res.json())
.then((pullData) => {
let myPullRequest = pullData.find((pull) => pull.user.login === repo.owner.login)
if (myPullRequest) {
getCommits(myPullRequest.commits_url, repo.name)
} else {
document.getElementById(`commits-${repo.name}`).innerHTML += `No pulls yet.`
}
})
})
}

//GET NUMBER OF COMMITS
const getCommits = (commitsUrl, repo) => {
fetch(commitsUrl, options)
.then(res => res.json())
.then((data) => {
document.getElementById(`commits-${repo}`).innerHTML += `${data.length}`
console.log(data.length)
})
}
78 changes: 76 additions & 2 deletions code/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,77 @@
body {
background: #FFECE9;
}
background: grey;
font-family: 'Bebas Neue', cursive;
margin: 1rem;
}

header {
background-color: lightgrey;
border-radius: 180%;
color: black;
text-align: center;

}

.flex {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I wasn't able to find an element with this class name, is it used somewhere?

display: flex;

}

h1 {
font-size: 40px;
text-align: center;
}

h2 {
font-size: 40px;
text-align: center;
}

h3 {
font-size: 20px;
text-align: center;
}

/*Image*/
img {
width: 200px;
border-radius: 50%;
padding: 2rem;
}

a {
color: black;
}

.profile
{
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
margin-left: auto;
margin-right: auto;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think these two rows you could combine using: margin: x auto. X (insert right number here) referring to top and bottom margin and auto referring to right and left margin :)

width: 50%;
}
.forkedrepo-div
{
border: black solid;
padding: 1rem;
margin: 2rem;
}
/* THE CHART SECTION */

#chart-wrapper {
width: 90%;
margin: 20px auto 40px;
}
Comment on lines +64 to +59
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're using the id chartwrapper here, but I couldn't find this id name from the code? You have a class name chart-container created for the element containing the chart (row 34 in html). It is good standard to use class names for styling, so maybe that class name could be used here instead? :)


#chart {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe here also would be better to use the class name instead of the id for the chart?

padding: 5%;
}

/* This is styling for the footer*/
footer {
background-color: darkgrey;
text-align: center;
}