-
Notifications
You must be signed in to change notification settings - Fork 130
Finished blue requirements #27
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
Open
isomoth
wants to merge
6
commits into
Technigo:main
Choose a base branch
from
isomoth:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7849faf
fetched name, picture, forked repos, pull requests
isomoth 60eed29
completed all fetches for the blue requirements
isomoth 664074c
Responsive grid and chart. Sorted projects after date.
isomoth 9b2c9e6
finished blue requirements
isomoth 08e6662
fixed chart height
isomoth 529a58b
fixed forkedRepos function and fixed indentation
isomoth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,21 @@ | ||
| # GitHub Tracker | ||
|
|
||
| Replace this readme with your own information about your project. | ||
| A site made to practice fetching from the GitHub API. | ||
|
|
||
| Start by briefly describing the assignment in a sentence or two. Keep it short and to the point. | ||
| ## Features | ||
|
|
||
| ## The problem | ||
| - Dynamic styling through DOM manipulation in JavaScript. | ||
| - Mobile-first styling. | ||
| - Data retrieved from GitHub's API: Basic user info, projects forked from Technigo (filtered by date of creation), number of commits, and whether there has been a pull request yet. | ||
| - Use of methods like filter, find, and sort to organize the data. | ||
| - A chart visualization of completed projects vs. projects left to do, using chart.js. | ||
|
|
||
| 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? | ||
| ## Challenges and Lessons learned | ||
|
|
||
| ## View it live | ||
| - The biggest challenge in terms of fetching was the getCommits function, since the API didn't have a direct path to fetch each commit. The solution was to first fetch all repos, then filter the forked ones. Then get their pull requests, and finally invoke the getCommits function within a conditional (if the project had any pull requests). | ||
| - Dynamic CSS with JavaScript was also a challenge, since the styling mindset was purely based on the HTML document up to this point. I learned to check the dev tools more often, to make sure the dynamic structure of the document was still coherent. | ||
| - The responsiveness of the chart was tricky because of the quirky nature of chart.js. I used a combination of the library's documentation and Stack Overflow answers to get ahead. In the end, I decided to go for a bar graphic instead of a donut. Its rectangular forms matched my layout better. | ||
|
|
||
| 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. | ||
| ## Deployed version | ||
|
|
||
| github-tracker-gonzalez.netlify.app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,39 @@ | ||
| //DOM-selector for the canvas 👇 | ||
| const ctx = document.getElementById('chart').getContext('2d') | ||
| // DOM-selector for the canvas | ||
| const ctx = document.getElementById('myChart').getContext('2d'); | ||
|
|
||
| //"Draw" the chart here 👇 | ||
| // Generate the chart based on the data fetched on script.js | ||
| const drawChart = (amount) => { | ||
| const config = { | ||
| type: 'bar', | ||
| data: { | ||
| labels: ['Finished Projects', 'Projects Left'], | ||
| datasets: [ | ||
| { | ||
| label: 'Completed Projects', | ||
| data: [amount, 19 - amount], | ||
| backgroundColor: ['#D365C8', '#3aafc9'], | ||
| hoverOffset: 4, | ||
| }, | ||
| ], | ||
| }, | ||
| options: { | ||
| // The first two options make the chart responsive | ||
| responsive: true, | ||
| maintainAspectRatio: false, | ||
| plugins: { | ||
| legend: { | ||
| display: false, | ||
| }, | ||
| tooltips: { | ||
| callbacks: { | ||
| label: function (tooltipItem) { | ||
| return tooltipItem.yLabel; | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const myChart = new Chart(ctx, config); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,40 @@ | ||
| <!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> | ||
|
|
||
| <!-- This will be used to draw the chart 👇 --> | ||
| <canvas id="chart"></canvas> | ||
|
|
||
| <script src="./script.js"></script> | ||
| <script src="./chart.js"></script> | ||
| </body> | ||
| </html> | ||
| <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> | ||
| <meta | ||
| name="description" | ||
| content="GitHub Technigo forked projects tracker" | ||
| /> | ||
| <meta name="author" content="Isabel González" /> | ||
| <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=Martel+Sans:wght@200;300;400;600;700;800;900&display=swap" | ||
| rel="stylesheet" | ||
| /> | ||
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | ||
| </head> | ||
| <body> | ||
| <div class="profile-container"> | ||
| <header> | ||
| <div id="user-info"></div> | ||
| </header> | ||
| <section id="projects"> | ||
| <h1 class="divider-title">Technigo Projects</h1> | ||
| <div id="project-grid"></div> | ||
| </section> | ||
| </div> | ||
| <!-- Draw a donut chart containing completed projects versus projects left --> | ||
| <section class="chart-container"> | ||
| <canvas id="myChart"></canvas> | ||
| </section> | ||
| <script src="./script.js"></script> | ||
| <!--Link the chart library--> | ||
| <script src="./chart.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // The strict mode in JavaScript prevents several bugs. For example, it won't let you use undeclared variables. | ||
| 'use strict'; | ||
|
|
||
| // Global variables | ||
| const USER = 'isomoth'; | ||
| const USER_URL = `https://api.github.com/users/${USER}`; | ||
| const REPOS_URL = `https://api.github.com/users/${USER}/repos`; | ||
| const userInfo = document.getElementById('user-info'); | ||
| const projectsContainer = document.getElementById('project-grid'); | ||
|
|
||
| // Fetch user info and inject it into a div | ||
| const getUserProfile = () => { | ||
| fetch(USER_URL) | ||
| .then((response) => response.json()) | ||
| .then((data) => { | ||
| userInfo.innerHTML += ` | ||
| <div class="user-info"> | ||
| <img class="user-image" src='${data.avatar_url}'/> | ||
| <div class="user-names"> | ||
| <h2 class="nickname">${data.name}</h2> | ||
| <h3><a href="https://github.com/isomoth">${data.login}</a></h3> | ||
| <p class="bio">${data.bio}</p> | ||
|
isomoth marked this conversation as resolved.
|
||
| <p class= "public">Public repos: ${data.public_repos}</p> | ||
| <p class= "twitter">Twitter: <a href="https://twitter.com/isomoth">@${data.twitter_username}</a></p> | ||
| </div> | ||
| </div> | ||
| `; | ||
| }); | ||
| }; | ||
|
|
||
| getUserProfile(); | ||
|
|
||
| // Fetch all of the user's projects where a pull request has been made | ||
| const getPullRequests = (allRepos) => { | ||
| allRepos.forEach((repo) => { | ||
| const PULL_URL = `https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`; | ||
| fetch(PULL_URL) | ||
| .then((response) => response.json()) | ||
| .then((data) => { | ||
| const userPullRequest = data.find( | ||
| (pull) => pull.user.login === repo.owner.login | ||
| ); | ||
| // Filter out pull requests from other users and fetch commits from them | ||
| if (userPullRequest) { | ||
| getCommits(userPullRequest.commits_url, repo.name); | ||
| } else { | ||
| // Catch exception when no pull request has been made | ||
| document.getElementById(`commit-${repo.name}`).innerHTML = | ||
| 'No pull requests so far.'; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| //Fetch all commits from filtered projects | ||
| const getCommits = (myCommitsUrl, myRepoName) => { | ||
| fetch(myCommitsUrl) // this will be 'commits_url' from line 45 | ||
| .then((res) => res.json()) | ||
| .then((data) => { | ||
| // Count amount of commits | ||
| document.getElementById(`commit-${myRepoName}`).innerHTML += data.length; | ||
| }); | ||
| }; | ||
|
|
||
| // Fetch all repositories that the user has forked from Technigo | ||
| const getRepositories = () => { | ||
|
isomoth marked this conversation as resolved.
|
||
| fetch(REPOS_URL) | ||
| .then((response) => response.json()) | ||
| .then((data) => { | ||
| let forkedRepos = data.filter( | ||
| (repo) => repo.fork && repo.name.includes('project-') | ||
| ); | ||
| // Sort repos based on date of creation ("created_at") | ||
| forkedRepos.sort( | ||
| (b, a) => new Date(a.created_at) - new Date(b.created_at) | ||
| ); | ||
| // Finally, use a loop to generate a card container for each project and fetch other relevant info about it | ||
| forkedRepos.forEach((repo) => { | ||
| projectsContainer.innerHTML += `<div class="repo-card"> | ||
| <h3><a class="repo-link" href="${repo.html_url}" target="_blank">${ | ||
| repo.name | ||
| }</a><h3> | ||
| <span> | ||
| <p>Default branch: ${repo.default_branch}</p> | ||
| <p>Latest push: ${new Date(repo.pushed_at).toDateString()}</p> | ||
| <p id="commit-${repo.name}">Amount of commits: </p> | ||
| <span> | ||
| </div>`; | ||
| }); | ||
| getPullRequests(forkedRepos), | ||
| //Use the data above to generate the chart from chart.js, displaying elapsed vs. remaining projects | ||
| drawChart(forkedRepos.length); | ||
| }); | ||
| }; | ||
|
|
||
| getRepositories(); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.