Skip to content

Commit 12d3643

Browse files
fetched pRs
1 parent 9513102 commit 12d3643

File tree

3 files changed

+60
-16
lines changed

3 files changed

+60
-16
lines changed

code/chart.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const config = {
88
labels: ["Finished projects", "Projects left"],
99
datasets: [
1010
{
11-
label: "My First Dataset",
12-
data: [6, 20 - 6],
13-
backgroundColor: ["rgb(255, 99, 132)", "rgb(54, 162, 235)"],
11+
label: "My Projects",
12+
data: [6, 19 - 6],
13+
backgroundColor: ["rgb(55, 99, 132)", "rgb(80, 92, 125)"],
1414
hoverOffset: 4,
1515
},
1616
],

code/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
</head>
1010
<body>
1111
<h1>GitHub Tracker</h1>
12-
<h2>Projects</h2>
13-
<main id="projects"></main>
12+
<section id="userProfile" class="user-profile"></section>
13+
<main id="projects" class="projects"></main>
1414

1515
<!-- This will be used to draw the chart 👇 -->
1616
<canvas id="chart"></canvas>

code/script.js

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,67 @@
11
const projects = document.getElementById("projects");
2+
const userProfile = document.getElementById("userProfile");
23
const chart = document.getElementById("chart");
4+
const user_URL = "https://api.github.com/users/Sherin-Susan-Thomas";
35
const repo_URL = "https://api.github.com/users/Sherin-Susan-Thomas/repos";
46

57
const options = {
68
method: "GET",
79
headers: {
8-
Authorization: ` ${API_TOKEN}`,
10+
Authorization: `token ${API_TOKEN}`,
911
},
1012
};
1113

12-
fetch(repo_URL, options)
13-
.then((res) => res.json())
14-
.then((userData) => {
15-
console.log("userData", userData);
16-
const filteredRepos = userData.filter(
17-
(item) => item.fork && item.name.includes("project-")
18-
);
19-
filteredRepos.forEach((repo) => {
20-
projects.innerHTML += `<h2 class = "repo-name" id = "repoName"> ${repo.name} </h2>`;
14+
//To fetch profile data
15+
const user = () => {
16+
fetch(user_URL, options)
17+
.then((res) => res.json())
18+
.then((data) => {
19+
console.log("data", data);
20+
userProfile.innerHTML += `<h2 class = "user-name" id= "userName"> ${data.name} </h2>
21+
<img src = ${data.avatar_url}>`;
2122
});
22-
console.log("filteredRepos", filteredRepos);
23+
};
24+
user();
25+
26+
// To fetch repositories
27+
const userRepo = () => {
28+
fetch(repo_URL, options)
29+
.then((res) => res.json())
30+
.then((userData) => {
31+
console.log("userData", userData);
32+
const filteredRepos = userData.filter(
33+
(item) => item.fork && item.name.includes("project-") // to filter technigo projects
34+
);
35+
filteredRepos.forEach((repo) => {
36+
const date = new Date(repo.pushed_at).toDateString();
37+
projects.innerHTML += `<h2 class = "repo-name" id= "repoName"> ${repo.name} </h2>
38+
<a href="${repo.html_url}">Link to the repository</a>
39+
<p class = "repo-name" id= "repoName"> Default Branch: ${repo.default_branch} </p>
40+
<p class = "repo-name" id= "repoName"> Latest Push update: ${date} </p>
41+
`;
42+
});
43+
console.log("filteredRepos", filteredRepos);
44+
pullRequests(filteredRepos);
45+
myChart(filteredRepos.length);
46+
});
47+
};
48+
49+
const pullRequests = (repos) => {
50+
repos.forEach((repo) => {
51+
console.log("repo", repo);
52+
fetch(
53+
`https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`,
54+
options
55+
) // to filter pull requests
56+
.then((res) => res.json())
57+
.then((data) => {
58+
console.log("data", data);
59+
const myPullRequest = data.find(
60+
(pull) => pull.user.login === repo.owner.login
61+
); // pullrequests fetches the entire pullrequest specfic to the projecr, filtering out pull requests made by me.
62+
console.log("myPullRequest", myPullRequest);
63+
});
2364
});
65+
};
66+
67+
userRepo();

0 commit comments

Comments
 (0)