|
1 | 1 | const projects = document.getElementById("projects"); |
| 2 | +const userProfile = document.getElementById("userProfile"); |
2 | 3 | const chart = document.getElementById("chart"); |
| 4 | +const user_URL = "https://api.github.com/users/Sherin-Susan-Thomas"; |
3 | 5 | const repo_URL = "https://api.github.com/users/Sherin-Susan-Thomas/repos"; |
4 | 6 |
|
5 | 7 | const options = { |
6 | 8 | method: "GET", |
7 | 9 | headers: { |
8 | | - Authorization: ` ${API_TOKEN}`, |
| 10 | + Authorization: `token ${API_TOKEN}`, |
9 | 11 | }, |
10 | 12 | }; |
11 | 13 |
|
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}>`; |
21 | 22 | }); |
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 | + }); |
23 | 64 | }); |
| 65 | +}; |
| 66 | + |
| 67 | +userRepo(); |
0 commit comments