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
10 changes: 4 additions & 6 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.
This weeks assignment is to create a tracker for technigo repositories fetched from GitHub API.

## The problem
This week I have googled so much and stack overflow has really helped me alot with my problems. Lectures helped as well where I learnt about the github token and how to set commits to 0.

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?
If I had more time I would change the tooltip to instead have the name of the languages written out at the top of the projects to the right and I would add a search bar for projects.

## 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.
Netlify: https://week7-githubtracker-jenquach.netlify.app (
27 changes: 27 additions & 0 deletions code/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,30 @@
const ctx = document.getElementById('chart').getContext('2d')

//"Draw" the chart here 👇

const drawChart = () => {
const config = {
type: 'doughnut',
data: {
labels: [
'Finished projects',
'Projects left',
],
datasets: [{
label: 'My First Dataset',
data: [5, 20-5],
backgroundColor: [
'#3dabcc',
'rgb(160,168,175)'
],
hoverOffset: 4
}],
},
};

const myChart = new Chart(ctx, config)
}
// These labels appear in the legend and in the tooltips when hovering different arcs



29 changes: 24 additions & 5 deletions code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,34 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Project GitHub Tracker</title>
<link rel="stylesheet" href="./style.css" />
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" crossorigin="anonymous" />
</head>
<body>
<h1>GitHub Tracker</h1>
<h2>Projects:</h2>
<main id="projects"></main>
<header class="header">
<nav class="topnav">
<h1><i class="fab fa-github"></i> GitHub Tracker</h1>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice using fontawesome icon in the header

</nav>
</header>

<wrapper class="wrapper">
<section class="profile-container">
<div id="user-info" class="user-info"></div>
</section>
<main id="projects" class="projects">
<h2 class="repo-title">repositories</h2>
</main>
</wrapper>

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

<section class="chart-container">
<div class="chartdiv">
<canvas id="chart" class="chart"></canvas>
</div>
</section>

<script src="./token.js"></script>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice with the token. Used one as well, really nice!

<script src="./script.js"></script>
<script src="./chart.js"></script>
</body>
Expand Down
125 changes: 125 additions & 0 deletions code/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// //GLOBAL VARIABLES
// const options = {
// method: 'GET',
// headers: {
// Authorization: `token ****`,
// },
// };


const USER = 'jenquach'
const USER_URL = `https://api.github.com/users/${USER}`
const REPOS_URL = `https://api.github.com/users/${USER}/repos`

const headerContainer = document.getElementById('topnav')
const profileContainer = document.getElementById('user-info')
const projectsContainer = document.getElementById('projects')
const pullRequests = document.getElementById('pullrequests')

// function to fetch the user data from GitHub API
const userProfile = () => {
fetch(USER_URL)
.then(res => res.json())
.then(data => {
profileContainer.innerHTML = `
<div class="picture">
<img class="user-picture" src="${data.avatar_url}"
</div>
<div class="user-information">
<h2>${data.name}</h2>
<a href="https://github.com/jenquach"><i class="fab fa-github"></i> ${data.login}</a>
<p><i class="fas fa-map-marker-alt"></i> ${data.location}</p>
</div>
`
})
}
// function to fetch the technigo repositories
const getRepositories = () => {
fetch(REPOS_URL)
.then(res => res.json())
.then(data => {
// filtering the technigo repositories
const technigoRepositories = data.filter(
repo => repo.fork && repo.name.includes('project-')
)
technigoRepositories.forEach(repo => {
projectsContainer.innerHTML += `
<div class="project">
<div class="repo-info">
<a href="${repo.html_url}">${repo.name}</a>
<p class="push">Recent push ${new Date(repo.pushed_at).toLocaleString("sv-SE", {dateStyle: 'short'})}</p>
<div id="language-${repo.name}" class="progress"></div>
</div>
<div class="repo-details">
<p id="branch">${repo.default_branch}</p>
<p class="commit" id="commit-${repo.name}"><i class="fas fa-code-branch"></i> </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.

Nice with icon from fontawesome again

</div>
</div>
`
getLanguages(repo)
})
// Draw chart with technigoRepositories data
drawChart(technigoRepositories.length)
getPullRequests(technigoRepositories)
})
}

// function to fetch all pull requests
const getPullRequests = (allRepositories) => {
allRepositories.forEach(repo => {
const myRepoName = repo.name
const PULL_URL = `https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`
fetch(PULL_URL)
.then(res => res.json())
.then(data => { //data is the array of all pull requests
// Detect if we have pull request or not.
const myPullRequest = data.find(
pull => pull.user.login === repo.owner.login
)
// If yes - call fetchCommits function
if (myPullRequest) {
getCommits(myPullRequest.commits_url, repo.name);
// If no - commits 0 is shown.
} else {
document.getElementById(`commit-${repo.name}`).innerHTML =
'<i class="fas fa-code-branch"></i> 0';
}
})
})
}

// function to fetch number of commits
const getCommits = (myCommitsUrl, myRepoName) => {
fetch(myCommitsUrl, )
.then(res => res.json())
.then(data => {
document.getElementById(`commit-${myRepoName}`).innerHTML += data.length
})
}

// function to fetch all the languages used in the repository
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This you solved really nice. The only thing I might have wished was that it could be printed out under each coloured bar what language is what color. Now you need to hover to see.

const getLanguages = (repo) => {
const languages_URL = `https://api.github.com/repos/${USER}/${repo.name}/languages`
fetch(languages_URL, )
.then(res => res.json())
.then(data => {
const html = data.HTML || 0;
const css = data.CSS || 0;
const js = data.JavaScript || 0;
const sum = html + css + js;
// calculates the percentage used of each language
const htmlPercentage = ((html / sum) * 100).toFixed(1);
const cssPercentage = ((css / sum) * 100).toFixed(1);
const jsPercentage = ((js / sum) * 100).toFixed(1);

document.getElementById(`language-${repo.name}`).innerHTML = `
<div class="language-html" title="html" style="width:${htmlPercentage}%;"></div>
<div class="language-css" title="css" style="width:${cssPercentage}%;"></div>
<div class="language-js" title="javascript" style="width:${jsPercentage}%;"></div>
`
})
}


userProfile()
getRepositories()
Loading