From 58dfaf3fdea6e7af122f56bb3f901d58060f3f7c Mon Sep 17 00:00:00 2001 From: StepbyStepp <91485842+SteppbySteph@users.noreply.github.com> Date: Mon, 21 Feb 2022 16:31:18 +0100 Subject: [PATCH 01/12] fetching repos --- code/script.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/code/script.js b/code/script.js index e69de29b..b448402a 100644 --- a/code/script.js +++ b/code/script.js @@ -0,0 +1,19 @@ +const projects = document.getElementById('projects') + +const username = 'SteppbySteph' +const USER_URL = `https://api.github.com/users/${username}/repos` + +//const USER_URL =('https://api.github.com/users/SteppbySteph/repos') +// const REPOS_URL = + + +//----FETCHING ALL REPOS----// +const fetchUserRepos = () => { + fetch(USER_URL) + .then(res => res.json()) + .then(data => { + console.log('repos', data) + }) +} + +fetchUserRepos() \ No newline at end of file From ca37893d29b6def6f33397fc8f93b04058852245 Mon Sep 17 00:00:00 2001 From: StepbyStepp <91485842+SteppbySteph@users.noreply.github.com> Date: Mon, 21 Feb 2022 17:15:30 +0100 Subject: [PATCH 02/12] fetching userProfile and avatar --- code/script.js | 34 ++++++++++++++++++++++++++++++++-- code/style.css | 5 +++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/code/script.js b/code/script.js index b448402a..4c28c5b2 100644 --- a/code/script.js +++ b/code/script.js @@ -1,19 +1,49 @@ const projects = document.getElementById('projects') const username = 'SteppbySteph' -const USER_URL = `https://api.github.com/users/${username}/repos` +const USER_PROFILE = `https://api.github.com/users/${username}` +const USER_REPO = `https://api.github.com/users/${username}/repos` //const USER_URL =('https://api.github.com/users/SteppbySteph/repos') // const REPOS_URL = +//----USER NAME & PROFILE----// + +const getProfile = () =>{ + fetch(USER_PROFILE) + .then(res => res.json()) + .then(data => { + console.log('user', data) + + const user = data.login + const avatar = data.avatar_url + projects.innerHTML += ` +
description
+// ` +// }) +// getPullRequests(forkedRepos) +// const getPullRequests = (repos) => { +// const USER_PR = `https://api.github.com/repos/Technigo/${repoName}/pulls?per_page=100` +// forkedRepos.forEach(repo => { +// fetch(USER_PR, options) +// .then(res => res.json()) +// .then(data => { +// console.log('PR', data) + +// }) + +// }) +// } - -//----FETCHING ALL REPOS----// const getRepos = () => { - fetch(USER_REPO) + fetch(USER_REPO, options) .then(res => res.json()) .then(data => { - //console.log('repos', data) - - data.forEach((item) => { - console.log('repo', item.name) + console.log('repos', data) + + // Creating constsant for my filtered repos + forkedRepos = data.filter((repo) => repo.name.startsWith('project-')) + + // forEach function to create HTML elements & pull requests + forkedRepos.forEach((repo) => { + + // Getting Repo Name + repoName = repo.name; + + + // Getting Most Recent Push Date + pushDate = repo.pushed_at.substr(0, 10) + + //Getting the Default Branch + defaultBranch = repo.default_branch + + //Getting the URL of the repo + urlRepo = repo.html_url + + // Step: Find the necessary info and add it to your innerHTML section below: + + // Creating Project InnerHTML + projects.innerHTML += ` +Most recent push date: ${pushDate}
+Name of default branch: ${defaultBranch}
+URL to the Github repo: ${urlRepo}
+Number of commits:
+ ` + + // Fetch for all pull requests + const USER_NAME = repo.owner.login + const USER_PR = `https://api.github.com/repos/Technigo/${repoName}/pulls?per_page=100`; + fetch(USER_PR, options) + .then(res => res.json()) + .then(pullRequests => { + //console.log('PR', data) + const myPR = pullRequests.find((pull) => + pull.user.login === repo.owner.login + ) + console.log(myPR) + + if(myPR) { + getCommitNr(myPR, repo.name) + } else { + document.getElementById(`commit-${repo.name}`).innerHTML += '0' + } + + // pull.forEach((pull) => { + // if (pull.user.login === repo.owner.login) { + // console.log('step pull', pull) + // } + // }) + + }) + //console.log('PR user', ) + //console.log('My pull requests', myPR) + + }) - const repoName = item.name - projects.innerHTML += `${repoName}` - }) - }) - -} + } + + const getCommitNr = (myPull, myRepoName) =>{ + fetch(myPull.commits_url) + .then(res => res.json()) + .then((commit) => { + document.getElementById(`commit-${myRepoName}`).innerHTML += commit.length + }) + + + } + + // Here you need to filter your data to only include your own pull requests + // After you have a filtered list of your pull requests, you need to add them to your innerHTML section above + + // Correct - you don't need to make a new fetch for every thing you need. Some of these fetches will include multiple data + + // I have one function which builds the header which includes my username and avatar, just like you. + // It makes sense to make it as one function because it doesn't need to iterate + + // For the project sections, where you need to add information from mulitple fetches into the same "individual project block" (i don't know what to call it) + // It makes better sense to keep it inside the same function / or inside the same "forEach" or "for" loop + + + + // const commitURL = repo.commits_url + // console.log('commitURL', commitURL) + // fetch(commitURL, options) + // .then(res => res.json()) + // .then(data => { + // console.log('commits', data) + // }) + + + + + +getRepos() + + //----FETCHING ALL PULL REQUESTS----// + + +// These are the requirements for the project: + +// A list of all repos that are forked from Technigo (You completed this! Yay) +// Your username and profile picture (You completed this! Yay) +// Most recent update (push) for each repo (I understood this as the date of the last push) (You completed this! Yay) +// Name of your default branch for each repo (I understood this as the name of the repo) (You completed this! Yay) + + +// URL to the actual github repo. You can find that in your USER_REPO fetch (repoLink = repo.html_url), insert in e.g. line 84 +// Yes. for every repo which is why it should be inside the forEach loop. + +// Number of commits for each repo. You need to do a fetch for this one inside your forEach loop. The url for this is repo.git_commits_url +// ---- This will return an array with all of your commits for each repo. To get the number of commits, you can use array.length (replace array with the name of your json data) + +// Last steps: Chart.js (I don't know anything about this, just started) + +// Media Queries in CSS + +// Before I leave: + +// I'm going for blue too. No more haha. + +// If you want to see the information I included in mine, click here: +// https://github-tracker-week7.netlify.app/ +// The only thing I'm missing is the chart & media queries - so we're almost just as far as each other + +// The link to my github repo is here, if you want to read the code (if you get stuck) +// https://github.com/michaelchangdk/project-github-tracker + + + + + + + + + + + + + + + + + + +// pushDate = repo.pushed_at.substr(0, 10) + +// This section is for fun :) >>>>>> +// pushYear = pushDate.substr(0, 4) +// pushMonthRaw = pushDate.substr(5, 2) +// pushDay = pushDate.substr(8, 2) +// console.log(pushYear) +// console.log(pushDate) -getRepos() \ No newline at end of file +// if (pushDay < 10) { +// pushDay = pushDay.replace("0", "") +// } \ No newline at end of file From 58de0f3cbc6921f15f80a1299f4dc559dc4e4738 Mon Sep 17 00:00:00 2001 From: StepbyStepp <91485842+SteppbySteph@users.noreply.github.com> Date: Thu, 24 Feb 2022 16:20:47 +0100 Subject: [PATCH 05/12] changed styling all files, added chart.js, made responsive --- code/chart.js | 35 +++++++- code/index.html | 26 +++--- code/script.js | 218 ++++++++++-------------------------------------- code/style.css | 131 ++++++++++++++++++++++++++++- 4 files changed, 219 insertions(+), 191 deletions(-) diff --git a/code/chart.js b/code/chart.js index 92e85a30..e43e8646 100644 --- a/code/chart.js +++ b/code/chart.js @@ -1,4 +1,37 @@ //DOM-selector for the canvas 👇 const ctx = document.getElementById('chart').getContext('2d') -//"Draw" the chart here 👇 +// Creating a function which is invoked in js.file. +const showChart = (repos) => { + Chart.defaults.font.size = 18; + + const data = { + labels: ['Completed projects', 'Remaining projects'], + datasets: [{ + data: [repos, 19-repos], + backgroundColor: ['rgb(27, 20, 100)', 'rgb(255, 255, 0)'], + borderWidth: 2, + borderColor: 'rgb(27, 20, 100)', + hoverBorderWidth:3, + hoverBorderColor: 'rgb(27, 20, 100)', + }] + }; + + const config = { + type: 'doughnut', + data: data, + options: { + plugins: { + legend: { + display: true, + position: 'bottom', + labels: { + color: 'rgb(27, 20, 100)', + } + } + } + } + }; + + const myChart = new Chart(ctx, config); +} diff --git a/code/index.html b/code/index.html index 23310e61..55da654d 100644 --- a/code/index.html +++ b/code/index.html @@ -6,23 +6,23 @@