-
Notifications
You must be signed in to change notification settings - Fork 131
GitHub Tracker by Joanna Lodell - Week 7 #97
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
1cca47c
f13604c
8cf3515
c3f623a
0e8d81b
68343ef
638f0f5
a0ed74c
44d2554
c0a4942
a5ed4be
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,11 @@ | ||
| # 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. | ||
| The assignment was to create a GitHub Tracker. | ||
|
|
||
| ## 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? | ||
| Using HTML, CSS and JS. Using the API:s frm GitHub. Also first use of a chart. If I had more time I would've continued with the styling and JS functions. The styling as of now I think has too much code. | ||
|
|
||
| ## 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://modest-archimedes-0644fa.netlify.app/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,37 @@ | ||
| //DOM-selector for the canvas 👇 | ||
| const ctx = document.getElementById('chart').getContext('2d') | ||
| const ctx = document.getElementById("myChart").getContext("2d"); | ||
|
|
||
| //"Draw" the chart here 👇 | ||
|
|
||
| const drawChart = (amount) => { | ||
| const config = { | ||
| type: "bar", | ||
| data: { | ||
| labels: ["Finished projects", "Projects to do"], | ||
| datasets: [ | ||
| { | ||
| label: "Technigo Projects", | ||
| data: [amount, 19 - amount], | ||
| backgroundColor: ["#13233d", "#fafafa"], | ||
|
|
||
| hoverOffset: 4, | ||
| }, | ||
| ], | ||
| }, | ||
| options: { | ||
| layout: { | ||
| padding: 25, | ||
| }, | ||
| plugins: { | ||
| legend: { | ||
| labels: { | ||
| font: { | ||
| size: 15, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
| const myChart = new Chart(ctx, config); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // DOM SELECTORS | ||
| const projectsContainer = document.getElementById('projects') | ||
| const header = document.getElementById('header') | ||
| const profile = document.getElementById('profile') | ||
|
|
||
|
|
||
| // GLOBAL VARIABLES | ||
| const username = 'joannalodell19' | ||
| let filteredRepo = [] // Probably not needed | ||
|
|
||
| // let reponame = '' | ||
| const API_URL = `https://api.github.com/users/${username}/repos` | ||
| const API_PROFILE = `https://api.github.com/users/${username}` | ||
|
|
||
| const API_TOKEN = TOKEN || process.env.API_KEY; | ||
|
|
||
| const options = { | ||
| method: 'GET', | ||
| headers: { | ||
| Authorization: `token ${API_TOKEN}` | ||
| } | ||
| } | ||
|
|
||
| const profilePic = () => { | ||
| fetch(API_PROFILE) | ||
| .then(res => res.json()) | ||
| .then(data => { | ||
| // console.log(data) | ||
| picture = data.avatar_url | ||
| let profilePicture = `<div class = "photobox"> | ||
| <img class = "photo" src="${picture}" /> | ||
| <p>${username}</p> | ||
| </div>`; | ||
| return (profile.innerHTML += profilePicture) | ||
| }) | ||
| } | ||
|
|
||
| profilePic() | ||
|
|
||
| const getRepos = () => { | ||
| fetch(API_URL) | ||
| .then(res => res.json()) | ||
| .then(data => { | ||
| // console.log('unfiltered data', data) | ||
|
|
||
| const forkedRepos = data.filter(repo => repo.fork = true) | ||
| // console.log('data filtered by forks', forkedRepos) | ||
|
|
||
| const filteredRepo = forkedRepos.filter(repo => repo.name.startsWith('project-') === true) | ||
| // console.log('data filtered on projects', filteredRepo) | ||
|
|
||
| filteredRepo.forEach(repo => { | ||
| // console.log(repo.commits_url) | ||
| projectsContainer.innerHTML += ` | ||
| <div class="repo" id=${repo.name}> | ||
| <a href="${repo.html_url}"><h3>${repo.name}</h3></a> | ||
| <p> Default branch: ${repo.default_branch}</p> | ||
| <p> Recent push: ${new Date(repo.pushed_at).toDateString()}</p> | ||
| <p id='commit-${repo.name}'> Number of commits: </p> | ||
| </div> | ||
| ` | ||
| }) | ||
| getPullRequests(filteredRepo); | ||
| drawChart(filteredRepo.length) | ||
| }) | ||
| } | ||
|
|
||
|
|
||
| getRepos() | ||
|
|
||
| // Pull requests for each 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. Good comment! Makes it easy to understand what the code does, even for someone who is new to coding and maybe dosen't understand exactly what the function does! |
||
| const getPullRequests = (repos) => { | ||
| repos.forEach((repo) => { | ||
| const PULLREQUEST_URL = `https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`; | ||
| fetch(PULLREQUEST_URL, options) | ||
| .then((res) => res.json()) | ||
| .then((pull) => { | ||
| const myPullRequest = pull.find( | ||
| (pull) => pull.user.login === repo.owner.login | ||
| ); | ||
|
|
||
| // If pull request done by user, getCommits function is invoked | ||
| if (myPullRequest) { | ||
| getCommits(myPullRequest.commits_url, repo.name); | ||
| } else { | ||
| document.getElementById(`commit-${repo.name}`).innerHTML = | ||
| "No pull request done by user"; | ||
|
Comment on lines
+82
to
+87
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 code! I struggled alot to make my if statements actually work, and my code became way longer to get the same result! |
||
| } | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| const getCommits = (myCommitsUrl, myRepoName) => { | ||
| fetch(myCommitsUrl) | ||
| .then((res) => res.json()) | ||
| .then((commit) => { | ||
| document.getElementById(`commit-${myRepoName}`).innerHTML += | ||
| commit.length; | ||
| }); | ||
| }; | ||
|
|
||
| //myChart(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,106 @@ | ||
| * { | ||
| box-sizing: border-box; | ||
| -webkit-box-sizing: border-box; | ||
| -moz-box-sizing: border-box; | ||
| -webkit-font-smoothing: antialiased; | ||
| text-rendering: optimizeLegibility; | ||
| } | ||
|
|
||
| body { | ||
| background: #FFECE9; | ||
| } | ||
| background: pink; | ||
| font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| max-height: 100vh; | ||
| } | ||
|
|
||
| .header { | ||
| display: grid; | ||
| grid-template-columns: auto; | ||
| align-items: center; | ||
| width: auto; | ||
| } | ||
|
|
||
| h1 { | ||
| display: flex; | ||
| width: 100%; | ||
| margin: auto; | ||
| margin-top: 10%; | ||
| justify-content: center; | ||
| font-size: 8vw; | ||
| font-weight: 700; | ||
| color: #13233d; | ||
| text-transform: uppercase; | ||
| } | ||
|
|
||
| .profile { | ||
| align-items: center; | ||
| } | ||
|
|
||
| .photobox { | ||
| align-items: center; | ||
| padding: 5%; | ||
| margin-top: 20px; | ||
| } | ||
|
|
||
| .photobox p { | ||
| color: black; | ||
| font-weight: bolder; | ||
| } | ||
|
|
||
| .photo { | ||
| width: 100px; | ||
| border-radius: 50%; | ||
| border: #13233d solid 3px; | ||
| } | ||
|
|
||
| .projects { | ||
| display: grid; | ||
| grid-template-columns: 1 fr; | ||
| justify-content: center; | ||
| margin-bottom: 50px; | ||
| } | ||
|
|
||
| .repo { | ||
| background-color: #fafafa; | ||
| display: flex; | ||
| flex-direction: column; | ||
| margin-top: 5%; | ||
| width: 300px; | ||
| padding: 3%; | ||
| border: 5px dashed #13233d; | ||
| } | ||
|
|
||
| .repo p { | ||
| font-weight: 600; | ||
| margin: 2px; | ||
| color: #13233d; | ||
| } | ||
|
|
||
| .repo a { | ||
| color: #13233d; | ||
| text-decoration: none; | ||
|
|
||
| } | ||
|
|
||
| a:hover { | ||
| text-decoration: underline; | ||
| } | ||
|
|
||
|
|
||
| @media (min-width: 768px) { | ||
|
|
||
| .projects { | ||
| display: grid; | ||
| grid-template-columns: 1fr 1fr; | ||
| column-gap: 5%; | ||
| } | ||
| } | ||
|
|
||
| @media (min-width: 1024px) { | ||
| .projects { | ||
| display: grid; | ||
| grid-template-columns: 1fr 1fr 1fr; | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
To make the code more clean, try and remember to remove console.logs before sending it. I miss these all the time aswell so I'm not critizicing in any way. I belive they will be much harder on us removing these further on.