Skip to content

Commit ccbd122

Browse files
EmelieEmelie
authored andcommitted
added getUserInfo and getPullRequest fetches and functions working on making them fetch the correct data
1 parent 3c50607 commit ccbd122

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

code/chart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const drawChart = (amount) => {
1111
datasets: [
1212
{
1313
label: "My First Dataset",
14-
data: [amount, 20 - 4],
14+
data: [amount, 20 - 6],
1515
backgroundColor: [
1616
"rgb(255, 99, 132)",
1717
"rgb(54, 162, 235)",

code/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ <h1>GitHub Tracker</h1>
1313
<h2>Projects:</h2>
1414
<main id="projects"></main>
1515

16+
<section id="user-info"></section>
17+
1618
<!-- This will be used to draw the chart 👇 -->
1719
<div><canvas id="chart"></canvas></div>
1820

code/script.js

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,65 @@
11
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
35

46
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+
}
518

619
const getRepos = () => {
720
fetch(REPOS_URL)
821
.then((response) => response.json())
922
.then((data) => {
1023
console.log(data)
11-
// data.forEach((repo) => console.log(repo.name))
12-
const forkedRepos = data.filter(
24+
let forkedRepos = data.filter(
1325
(repo) => repo.fork && repo.name.startsWith("project-")
1426
)
1527
forkedRepos.forEach(
1628
(repo) => (projectsContainer.innerHTML += `<h3>${repo.name}</h3>`)
1729
)
1830
drawChart(forkedRepos.length)
31+
getPullRequests(forkedRepos)
1932
})
2033
}
2134

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()
2265
getRepos()

0 commit comments

Comments
 (0)