|
| 1 | +const REPOS_URL = "https://api.github.com/users/themisk84/repos"; |
| 2 | +const NEWS_SITE_COMMITS = |
| 3 | + "https://api.github.com/repos/Technigo/project-news-site/pulls/214/commits"; |
| 4 | +const projects = document.getElementById("projects"); |
| 5 | +const profileImage = document.getElementById("profileImage"); |
| 6 | +const userName = document.getElementById("userName"); |
| 7 | + |
| 8 | +// const forkedRepos = (data) => { |
| 9 | +// const Reposforked = data.filter( |
| 10 | +// (repo) => repo.fork && repo.name.startsWith("project") |
| 11 | +// ); |
| 12 | +// Reposforked.forEach( |
| 13 | +// (repo) => |
| 14 | +// (projects.innerHTML += `<div class="repo" id="${repo.name}"> |
| 15 | +// <h3><a href="${repo.html_url}" target="_blank">${repo.name}</a></h3> |
| 16 | +// </div>`) |
| 17 | +// ); |
| 18 | +// }; |
| 19 | + |
| 20 | +const getRepos = () => { |
| 21 | + fetch(REPOS_URL) |
| 22 | + .then((response) => response.json()) |
| 23 | + .then((data) => { |
| 24 | + console.log(data); |
| 25 | + |
| 26 | + const forkedRepos = data.filter( |
| 27 | + (repo) => repo.fork && repo.name.startsWith("project") |
| 28 | + ); |
| 29 | + forkedRepos.forEach( |
| 30 | + (repo) => |
| 31 | + (projects.innerHTML += `<div class="repo" id="${repo.name}"> |
| 32 | + <h3><a href="${repo.html_url}" target="_blank">${ |
| 33 | + repo.name |
| 34 | + }</a></h3> |
| 35 | + <h4>${repo.default_branch}</h4> |
| 36 | + <ha>Last updated: ${new Date( |
| 37 | + repo.updated_at |
| 38 | + ).toLocaleString()}</h4> |
| 39 | + </div>`) |
| 40 | + ); |
| 41 | + const profileImg = data.forEach( |
| 42 | + (profile) => (profileImage.src = profile.owner.avatar_url) |
| 43 | + ); |
| 44 | + const profileName = data.forEach( |
| 45 | + (nickname) => (userName.innerHTML = nickname.owner.login) |
| 46 | + ); |
| 47 | + getPullRequest(forkedRepos); |
| 48 | + }); |
| 49 | +}; |
| 50 | + |
| 51 | +const getPullRequest = (forkedRepos) => { |
| 52 | + forkedRepos.forEach((repo) => { |
| 53 | + fetch( |
| 54 | + `https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=100` |
| 55 | + ) |
| 56 | + .then((response) => response.json()) |
| 57 | + .then((data) => { |
| 58 | + // console.log(data); |
| 59 | + const myPulls = data.filter( |
| 60 | + (pulls) => pulls.user.login === repo.owner.login |
| 61 | + ); |
| 62 | + console.log(myPulls); |
| 63 | + const commitsURL = myPulls[0].commits_url; |
| 64 | + // console.log(commitsURL); |
| 65 | + getCommits(commitsURL, repo); |
| 66 | + |
| 67 | + // const myComments = |
| 68 | + }); |
| 69 | + }); |
| 70 | +}; |
| 71 | + |
| 72 | +const getCommits = (commitsURL, repo) => { |
| 73 | + fetch(commitsURL) |
| 74 | + .then((response) => response.json()) |
| 75 | + .then((data) => { |
| 76 | + // console.log(data.length); |
| 77 | + document.getElementById( |
| 78 | + `${repo.name}` |
| 79 | + ).innerHTML += `<h4> Number of commits: ${data.length}</h4>`; |
| 80 | + }); |
| 81 | +}; |
| 82 | + |
| 83 | +getRepos(); |
0 commit comments