diff --git a/README.md b/README.md index 1613a3b0..0699b3bf 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,12 @@ # 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 aim of the project was to build a personal github tracker that would show my technigo-projects. This was done by fetching and displaying data from API's, using forEach, filter and find methods. A doughnut chart was also implemented to give a visual display of the amount of projects done. In terms of styling, a CSS grid and a hero header was used. ## 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? +In the beginning of the project it felt like there were a lot of API fetches that needed to be done. It was also hard to understand were to place, and where to call the different functions. +The solution were to scale down the project and do small chunks at a time. ## 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://github-tracker-fatima.netlify.app/ diff --git a/code/assets/background.png b/code/assets/background.png new file mode 100644 index 00000000..ed1f59ff Binary files /dev/null and b/code/assets/background.png differ diff --git a/code/chart.js b/code/chart.js index 92e85a30..cfbecc86 100644 --- a/code/chart.js +++ b/code/chart.js @@ -1,4 +1,24 @@ //DOM-selector for the canvas 👇 -const ctx = document.getElementById('chart').getContext('2d') +const ctx = document.getElementById("chart").getContext("2d"); //"Draw" the chart here 👇 + +const drawChart = (amount) => { + //This function is being called inside the getRepos function + + const config = { + type: "doughnut", + data: { + labels: ["P. Finished", "P. Left"], + datasets: [ + { + label: "My First Dataset", + data: [amount, 20 - amount], //1st number:the lenght of my repo array, 20(total projects I must do) minus the repo array + backgroundColor: ["#FFB319", "grey"], + hoverOffset: 4, + }, + ], + }, + }; + const myChart = new Chart(ctx, config); +}; diff --git a/code/index.html b/code/index.html index 2fb5e0ae..a3929c44 100644 --- a/code/index.html +++ b/code/index.html @@ -1,21 +1,81 @@ - - - - - Project GitHub Tracker - - - -

GitHub Tracker

-

Projects:

-
+ + + + + + + + + + + + + + + + + Project GitHub Tracker - - + + + + +
+ +

+ GitHub
Tracker +

+
+
+
+
+
+
- - - - \ No newline at end of file +
+ +
+

My Projects

+ +
+ +
+ +
+
+ + + + + + diff --git a/code/script.js b/code/script.js index e69de29b..ba130a5c 100644 --- a/code/script.js +++ b/code/script.js @@ -0,0 +1,87 @@ +//DOM SELECTORS: +const projectsContainer = document.getElementById("projects"); +const profileSection = document.getElementById("profile"); + +//GLOBAL VARIABLES: +const userName = "Fatima-GR"; +const API_GITHUB = `https://api.github.com/users/${userName}/repos`; //Here we use backticks instead of quotes because we are injecting a variable +const API_GITHUB_PROFILE = `https://api.github.com/users/${userName}`; + +// FUNCTIONS: + +//Get all info about my github profile +const getMyProfile = () => { + fetch(API_GITHUB_PROFILE) + .then(resp => resp.json()) + .then(data => { + profileSection.innerHTML = ` +
+ profile picture +
+
+

${data.name}

+ ${data.login} + fatigr2692@gmail.com +

${data.location}

+

+ + ` + }) +} +getMyProfile() + + +// Get all my repositories from Technigo +const getRepos = (search) => { + fetch(API_GITHUB) + .then((resp) => resp.json()) + .then((data) => { + // Filtering the repos that are forked from Technigo plus the ones that start with the project word + let forkedRepos = data.filter((repo) => repo.fork && repo.name.startsWith("project-")); + forkedRepos.forEach((repo) => { + projectsContainer.innerHTML += ` +
+ ${repo.name} +

Default branch: ${repo.default_branch}

+

Last update: ${new Date(repo.pushed_at).toDateString()}

+

Number of commits:

