forked from Technigo/project-github-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
96 lines (89 loc) · 3.13 KB
/
script.js
File metadata and controls
96 lines (89 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const USER = "Lundgreneddie";
const GITHUB_URL = `https://api.github.com/users/${USER}/repos`;
const COMMIT_URL = `https://api.github.com/repos/Lundgreneddie/project-news-site/commits`;
const projectsContainer = document.getElementById("projects");
const pullContainer = document.getElementById("pull-requests");
const profileInfo = document.getElementById("profile");
// function to get profile picture and name
const profile = () => {
fetch(`https://api.github.com/users/${USER}`)
.then(response => {
return response.json();
})
.then(json => {
profileInfo.innerHTML += `
<img src=${json.avatar_url}>
<a class="username-link" href="https://github.com/Lundgreneddie">
<h3 class="username"><i class="fab fa-github"></i>
${json.login}</a></h3>
<p class="repo-amount">This account has a total of ${json.public_repos} repos</p>
`;
});
};
profile(); // invoking the profile function
//
// function to get all of the repos and commits
const getRepos = () => {
fetch(GITHUB_URL)
.then(response => {
return response.json();
})
.then(json => {
// this filters out ONLY the forked projects from technigo
const forkedRepos = json.filter(
repo => repo.fork && repo.name.startsWith("project-")
);
// this creates a forEach function to get all of the projects
forkedRepos.forEach(
repo =>
(projectsContainer.innerHTML += `
<div class="repo-items">
<a class="links" href=${repo.html_url}>${repo.name}</a>
<p><span class="push-title">Most recent push</span>
${new Date(repo.pushed_at).toDateString()} at ${repo.pushed_at.slice(
11,
16
)}</p>
<p class="branch">${repo.default_branch}</p>
<p id="commit-${repo.name}">Number of commits: </p>
</div>`)
);
fetchPullRequestsArray(forkedRepos);
drawChart(forkedRepos.length);
});
};
// this fetches all of the pull requests and commit made to those
const fetchPullRequestsArray = allRepositories => {
allRepositories.forEach(repo => {
const PULL_URL = `https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`;
fetch(PULL_URL)
.then(res => res.json())
.then(json => {
const myPullRequest = json.find(
pull => pull.user.login === repo.owner.login
);
// Detect if we have pull request or not.
// If yes - call fetchCommits function
// If no - inform user that no pull request was yet done
if (myPullRequest) {
fetchCommits(myPullRequest.commits_url, repo.name);
} else {
document.getElementById(`commit-${repo.name}`).innerHTML =
"No pull requests done";
}
});
});
};
const fetchCommits = (myCommitsUrl, myRepoName) => {
fetch(myCommitsUrl)
.then(res => res.json())
.then(json => {
document.getElementById(`commit-${myRepoName}`).innerHTML += json.length;
});
};
getRepos(); // invoking the function
// function to toggle the dark mode
const myFunction = () => {
const element = document.body;
element.classList.toggle("dark-mode");
};