diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..c0fafcc6 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..2c1117b2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +secret.js \ No newline at end of file diff --git a/README.md b/README.md index 1613a3b0..cdc4f9b8 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. +Assignment to fetch Technigo Projects with name and URL + number of commits via pull requests. +Also calculate projects made comparing to projects remaining. ## 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 started with the Js file - trying one API fetch at a time - console logging and then positioning the data in InnerHTML before declaring and invoking next function. After all information i needed was fetched I did the styling. Last I made the chart and the token. +I googled, used SO for checking other people questions regarding this project. +If I had more time I would have added more information like commit comments. ## 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://ecstatic-wing-3740de.netlify.app/ diff --git a/code/chart.js b/code/chart.js index 92e85a30..91fc5d81 100644 --- a/code/chart.js +++ b/code/chart.js @@ -1,4 +1,29 @@ -//DOM-selector for the canvas 👇 +//DOM-selector for the canvas const ctx = document.getElementById('chart').getContext('2d') -//"Draw" the chart here 👇 +const activateChart = (projects) => { + +const labels = [ + 'Projects completed', + 'Projects in pipeline', + ]; + + const data = { + labels: labels, + datasets: [{ + data: [projects, 19-projects], + backgroundColor: ['rgb(255, 99, 132)','rgb(255, 69, 0)'], + borderColor: ['rgb(255, 99, 132)','rgb(255, 69, 0)'], + }] + }; + + const config = { + type: 'doughnut', + data: data, + }; + + new Chart(document.getElementById('chart'),config); + +} + + diff --git a/code/hero-grafitti2.jpg b/code/hero-grafitti2.jpg new file mode 100644 index 00000000..e7b6acfb Binary files /dev/null and b/code/hero-grafitti2.jpg differ diff --git a/code/index.html b/code/index.html index 2fb5e0ae..09797fca 100644 --- a/code/index.html +++ b/code/index.html @@ -5,16 +5,30 @@ Project GitHub Tracker + + + + + -

GitHub Tracker

-

Projects:

-
- - - +
+
+
+
+
+
+
+
+ + +
+
+ + + diff --git a/code/script.js b/code/script.js index e69de29b..888ec8fd 100644 --- a/code/script.js +++ b/code/script.js @@ -0,0 +1,102 @@ +//DOM selectors +const userContainer = document.getElementById ('userContainer') +const projectContainer = document.getElementById ('projectContainer') + +//Global selectors +const user = 'josse79' +const API_USER = `https://api.github.com/users/${user}` +const API_REPOS_LIST = `https://api.github.com/users/${user}/repos` + +//The TOKEN function +const options = { + method: 'GET', + headers: { + Authorization: 'API_KEY' + } +} + +//1st function and fetch to get the user details +const getUser = () => { + fetch(API_USER, options) + .then(res => res.json()) + .then(data => { + userContainer.innerHTML = ` + +

${data.login}

` + }) + getRepos () +} +//2nd function and fetch to get the repo list +const getRepos = () => { + fetch(API_REPOS_LIST, options) + .then(res => res.json()) + .then(data => { + //Filtering out the forked repos & repos starting with project + const forkedRepos = data.filter((repo) => repo.fork && repo.name.startsWith('project')) + forkedRepos.forEach((repo) => { + //Positioning the information in HTML also with dynamic ID repo.name + projectContainer.innerHTML += ` +
+

${repo.name}

+ ${repo.html_url} +

Default branch ${repo.default_branch}

+

Recent push: ${new Date(repo.pushed_at).toDateString()}

+
` + }) + //Passing the filtered repos to next function + getPullRequests(forkedRepos) + //Passing the filtered repos length to chartfunction in chart.js + activateChart(forkedRepos.length) + }) + + //3rd function and fetch to get all the pulls with help of repo.name + const getPullRequests = (repos) => { + repos.forEach(repo => { + fetch(`https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=100`, options) + .then(res => res.json()) + .then(data => { + //Filter my own pulls by comparing user login and repo owner + const filteredPulls = data.find((pull) => pull.user.login === repo.owner.login) + //Passing the filtered pulls to next functions + if (filteredPulls) { + //Passing the commits_url and review_comments_url as arguments to next functions + //Also passing along the dynamic ID repo.name to be able to positioning in HTML + getCommits(filteredPulls.commits_url, repo.name) + getReview(filteredPulls.review_comments_url, repo.name) + } else { + document.getElementById(`${repo.name}`).innerHTML += ` +

No pull request made

` + } + }) + }) + } + + //4th function and fetch. Fetch (commits_url declared in getPullRequests function + //therefore activated by argument URL and repoName + const getCommits = (URL, repoName) => { + fetch(URL, options) + .then(res => res.json()) + .then(data => { + //Positioning by dynamic ID repoName + document.getElementById(repoName).innerHTML += ` +

Number of commits: ${data.length}

` + }) + } + + //5th function and fetch. Fetch (commits_url declared in getPullRequests function + //therefore activated by argument URL and repoName + const getReview = (URL, repoName) => { + fetch(URL, options) + .then(res => res.json()) + .then(data => { + //If any review made - positioning data by dynamic ID repoName + if (`${data[0].user.login} == ''`) { + document.getElementById(repoName).innerHTML += ` +

Review made by: ${data[0].user.login}

` + } else { + } + }) + } +} +//Invoking first function +getUser () diff --git a/code/style.css b/code/style.css index 7c8ad447..c38275e8 100644 --- a/code/style.css +++ b/code/style.css @@ -1,3 +1,114 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + -webkit-font-smoothing: antialiased; + text-rendering: optimizeLegibility; + font-family: "Roboto", sans-serif +} + +h1 { + max-height: 5vh; + min-height: 2vh; + font-weight: 500; + padding-bottom: 1vh; + margin-bottom: 1vh +} + +p { + padding: 0.5vh +} + +a { + color: rgb(255, 69, 0) +} + +.hero-image { + background-image: url("hero-grafitti2.jpg"); + width: 100vw; + height: 30vh; + background-position: center; + background-size: cover; + background-repeat: no-repeat +} + body { - background: #FFECE9; -} \ No newline at end of file + color: black; +} + +.user-container { + position: relative; + text-align: center; + bottom: 12vh +} + +.user-image { + border-radius: 50%; + width: 25vh; + filter: grayscale(100%) +} + +.project-container { + display: grid; + margin-top: -5vh; + justify-content: center; + text-align: center; +} +.repos { + padding-bottom: 5vh; + font-weight: 300; + margin-bottom: 5vh; + padding: 1vh; + cursor: pointer; +} + +.project-container :hover { + background: linear-gradient(90deg, #D1D1D1, #e6e6e6 50%, #e6e6e6 50%, #e6e6e6 50%, #D1D1D1); +} + +.chart-section { + display: flex; + justify-content: center; + margin: 7vh 0 15vh; +} +.chart-container { + max-width: 50vw; + min-width: 50vw +} + +/*media queries*/ +@media screen and (min-width: 668px) { + .hero-image { + height: 35vh + } + .user-container { + bottom: 15vh +} + .user-image { + width: 30vh + } + .project-container { + grid-template-columns: 1fr 1fr + } + h1 { + margin-bottom: 2vh + } +} + +@media screen and (min-width: 1025px) and (orientation: landscape) { + .hero-image { + height: 55vh + } + .user-container { + bottom: 18vh + } + .user-image { + width: 35vh + } + .project-container { + margin-left: 12vw; + margin-right: 12vw + } +}