-
Notifications
You must be signed in to change notification settings - Fork 131
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
Open
faypi
wants to merge
8
commits into
Technigo:main
Choose a base branch
from
faypi: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
8 commits
Select commit
Hold shift + click to select a range
c918528
Fetched all repos(filters: forked, from Technigo) and fetched my PRs
faypi a4cb298
got all data for blue lvl
faypi 347c381
present data to html
faypi c1ccc8e
added chart and styling
faypi d290c3f
formatting
faypi 80d7194
added netflify link on readme file
faypi 49e384c
get element before changing it
faypi f44d077
fetch comments after PRs
faypi 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| code/secret.js |
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
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
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
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,161 @@ | ||
| 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) | ||
| .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"; | ||
| } | ||
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,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; | ||
| } | ||
| } |
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.
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!