|
1 | 1 | // main fetch and function and put the DOM here |
2 | | -const projectsContainer = document.getElementById('projects') |
3 | | -const headerContainer = document.getElementById('header') |
4 | | -const USER = 'DALA746' |
5 | | -const ALL_MY_REPOS = `https://api.github.com/users/${USER}/repos` |
| 2 | +const projectsContainer = document.getElementById('projects'); |
| 3 | +const headerContainer = document.getElementById('header'); |
| 4 | +const USER = 'DALA746'; |
| 5 | +const ALL_MY_REPOS = `https://api.github.com/users/${USER}/repos`; |
6 | 6 |
|
7 | | -const button = document.getElementById('button') |
| 7 | +const button = document.getElementById('button'); |
8 | 8 |
|
9 | | -const getRepos = () => { |
10 | | - fetch(ALL_MY_REPOS) |
11 | | - .then(res => res.json()) |
12 | | - .then((json) => { |
13 | | - console.log(json) // This json shows all of my repos on GitHub |
14 | | - // filter repos so I can only get tehcnigos repos |
15 | | - const forkedRepos = json.filter(repo => repo.fork && repo.name.startsWith('project-')) // or you can use includes method |
16 | | - drawChart(forkedRepos.length) |
| 9 | +const searchProject = () => { |
| 10 | + let input = document.getElementById('searchbar').value; |
| 11 | + input = input.toLowerCase(); |
| 12 | + let repo = document.getElementsByClassName('repo'); |
17 | 13 |
|
18 | | - forkedRepos.forEach((repo) => { |
19 | | - // header container |
20 | | - headerContainer.innerHTML = ` |
21 | | - <div class="info-about-user"> |
22 | | - <img class="profile-img"src="${repo.owner.avatar_url}" /> |
23 | | - <h2>Darya Lapata</h2> |
24 | | - <h3>${repo.owner.login}</h3> |
25 | | - <p>Location: Stockholm</p> |
26 | | - </div> |
27 | | - ` |
28 | | - // project container |
29 | | - projectsContainer.innerHTML += ` |
30 | | - <div class="repo"> |
31 | | - <a href="${repo.clone_url }" target="_blank"><h3>${repo.name}</h3> </a> |
32 | | - <p id="commit-${repo.name}">Commits amount: </p> |
33 | | - <p>Latest push update: ${ new Date(repo.pushed_at).toDateString()}</p> |
34 | | - <p>Default branch: ${repo.default_branch}</p> |
35 | | - </div> |
36 | | - ` |
37 | | - }) |
38 | | - getPullRequests(forkedRepos) // passing all my forked repos to this function |
39 | | - }) |
40 | | -} |
41 | | -// calling getRepos function |
42 | | -getRepos() |
| 14 | + for (i = 0; i < repo.length; i++) { |
| 15 | + if (!repo[i].innerHTML.toLowerCase().includes(input)) { |
| 16 | + repo[i].style.display = 'none'; |
| 17 | + } else { |
| 18 | + repo[i].style.display = 'block'; |
| 19 | + } |
| 20 | + } |
| 21 | +}; |
43 | 22 |
|
44 | | -// GETTING ALL MY PULL REQUESTS |
45 | | -const getPullRequests = (forkedRepos) => { // repos är samma som forkedRepos |
46 | | - forkedRepos.forEach(repo => { |
47 | | - // console.log(repo) // alla mina forked pull requests |
48 | | - fetch(`https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`) // getting all pullrequest to the specific project |
49 | | - .then(res => res.json()) |
50 | | - .then(data => { |
51 | | - const myPullRequests = data.find(pull => pull.user.login === repo.owner.login) // there is a different between filter and find function, with find you get a sandwich with a name on |
52 | | - getCommits(myPullRequests.commits_url, repo.name) // link |
53 | | - }) |
54 | | - }) |
55 | | -} |
| 23 | +const renderHTML = (repos) => { |
| 24 | + console.log(repos); |
| 25 | + repos.forEach((repo) => { |
| 26 | + headerContainer.innerHTML = ` |
| 27 | + <div class="info-about-user"> |
| 28 | + <img class="profile-img"src="${repo.owner.avatar_url}" /> |
| 29 | + </div> |
| 30 | + <h3>${repo.owner.login}</h3> |
| 31 | + <div>SOME STATS</div> |
56 | 32 |
|
57 | | -const getCommits = (url, myRepoName) => { |
58 | | -// fetching url for commits |
59 | | - fetch(url) |
60 | | - .then(res => res.json()) |
61 | | - .then(data => { |
62 | | - const numberOfCommits = data.length |
63 | | - document.getElementById(`commit-${myRepoName}`).innerHTML += numberOfCommits |
64 | | - }) |
65 | | -} |
| 33 | + `; |
| 34 | + projectsContainer.innerHTML += ` |
| 35 | + <div class="repo"> |
| 36 | + <a href="${ |
| 37 | + repo.clone_url |
| 38 | + }" target="_blank"><div class="icon-container"><i class="fal fa-book" style="font-size:25px;color:var(--grey);"></i><h3>${ |
| 39 | + repo.name |
| 40 | + }</h3></div> </a> |
| 41 | + <p id="commit-${repo.name}"><span class="bold">Commits amount: </span></p> |
| 42 | + <p><span class="bold">Language:</span> ${repo.language}</p> |
| 43 | + <p><span class="bold">Latest push update:</span> ${new Date( |
| 44 | + repo.pushed_at |
| 45 | + ).toDateString()}</p> |
| 46 | + <p><span class="bold">Default branch:</span> ${repo.default_branch}</p> |
| 47 | + </div> |
| 48 | + `; |
| 49 | + }); |
| 50 | +}; |
66 | 51 |
|
| 52 | +const getRepos = () => { |
| 53 | + fetch(ALL_MY_REPOS) |
| 54 | + .then((res) => res.json()) |
| 55 | + .then((json) => { |
| 56 | + console.log(json); |
| 57 | + const forkedRepos = json.filter( |
| 58 | + (repo) => repo.fork && repo.name.startsWith('project-') |
| 59 | + ); |
| 60 | + drawChart(forkedRepos.length); |
| 61 | + renderHTML(forkedRepos); |
| 62 | + // getPullRequests(forkedRepos); |
| 63 | + }); |
| 64 | +}; |
67 | 65 |
|
| 66 | +getRepos(); |
68 | 67 |
|
| 68 | +// GETTING ALL MY PULL REQUESTS |
| 69 | +// const getPullRequests = (forkedRepos) => { |
| 70 | +// forkedRepos.forEach((repo) => { |
| 71 | +// fetch(`https://api.github.com/repos/Technigo/${repo.name}/pulls`) |
| 72 | +// .then((res) => res.json()) |
| 73 | +// .then((data) => { |
| 74 | +// console.log(data); |
| 75 | +// const myPullRequests = data.find( |
| 76 | +// (pull) => pull.user.login === repo.owner.login |
| 77 | +// ); |
| 78 | +// console.log(myPullRequests, 'data'); |
| 79 | +// getCommits(myPullRequests.commits_url, repo.name); |
| 80 | +// }); |
| 81 | +// }); |
| 82 | +// }; |
69 | 83 |
|
| 84 | +const getCommits = (url, myRepoName) => { |
| 85 | + fetch(url) |
| 86 | + .then((res) => res.json()) |
| 87 | + .then((data) => { |
| 88 | + const numberOfCommits = data.length; |
| 89 | + document.getElementById(`commit-${myRepoName}`).innerHTML += |
| 90 | + numberOfCommits; |
| 91 | + }); |
| 92 | +}; |
70 | 93 |
|
| 94 | +button.addEventListener('click', (e) => { |
| 95 | + e.preventDefault(); |
| 96 | + searchProject(); |
| 97 | +}); |
0 commit comments