-
Notifications
You must be signed in to change notification settings - Fork 131
Github tracker for Anna Thunberg #53
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
1b9a3e2
14641d7
af16326
767923c
e0b9fb4
a6f5a44
2b31f8c
ea08752
52004ed
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,18 @@ | ||
| # 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. | ||
| A site that keeps track of my Github repositories. | ||
| The project name (with url), latest push, number of commits and pull request is fetched from the Github API, along with my profile info. | ||
|
|
||
| ## 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? | ||
| I fetched all my repos and used the filter method to only keep the ones forked from Technigo that start with "project". | ||
| I fetched the other data using a similar method, either directly from the API if possible, and filtered it when necessary. | ||
| For sorting the repos in order by date, I used a function that I found on stack overflow to avoid a lot of issues with dates in js. | ||
|
|
||
| My plan was to use grid for my layout, however, that part is NOT complete yet (as of deadline) and I will keep working on it. | ||
| The page works on different devices, but I plan to make the project-divs look more unified in height. | ||
|
|
||
|
|
||
| ## 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://annathunberg-githubtracker.netlify.app/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,16 +5,60 @@ | |
| <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="preconnect" href="https://fonts.googleapis.com"> | ||
| <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
| <link href="https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@400;500;600&display=swap" rel="stylesheet"> | ||
| <link rel="stylesheet" href="./style.css" /> | ||
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <h1>GitHub Tracker</h1> | ||
| <h2>Projects:</h2> | ||
| <main id="projects"></main> | ||
|
|
||
|
|
||
|
|
||
| <section class="profile-section"> | ||
|
|
||
| <img id="avatar"> </img> | ||
|
|
||
| <p id="full-name"></p> | ||
|
|
||
| <p id="username"></p> | ||
|
|
||
| </section> | ||
|
|
||
| <section class="projects-section"> | ||
|
|
||
| <h2>My Projects</h2> | ||
|
|
||
| <main> | ||
| <div class="grid-container"> | ||
| <div class="grid-item"> | ||
|
|
||
| <div id="list"></div> | ||
|
|
||
| </div> <!--closing tag grid item--> | ||
|
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. Great reminder! I should use comments like these more often. It is so easy to delete the wrong one >< |
||
| </div> <!--closing tag grid container--> | ||
|
|
||
| </main> | ||
|
|
||
| </section> | ||
|
|
||
|
|
||
|
|
||
| <h2>Project count</h2> | ||
|
|
||
| <div id="chart-wrapper"> | ||
|
|
||
|
|
||
|
|
||
| <!-- This will be used to draw the chart 👇 --> | ||
| <canvas id="chart"></canvas> | ||
|
|
||
| </div> | ||
|
|
||
| </section> | ||
|
|
||
| <script src="./script.js"></script> | ||
| <script src="./chart.js"></script> | ||
| </body> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // DOM SELECTORS | ||
| const list = document.getElementById('list') | ||
| const avatar = document.getElementById('avatar') | ||
| const fullName = document.getElementById('full-name') | ||
| const username = document.getElementById('username') | ||
|
|
||
| // LIST OF APIS TO FETCH FROM | ||
| const USER = 'annathunberg' | ||
| const API_MY_REPOS = `https://api.github.com/users/${USER}/repos`// user-variable instead of my login | ||
| const API_MY_PROFILE = 'https://api.github.com/users/annathunberg' | ||
|
|
||
| // FETCHES THE PROFILE PIC, NAME AND USERNAME | ||
| fetch(API_MY_PROFILE) | ||
| .then((response) => response.json()) | ||
| .then((data) => { | ||
| fullName.innerHTML = `Hi! I'm ${data.name}` | ||
| username.innerHTML = `Username: <a href="${data.html_url}">${data.login}</a>` | ||
| avatar.src = data.avatar_url | ||
| }) | ||
|
|
||
| // FETCHES MY REPOS | ||
|
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 like the clean headings to comment your code. Makes it very readble. |
||
| fetch(API_MY_REPOS) | ||
| .then((response) => response.json()) | ||
| .then((data) => { | ||
| const forkedRepos = data.filter(isFork) | ||
| const sortedForkedRepos = forkedRepos.sort(sortingFunctionFromStackOverflow) | ||
| sortedForkedRepos.forEach(addRepoToList) | ||
| drawChart(sortedForkedRepos.length) | ||
| addCommits(sortedForkedRepos) | ||
| addPullRequests(sortedForkedRepos) | ||
| }) | ||
|
|
||
| function addCommits(repos) { | ||
| repos.forEach((repo) => { | ||
| const commitsUrl = `https://api.github.com/repos/${USER}/${repo.name}/commits`; | ||
| fetch(commitsUrl) | ||
| .then((response) => response.json()) | ||
| .then((data) => { | ||
| document.getElementById(`commit-${repo.name}`).innerHTML = `Commits: ${data.length}` | ||
| }) | ||
| }); | ||
| } | ||
|
|
||
| function addPullRequests(repos) { | ||
| repos.forEach((repo) => { | ||
| const pullRequestsUrl = `https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`; | ||
| fetch(pullRequestsUrl) | ||
| .then((response) => response.json()) | ||
| .then((data) => { | ||
| const myPullRequests = data.filter((pullRequest) => pullRequest.user.login === USER); | ||
| // IF ELSE STATEMENT FOR 0 PULLS? | ||
| document.getElementById(`pull-request-${repo.name}`).innerHTML = `Pull requests: ${myPullRequests.length}` | ||
|
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. You have solved this in another way than Maks (or was it jennie?) showed us. I actually like yours better. It is more understandable when you visit the site. |
||
| }); | ||
| }); | ||
| } | ||
|
|
||
| // RETURNS REPOS THAT ARE FORKED AND START WITH PROJECTS | ||
| function isFork(repo) { | ||
| return repo.fork && repo.name.startsWith('project-') | ||
| } | ||
|
|
||
| // CREATES THE LIST OF REPOS | ||
| function addRepoToList(repo) { | ||
| list.innerHTML += `<div> | ||
| <a href="${repo.html_url}">${repo.name}</a> | ||
| <p>Default Branch: ${repo.default_branch}</p> | ||
| <p>Updated: ${new Date(repo.pushed_at).toDateString()}</p> | ||
| <p id="commit-${repo.name}"></p> | ||
| <p id="pull-request-${repo.name}"></p> | ||
| </div>` | ||
| } | ||
|
|
||
| // SORTS THE REPOS IN CHRONOLOGICAL ORDER BY DATE | ||
|
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. The famous sorting function! I used it as well :) Maybe reverse the order to get the latest and most advanced project first? |
||
| function sortingFunctionFromStackOverflow(a, b) { | ||
| // https://stackoverflow.com/questions/10123953/how-to-sort-an-object-array-by-date-property | ||
| return new Date(a.created_at) - new Date(b.created_at) | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
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.
Airy code - but I like it!