-
Notifications
You must be signed in to change notification settings - Fork 131
Week 7 - GitHub Tracker by Jenny #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
24252e0
9ee2600
16ca877
54f817f
ff3b859
8e836e4
53cabd2
f71b9f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 ( |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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> | ||
| </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> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
|
||
| 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> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
There was a problem hiding this comment.
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