-
Notifications
You must be signed in to change notification settings - Fork 130
Week 7 - GitHub Tracker - Fay Pistikozoglou #101
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 7 commits
c918528
a4cb298
347c381
c1ccc8e
d290c3f
80d7194
49e384c
f44d077
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 @@ | ||
| code/secret.js |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| const username = 'faypi' | ||
| const API_URL = `https://api.github.com/users/${username}/repos` | ||
| const API_USER_PROFILE = `https://api.github.com/users/${username}` | ||
| const projects = document.getElementById("projects"); | ||
| const profile = document.getElementById("profile"); | ||
| const totalProjectsDuringBootcamp = 19; | ||
| // const API_TOKEN = TOKEN || process.env.API_KEY; | ||
| const options = { | ||
| method: 'GET', | ||
| headers: { | ||
| Authorization: `token ${API_TOKEN}` // you need to paste your token over here. | ||
| } | ||
| } | ||
|
|
||
| fetch(API_USER_PROFILE, options) | ||
| .then(res => res.json()) | ||
| .then(data => { | ||
| const name = data.name | ||
| const profilePic = data.avatar_url | ||
| // const memberSince = data.created_at | ||
| const followers = data.followers | ||
| const following = data.following | ||
| profile.innerHTML += ` | ||
| <h1>${username}'s GitHub Tracker</h1> | ||
| <div class="profile-details"> | ||
| <img src=${profilePic} /> | ||
| <span id="fullname">${name}</span> | ||
| <span id="username">${username}</span> | ||
| <span id="following">following ${following}</span> | ||
| <span id="followers">followed by ${followers}</span> | ||
| </div> | ||
| ` | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| fetch(API_URL, options) // options object is passed as 2nd argument to fetch() function. | ||
| .then(res => res.json()) | ||
| .then(data => { | ||
| const myRepos = data.filter((forkedRepos) => forkedRepos.fork == true && forkedRepos.name.startsWith("project-")) | ||
| const numberOfProjects = myRepos.length | ||
| drawChart([numberOfProjects, totalProjectsDuringBootcamp - numberOfProjects]) | ||
| getPullRequests(myRepos) | ||
| }); | ||
|
|
||
| //Remember to pass along your filtered repos as an argument when | ||
| //you are calling this function | ||
|
|
||
| const getPullRequests = (repos) => { | ||
| //Get all the PRs for each project. | ||
| repos.forEach(repo => { | ||
| fetch('https://api.github.com/repos/technigo/' + repo.name + '/pulls' + '?per_page=100', options) | ||
| .then(res => res.json()) | ||
| .then(data => { | ||
|
|
||
| const repoBranchName = repo.default_branch | ||
| const repoName = repo.name | ||
| const repoUrl = repo.html_url | ||
|
|
||
| projects.innerHTML += ` | ||
| <div class="repo-card"> | ||
| <div class="repo" id=${repoName}> | ||
| <h2> | ||
| <a href=${repoUrl}> | ||
| ${repoName}:${repoBranchName} | ||
| </a> | ||
| </h2> | ||
| </div> | ||
| </div> | ||
| ` | ||
|
|
||
|
|
||
| const myPullRequests = data.filter((myPR) => myPR.user.login == repo.owner.login); | ||
| handlePullRequest(repoName, myPullRequests) | ||
| }) | ||
| }) | ||
|
|
||
| } | ||
|
|
||
| const handlePullRequest = (repoElementId, myPullRequests) => { | ||
|
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. good readability to define handlePullRequest separately! |
||
|
|
||
| //Get all the PRs for each project. | ||
| myPullRequests | ||
| .forEach((pullRequest) => { | ||
| const prTitle = pullRequest.title | ||
| const prUrl = pullRequest.html_url | ||
| const repo = document.getElementById(repoElementId); | ||
| repo.innerHTML += ` | ||
| <div class="pull-request"> | ||
| <span>PR: <a href=${prUrl}> ${prTitle}</a></span> | ||
| </div> | ||
| ` | ||
| }) | ||
| myPullRequests | ||
| .map(pullRequest => pullRequest.commits_url) | ||
| .forEach(commitUrl => { | ||
| fetch(commitUrl + "?per_page=100", options) | ||
| .then(res => res.json()) | ||
| .then(data => { | ||
| const mostRecentCommit = data[data.length - 1] | ||
| const commitMessage = mostRecentCommit.commit.message | ||
| const commitAuthor = mostRecentCommit.author.login | ||
| const commitUrl = mostRecentCommit.html_url | ||
| const commitDateString = mostRecentCommit.commit.author.date | ||
| const commitDate = Date.parse(commitDateString) | ||
| const commitTimeSince = timeSince(commitDate) | ||
|
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 to use function definition for displaying date 👍 |
||
| const repo = document.getElementById(repoElementId); | ||
| repo.innerHTML += ` | ||
| <div> | ||
| <p>${data.length} commits</p> | ||
| <p>latest: <a href=${commitUrl}>${commitMessage}</a> by ${commitAuthor} ${commitTimeSince}</p> | ||
| </div> | ||
| ` | ||
| }) | ||
| }) | ||
|
|
||
| myPullRequests | ||
| .map(pullRequest => pullRequest.review_comments_url) | ||
|
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 just wonder if you need both map and forEach?
Author
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 separated the 2 just to have a bit cleaner code. It is totally optional :) Thanks for checking though! |
||
| .forEach(reviewCommentUrl => { | ||
| fetch(reviewCommentUrl + "?per_page=100", options) | ||
| .then(res => res.json()) | ||
| .then(data => { | ||
| const repo = document.getElementById(repoElementId); | ||
| repo.innerHTML += ` | ||
| <div class="comments"> | ||
| <span>received ${data.length} comments</span> | ||
| </div> | ||
| ` | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| function timeSince(date) { | ||
|
|
||
| var seconds = Math.floor((new Date() - date) / 1000); | ||
|
|
||
| var interval = seconds / 31536000; | ||
|
|
||
| if (interval > 1) { | ||
| return Math.floor(interval) + " years ago"; | ||
| } | ||
| interval = seconds / 2592000; | ||
| if (interval > 1) { | ||
| return Math.floor(interval) + " months ago"; | ||
| } | ||
| interval = seconds / 86400; | ||
| if (interval > 1) { | ||
| return Math.floor(interval) + " days ago"; | ||
| } | ||
| interval = seconds / 3600; | ||
| if (interval > 1) { | ||
| return Math.floor(interval) + " hours ago"; | ||
| } | ||
| interval = seconds / 60; | ||
| if (interval > 1) { | ||
| return Math.floor(interval) + " minutes ago"; | ||
| } | ||
| return Math.floor(seconds) + " seconds ago"; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,59 @@ | ||
| body { | ||
| background: #FFECE9; | ||
| margin: 0 auto; | ||
| font-family: 'Titillium Web', sans-serif; | ||
| } | ||
|
|
||
| #projects { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| .repo-card { | ||
| max-width: 250px; | ||
| margin-bottom: 30px; | ||
| border: 1px solid #776c6c42; | ||
| } | ||
|
|
||
| .repo { | ||
| padding: 20px; | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: space-between; | ||
| } | ||
|
|
||
| .repo a { | ||
| color: inherit; | ||
| } | ||
|
|
||
| #chart { | ||
| margin: 20px 0; | ||
| } | ||
|
|
||
| .profile-card { | ||
| display: flex; | ||
| flex-direction: column; | ||
| max-width: 250px; | ||
| margin: 0 auto; | ||
| } | ||
|
|
||
| .profile-details { | ||
| display: flex; | ||
| flex-direction: column; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .profile-details img { | ||
| width: 100%; | ||
| border-radius: 30%; | ||
| } | ||
|
|
||
| h1, h2 { | ||
| text-align: center; | ||
| } | ||
|
|
||
| @media (min-width: 530px) { | ||
| #projects { | ||
| justify-content: space-between; | ||
| } | ||
| } |
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.
great inline expression 👍
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.
Thank youuu!