+
+ `; + }); + drawChart(forkedRepos.length); // Function being called with the length of the repos which is needed in the chart + getPullRequests(forkedRepos); // Function being called + }) +}; +getRepos(); + + +// Get all the pull requests of my projects +const getPullRequests = (allRepositories) => { + allRepositories.forEach((repo) => { + // console.log(repo.owner.login) + const API_PR = `https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=100`; + fetch(API_PR) + .then((resp) => resp.json()) + .then((data) => { + const myPullRequest = data.find((pull) => pull.user.login === repo.owner.login) // It gets only the PR that I made by comparing pull.user.login with repo.owner.login + // Detect if we have pull request or not: If yes - call getCommits function // If no - inform user that no pull request was yet done + if(myPullRequest) { + getCommits(myPullRequest.commits_url, repo.name); // Function being called + } else { + document.getElementById(`commit-${repo.name}`).innerHTML = + 'No pull request yet done!'; + } + }); + }); +}; + +// Get the amount of commits +const getCommits = (myCommitsUrl,myRepoName) => { + fetch(myCommitsUrl) + .then(res => res.json()) + .then(data => { + document.getElementById(`commit-${myRepoName}`).innerHTML += ` ${data.length}`; + }) +} + + diff --git a/code/style.css b/code/style.css index 7c8ad447..1f430b25 100644 --- a/code/style.css +++ b/code/style.css @@ -1,3 +1,213 @@ +:root { + --primary: #F0A500; + --secondary:#fff; +} + +* { + box-sizing: border-box; + margin: 0; + padding: 0; +} + body { - background: #FFECE9; -} \ No newline at end of file + font-size: 20px; +} +/* Header */ +.header { + background-color: var(--secondary); + position: relative; + height: 160px; +} + +.heading-one { + text-align: center; + font-family: 'Yanone Kaffeesatz', sans-serif; + font-size: 50px; +} + +.tracker { + color:var(--primary); +} + +.fab { + color:#000; + margin-top:18px; + margin-left: 15px; + font-size:28px; +} + +.burger { + height: 50px; + position: absolute; + top:18px; + right: 20px; +} + +.burger div { + width: 30px; + height: 6px; + background-color: #000; + border:1px solid var(--secondary); +} + +/* Profile section */ +.profile-section { + height: 700px; + background-color: black; + font-family: 'Roboto Condensed', sans-serif; +} + +.picture-container { + text-align: center; +} + +.profile-pic { + width: 200px; + border-radius: 50%; + padding-bottom: 25px; + margin-top: 200px; +} + +.myProfile { + color:var(--secondary); + padding-top: 20px; + text-align: center; + line-height: 38px; +} + +.account, .email { + display: block; + text-decoration: none; + color:var(--primary); +} + +.account:hover, .email:hover { + color:var(--secondary); +} + +.fas { + color:var(--secondary); + font-weight: 800; + margin-right: 5px; +} + +/* Main */ +.main { + background-color:var(--secondary); + +} + +.heading-two { + text-align: center; + text-transform: uppercase; + color:grey; + padding-top:10px; + font-family: 'Roboto Condensed', sans-serif; + +} + +.projects-container { + width: 90%; + margin: 10px auto; +} + +.card { + width: 90%; + height: 190px; + background-color: var(--primary); + margin:15px auto; + box-shadow: 2px 2px 1px; + font-family: 'Roboto Condensed', sans-serif; + padding: 10px; + line-height: 30px; + color:grey; + box-shadow:10px 5px 5px; + text-align: center; +} + +.card:hover { + transform: scale(1.1,1.1); +} + + .repo { + color:grey; + text-decoration: none; + text-align: center; + display: block; + font-size: 1.3rem; + padding-bottom: 10px; + text-transform: uppercase; + text-shadow: 0.5px 0.5px 1px grey; + } + +.repo:hover { + color:#E8F6EF; +} + +span { + color:#E8F6EF; +} + + +/* Chart */ +.chart { + margin: 0 auto; + width: 300px; + padding-bottom: 15px; +} + +/* Footer */ +.footer { + background-color: #000; + height: 150px; +} + +.icon-footer { + text-align: center; +} + +.orange-icon { + color:var(--primary); + font-size:26px; + margin:30px auto; +} + +.copyright { + color:#B8DFD8; +} + +/* Media Queries */ + +@media(min-width: 768px) { + .projects-container { + display: flex; + flex-wrap: wrap; + } + + .card { + width: 40%; + max-width: 350px; + } + +} + + +@media(min-width:1334px) { + + html { + background-color:#E6E6E6; + } + + body { + width: 60%; + margin: 0 auto; + } +} + +@media(min-width:1685px) { + .chart { + width: 350px; + } +} + +