|
1 | | -const GITHUB_URL = "https://api.github.com/users/efstasia/repos"; |
| 1 | +const USER = "efstasia"; |
| 2 | +const GITHUB_URL = `https://api.github.com/users/${USER}/repos`; |
| 3 | +const projectsContainer = document.getElementById("projects"); |
| 4 | +const pullContainer = document.getElementById("pull-requests"); |
| 5 | +const profileInfo = document.getElementById("profile"); |
2 | 6 |
|
3 | | -fetch(GITHUB_URL) |
4 | | - .then((response) => { |
5 | | - return response.json(); |
6 | | - }) |
7 | | - .then((json) => { |
8 | | - console.log(json); |
9 | | - }); |
| 7 | +// function to get profile picture and name |
| 8 | +const profile = () => { |
| 9 | + fetch(`https://api.github.com/users/${USER}`) |
| 10 | + .then(response => { |
| 11 | + return response.json(); |
| 12 | + }) |
| 13 | + .then(json => { |
| 14 | + profileInfo.innerHTML += ` |
| 15 | + <h3>Username: ${json.login}</h3> |
| 16 | + <img src=${json.avatar_url}> |
| 17 | + `; |
| 18 | + }); |
| 19 | +}; |
| 20 | +profile(); // invoking the profile function |
10 | 21 |
|
11 | | -// const getPullRequests = (repos) => { |
12 | | -// //Get all the PRs for each project. |
13 | | -// repos.forEach((repo) => { |
14 | | -// fetch(GITHUB_URL) |
15 | | -// .then((res) => res.json()) |
16 | | -// .then((data) => { |
17 | | -// console.log(data); |
18 | | -// //TODO |
19 | | -// //1. Find only the PR that you made by comparing pull.user.login |
20 | | -// // with either USER or repo.owner.login |
21 | | -// //2. Now you're able to get the commits for each repo by using |
22 | | -// // the commits_url as an argument to call another function |
23 | | -// //3. You can also get the comments for each PR by calling |
24 | | -// // another function with the review_comments_url as argument |
| 22 | +// function to get all of the repos and commits |
| 23 | +const getRepos = () => { |
| 24 | + fetch(GITHUB_URL) |
| 25 | + .then(response => { |
| 26 | + return response.json(); |
| 27 | + }) |
| 28 | + .then(json => { |
| 29 | + console.log(json); |
| 30 | + const forkedRepos = json.filter( |
| 31 | + repo => repo.fork && repo.name.startsWith("project-") |
| 32 | + ); |
| 33 | + forkedRepos.forEach( |
| 34 | + repo => |
| 35 | + (projectsContainer.innerHTML += `<h3>Name of repo: ${repo.name}</h3> |
| 36 | + <p>Most recent push: ${repo.pushed_at.slice( |
| 37 | + 0, |
| 38 | + 10 |
| 39 | + )} at ${repo.pushed_at.slice(11, 16)} from ${ |
| 40 | + repo.default_branch |
| 41 | + } branch</p> |
| 42 | + URL: <a href=${repo.html_url}>CLICK HERE</a>`) |
| 43 | + ); |
| 44 | + drawChart(forkedRepos.length); |
| 45 | + }); |
| 46 | +}; |
| 47 | +getRepos(); // invoking the function |
| 48 | + |
| 49 | +// this gets the repos |
| 50 | +// const getPullRequests = repos => { |
| 51 | +// repos.forEach(repo => { |
| 52 | +// fetch(`https://api.github.com/repos/technigo/${repo.name}/pulls`) |
| 53 | +// .then(response => response.json()) |
| 54 | +// .then(json => { |
| 55 | +// console.log(json); |
| 56 | + |
| 57 | +// const filterPulls = json.filter(pull => |
| 58 | +// pull.user.login.includes("efstasia") |
| 59 | +// ); |
| 60 | +// console.log("FILTER PULLS", filterPulls); |
| 61 | +// filterPulls.forEach( |
| 62 | +// repo => |
| 63 | +// (pullContainer.innerHTML += `<h3>halloj vart är dom andra?? ${repo.name} ${repo.html_url}</h3>`) |
| 64 | +// ); |
25 | 65 | // }); |
26 | 66 | // }); |
27 | 67 | // }; |
0 commit comments