-
Notifications
You must be signed in to change notification settings - Fork 131
Week 7 - GitHub tracker #95
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
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // .gitignore file | ||
| code/secret.js |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,17 @@ | ||
| # GitHub Tracker | ||
|
|
||
| Replace this readme with your own information about your project. | ||
| This week I create a place to keep track of the GitHub repos. | ||
| HTML,CSS and javascript. | ||
|
|
||
| Start by briefly describing the assignment in a sentence or two. Keep it short and to the point. | ||
|
|
||
| ## The problem | ||
| I started with fetching the information through API. | ||
| then I tried to figure out how to filter the information I needed. | ||
| When I had information i displayed it on the site. | ||
| Styled with CSS (mobile first). | ||
|
|
||
| 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 try to include a search bar and also which languages the projects includes. | ||
|
|
||
| ## 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://silly-mestorf-a038ed.netlify.app/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,34 @@ | ||
| //DOM-selector for the canvas 👇 | ||
| const ctx = document.getElementById('chart').getContext('2d') | ||
|
|
||
| //"Draw" the chart here 👇 | ||
|
|
||
| //Chart | ||
| const activateChart = (projects) => { | ||
| console.log(projects) | ||
| const labels = [ | ||
| 'Completed projects', | ||
| 'Total projects', | ||
| ]; | ||
|
|
||
| const data = { | ||
| labels: labels, | ||
| datasets: [{ | ||
| label: 'Progress', | ||
| backgroundColor: ['rgb(57, 138, 185)','rgb(28, 101, 140)'], | ||
| borderColor: 'rgb(238, 238, 238)', | ||
| data: [projects, 19-projects], | ||
| }] | ||
| }; | ||
|
|
||
| const config = { | ||
| type: 'doughnut', | ||
| data: data, | ||
| options: {} | ||
| }; | ||
|
|
||
| new Chart( | ||
| document.getElementById('chart'), | ||
| config | ||
| ); | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,46 @@ | ||
| <!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" /> | ||
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | ||
| <link | ||
| href="https://fonts.googleapis.com/css2?family=Comforter&family=Fuzzy+Bubbles:wght@700&family=Montserrat:wght@300;400;700&family=Oswald:wght@300;500;600&family=Pacifico&family=Roboto:wght@300;400&family=Rock+Salt&family=Rowdies:wght@700&display=swap" | ||
| rel="stylesheet"> | ||
| </head> | ||
|
|
||
| <body> | ||
| <h1>GitHub Tracker</h1> | ||
| <h2>Projects:</h2> | ||
| <main id="projects"></main> | ||
| <header class="navigation-bar"> | ||
| <h1>GitHub Tracker</h1> | ||
| </a> | ||
| </header> | ||
| <div class="big-container"> | ||
| <div class="info-contain"> | ||
| <div id="profile-info" class="profile-container"></div> | ||
| <div class="chart-container"> | ||
| <h2>Progress</h2> | ||
| <canvas id="chart" class="chart"></canvas> | ||
| </div> | ||
| </div> | ||
|
|
||
| <!-- This will be used to draw the chart 👇 --> | ||
| <canvas id="chart"></canvas> | ||
| <div class="projects-container"> | ||
| <h2>Projects</h2> | ||
| <div id="projects" class="projects"> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <footer> | ||
| <h4>Technigo Week 7 Github Tracker</h4> | ||
| </footer> | ||
|
|
||
| <script src="./script.js"></script> | ||
| <script src="./secret.js"></script> | ||
| <script src="./chart.js"></script> | ||
| <script src="./token.js"></script> | ||
| <script src="./script.js"></script> | ||
| </body> | ||
|
|
||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| allow_forking: true | ||
| archive_url: "https://api.github.com/repos/toal13/project-business-site/{archive_format}{/ref}" | ||
| archived: false | ||
| assignees_url: "https://api.github.com/repos/toal13/project-business-site/assignees{/user}" | ||
| blobs_url: "https://api.github.com/repos/toal13/project-business-site/git/blobs{/sha}" | ||
| branches_url: "https://api.github.com/repos/toal13/project-business-site/branches{/branch}" | ||
| clone_url: "https://github.com/toal13/project-business-site.git" | ||
| collaborators_url: "https://api.github.com/repos/toal13/project-business-site/collaborators{/collaborator}" | ||
| comments_url: "https://api.github.com/repos/toal13/project-business-site/comments{/number}" | ||
| commits_url: "https://api.github.com/repos/toal13/project-business-site/commits{/sha}" | ||
| compare_url: "https://api.github.com/repos/toal13/project-business-site/compare/{base}...{head}" | ||
| contents_url: "https://api.github.com/repos/toal13/project-business-site/contents/{+path}" | ||
| contributors_url: "https://api.github.com/repos/toal13/project-business-site/contributors" | ||
| created_at: "2022-01-23T16:12:15Z" | ||
| default_branch: "master" | ||
| deployments_url: "https://api.github.com/repos/toal13/project-business-site/deployments" | ||
| description: null | ||
| disabled: false | ||
| downloads_url: "https://api.github.com/repos/toal13/project-business-site/downloads" | ||
| events_url: "https://api.github.com/repos/toal13/project-business-site/events" | ||
| fork: true | ||
| forks: 0 | ||
| forks_count: 0 | ||
| forks_url: "https://api.github.com/repos/toal13/project-business-site/forks" | ||
| full_name: "toal13/project-business-site" | ||
| git_commits_url: "https://api.github.com/repos/toal13/project-business-site/git/commits{/sha}" | ||
| git_refs_url: "https://api.github.com/repos/toal13/project-business-site/git/refs{/sha}" | ||
| git_tags_url: "https://api.github.com/repos/toal13/project-business-site/git/tags{/sha}" | ||
| git_url: "git://github.com/toal13/project-business-site.git" | ||
| has_downloads: true | ||
| has_issues: false | ||
| has_pages: false | ||
| has_projects: true | ||
| has_wiki: true | ||
| homepage: null | ||
| hooks_url: "https://api.github.com/repos/toal13/project-business-site/hooks" | ||
| html_url: "https://github.com/toal13/project-business-site" | ||
| id: 451158190 | ||
| is_template: false | ||
| issue_comment_url: "https://api.github.com/repos/toal13/project-business-site/issues/comments{/number}" | ||
| issue_events_url: "https://api.github.com/repos/toal13/project-business-site/issues/events{/number}" | ||
| issues_url: "https://api.github.com/repos/toal13/project-business-site/issues{/number}" | ||
| keys_url: "https://api.github.com/repos/toal13/project-business-site/keys{/key_id}" | ||
| labels_url: "https://api.github.com/repos/toal13/project-business-site/labels{/name}" | ||
| language: "CSS" | ||
| languages_url: "https://api.github.com/repos/toal13/project-business-site/languages" | ||
| license: null | ||
| merges_url: "https://api.github.com/repos/toal13/project-business-site/merges" | ||
| milestones_url: "https://api.github.com/repos/toal13/project-business-site/milestones{/number}" | ||
| mirror_url: null | ||
| name: "project-business-site" | ||
| node_id: "R_kgDOGuQgrg" | ||
| notifications_url: "https://api.github.com/repos/toal13/project-business-site/notifications{?since,all,participating}" | ||
| open_issues: 0 | ||
| open_issues_count: 0 | ||
| owner: {login: 'toal13', id: 91566202, node_id: 'U_kgDOBXUweg', avatar_url: 'https://avatars.githubusercontent.com/u/91566202?v=4', gravatar_id: '', …} | ||
| private: false | ||
| pulls_url: "https://api.github.com/repos/toal13/project-business-site/pulls{/number}" | ||
| pushed_at: "2022-01-29T19:48:50Z" | ||
| releases_url: "https://api.github.com/repos/toal13/project-business-site/releases{/id}" | ||
| size: 19693 | ||
| ssh_url: "git@github.com:toal13/project-business-site.git" | ||
| stargazers_count: 0 | ||
| stargazers_url: "https://api.github.com/repos/toal13/project-business-site/stargazers" | ||
| statuses_url: "https://api.github.com/repos/toal13/project-business-site/statuses/{sha}" | ||
| subscribers_url: "https://api.github.com/repos/toal13/project-business-site/subscribers" | ||
| subscription_url: "https://api.github.com/repos/toal13/project-business-site/subscription" | ||
| svn_url: "https://github.com/toal13/project-business-site" | ||
| tags_url: "https://api.github.com/repos/toal13/project-business-site/tags" | ||
| teams_url: "https://api.github.com/repos/toal13/project-business-site/teams" | ||
| topics: [] | ||
| trees_url: "https://api.github.com/repos/toal13/project-business-site/git/trees{/sha}" | ||
| updated_at: "2022-01-29T19:36:22Z" | ||
| url: "https://api.github.com/repos/toal13/project-business-site" | ||
| visibility: "public" | ||
| watchers: 0 | ||
| watchers_count: 0 | ||
| [[Prototype]]: Object | ||
| 2: {id: 454313860, node_id: 'R_kgDOGxRHhA', name: 'project-chatbot', full_name: 'toal13/project-chatbot', private: false, …} | ||
| 3: {id: 462003502, node_id: 'R_kgDOG4mdLg', name: 'project-github-tracker', full_name: 'toal13/project-github-tracker', private: false, …} | ||
| 4: {id: 456101513, node_id: 'R_kgDOGy-OiQ', name: 'project-guess-who', full_name: 'toal13/project-guess-who', private: false, …} | ||
| 5: {id: 448514498, node_id: 'R_kgDOGrvJwg', name: 'project-news-site', full_name: 'toal13/project-news-site', private: false, …} | ||
| 6: {id: 462883011, node_id: 'R_kgDOG5cIww', name: 'project-weather-app', full_name: 'toal13/project-weather-app', private: false, …} | ||
| 7: {id: 462241115, node_id: 'R_kgDOG409Ww', name: 'unit-tests', full_name: 'toal13/unit-tests', private: false, …} | ||
| length: 8 | ||
| [[Prototype]]: Array(0) | ||
| fiveserver.js:1 [Five Server] connected. | ||
| | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
|
|
||
| //-----DOM-----// | ||
| const profileInfo = document.getElementById("profile-info") | ||
| const projectsContainer = document.getElementById("projects") | ||
|
|
||
|
|
||
| //-----Global variables -----// | ||
| const userName = 'toal13' | ||
| const authorName = 'Tomoyo Alvåg' | ||
| const API_URL = `https://api.github.com/users/${userName}/repos`; | ||
| const USER_API = `https://api.github.com/users/${userName}`; | ||
|
|
||
|
|
||
| //-----Token-----// | ||
| const options = { | ||
| method: 'GET', //POST, PATCH, DELETE | ||
| headers: { | ||
| Authorization: `token ${TOKEN}` | ||
| } | ||
| } | ||
|
|
||
|
|
||
| //------Profile-----// | ||
| const getUser = () => { | ||
| fetch(USER_API, options) | ||
| .then(res => res.json()) | ||
| .then((data) => { | ||
| profileInfo.innerHTML += ` | ||
| <h2><img src = "./github.png"><a href="https://github.com/${userName}" target="_blank">${data.login}</a></h2> | ||
|
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. I love the small GitHub img next to your name! And it looks great in desktop mode that you placed this section and the chart to the left of the projects! |
||
| <img src = "${data.avatar_url}" class="user-picture"/> | ||
| ` | ||
| }) | ||
| } | ||
|
|
||
|
|
||
| //-----Repos-----// | ||
| const getRepos = () => { | ||
| fetch(API_URL, options) | ||
| .then(res => res.json()) | ||
| .then(data => { | ||
| //-----Filter repos-----// | ||
| const forkedRepos = data.filter((repo) => repo.fork && repo.name.startsWith('project-')); | ||
|
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. Very nice that you have both the fork and the project filters in the same row! |
||
|
|
||
| //-----Show repos in projectsContainer-----// | ||
| forkedRepos.forEach((repo) => { | ||
| projectsContainer.innerHTML += | ||
| `<div id= "projects"> | ||
| <h3><a href = ${repo.html_url}> ${repo.name} </a></h3> | ||
| <p>Default branch: ${repo.default_branch}</p> | ||
| <p>Latest push: ${repo.pushed_at.slice(0, 10)}, ${repo.pushed_at.slice(11, 16)}</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. what a nice detail with the time to here! |
||
| <p id="pull-${repo.name}"></p> | ||
| <p id="commit-${repo.name}">Commits: </p> | ||
| </div>`; | ||
| }); | ||
| //-----Initiate next function and chart-----// | ||
| fetchPullRequests(forkedRepos) | ||
| activateChart(forkedRepos.length) | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
| //-----My pull request-----// | ||
| const fetchPullRequests = (allRepos) => { | ||
| allRepos.forEach((repo) => { | ||
| const PULL_URL = `https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`; | ||
| fetch(PULL_URL, options) | ||
| .then((res) => res.json()) | ||
| .then((data) => { | ||
| //-----Check if i have a pullrequest for that repo user login and repo owner-----// | ||
| const myPullRequest = data.find( | ||
| (pull) => pull.user.login === repo.owner.login); | ||
| //-----If yes, start function getCommits-----// | ||
|
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. Here you could also add a link to the pullrequests - I did it like this: Pull request made by teammate } |
||
| if (myPullRequest) { | ||
| getCommits(myPullRequest.commits_url, repo.name); | ||
| //----If not, assume and print Group project-----// | ||
| } else { | ||
| document.getElementById(`commit-${repo.name}`).innerHTML = 'Group project'; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
| //-----Function to get amount of commit. Print on page.-----// | ||
| const getCommits = (myCommitsUrl, myRepoName) => { | ||
| fetch(myCommitsUrl, options) | ||
| .then((res) => res.json()) | ||
| .then((data) => { | ||
| document.getElementById(`commit-${myRepoName}`).innerHTML += [data.length]; | ||
| }); | ||
| }; | ||
|
|
||
| //-----Initiate on page load-----// | ||
| getRepos(); | ||
| getUser(); | ||
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.
If you would like to change the name of the site you can do this on Netlify if you go to the site overview > site settings > and under site information > change site name