|
1 | 1 | const USER = "waliem" |
2 | | -const REPOS_URL = `https://api.github.com/users/waliem/repos` |
| 2 | +const REPOS_URL = `https://api.github.com/users/${USER}/repos` |
| 3 | +const USER_INFO_URL = `https://api.github.com/users/${USER}` |
| 4 | +// let repoName = repo.name |
3 | 5 |
|
4 | 6 | const projectsContainer = document.getElementById("projects") |
| 7 | +const userContainer = document.getElementById("user-info") |
| 8 | + |
| 9 | +const getUserInfo = () => { |
| 10 | + fetch(USER_INFO_URL) |
| 11 | + .then((response) => response.json()) |
| 12 | + .then((data) => { |
| 13 | + console.log("USER DATA HERE", data) |
| 14 | + userContainer.html += `<h2>User name: ${data.name}</h2> |
| 15 | + <img src="https://avatars.githubusercontent.com/u/84201089?v=4" alt="User profile picture">` |
| 16 | + }) |
| 17 | +} |
5 | 18 |
|
6 | 19 | const getRepos = () => { |
7 | 20 | fetch(REPOS_URL) |
8 | 21 | .then((response) => response.json()) |
9 | 22 | .then((data) => { |
10 | 23 | console.log(data) |
11 | | - // data.forEach((repo) => console.log(repo.name)) |
12 | | - const forkedRepos = data.filter( |
| 24 | + let forkedRepos = data.filter( |
13 | 25 | (repo) => repo.fork && repo.name.startsWith("project-") |
14 | 26 | ) |
15 | 27 | forkedRepos.forEach( |
16 | 28 | (repo) => (projectsContainer.innerHTML += `<h3>${repo.name}</h3>`) |
17 | 29 | ) |
18 | 30 | drawChart(forkedRepos.length) |
| 31 | + getPullRequests(forkedRepos) |
19 | 32 | }) |
20 | 33 | } |
21 | 34 |
|
| 35 | +//Remember to pass along your filtered repos as an argument when |
| 36 | +//you are calling this function |
| 37 | + |
| 38 | +const getPullRequests = (forkedRepos) => { |
| 39 | + forkedRepos.forEach((repo) => { |
| 40 | + fetch( |
| 41 | + `https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=100` |
| 42 | + ) |
| 43 | + .then((res) => res.json()) |
| 44 | + .then((data) => { |
| 45 | + const myPr = data.filter((pull) => pull.user.login === repo.owner.login) |
| 46 | + console.log("MY PRs", myPr) |
| 47 | + |
| 48 | + fetch(`https://api.github.com/repos/${USER}/${repo.name}/commits`) |
| 49 | + .then((res) => res.json()) |
| 50 | + .then((data) => { |
| 51 | + console.log(data) |
| 52 | + const filterCommits = data.filter( |
| 53 | + (repo = repo.commit.committer.name === "Emelie") |
| 54 | + ) |
| 55 | + }) |
| 56 | + |
| 57 | + //2. Now you're able to get the commits for each repo by using |
| 58 | + // the commits_url as an argument to call another function |
| 59 | + //3. You can also get the comments for each PR by calling |
| 60 | + // another function with the review_comments_url as argument |
| 61 | + }) |
| 62 | + }) |
| 63 | +} |
| 64 | +getUserInfo() |
22 | 65 | getRepos() |
0 commit comments