forked from Technigo/project-github-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommits.js
More file actions
72 lines (64 loc) · 2.53 KB
/
commits.js
File metadata and controls
72 lines (64 loc) · 2.53 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
const commitsSection = document.getElementById("commits");
const fetchRepositories = (repositories) => {
const myRepos = repositories.filter((repo) => repo.fork && repo.name !== "unit-tests").length;
repositories.filter(repo => {
if (repo.fork && repo.name !== "unit-tests") {
fetchCommits(repo)
}
});
displayChart(myRepos);
};
const fetchCommitMessages = (commits, repository) => {
const repositoryName = repository.name;
const newCommits = commits.filter(commits => commits.commit.author.date.includes("2022"));
document.addEventListener("click", (event) => {
if (event.target.id === repositoryName) {
const repoClassname = `.${repositoryName}`;
document.querySelectorAll(repoClassname).forEach(name => {
if (name.style.display === "none") {
name.style.display = "block";
} else {
name.style.display = "none";
}
})
};
});
commitsSection.innerHTML += `
<div class="commits__text">
<div><p><a href="${repository.html_url}/commits" target="_blank">${username}/${repositoryName}</a></p></div>
<div class="progress">
<div class="progress-bar bg-success" role="progressbar" style="width: ${newCommits.length * 3}%"
aria-valuenow="${newCommits.length}" aria-valuemin="0" aria-valuemax="100">
</div>
</div>
<div>
<button type="button" id=${repositoryName} class="btn btn-secondary btn-sm dropdown-toggle"
data-bs-toggle="dropdown" aria-expanded="false">${newCommits.length} commits
</button>
</div>
</div>
`
for (let i = 0; i < newCommits.length; i++) {
const { message, committer, author } = newCommits[i].commit;
const { avatar_url } = newCommits[i].author;
const date = new Date(committer.date);
const formattedDate = date.toDateString().split(' ').slice(1).join(' ');
commitsSection.innerHTML += `
<div id="messageWrapper" class=${repositoryName} style="display: none">
<p class="text">${message}</p>
<p class="subtext"><img class="icons circle" src=${avatar_url} alt=${author.name}>
<span class="bold-text">${author.name} </span> <span class="hide-text">committed on ${formattedDate}</span></p>
</div>
`
}
};
fetch(REPOS_URL, options)
.then(res => res.json())
.then(data => fetchRepositories(data))
.catch(error => console.log(error))
const fetchCommits = (repo) => {
fetch(`${COMMITS_URL}${repo.name}/commits`, options)
.then(res => res.json())
.then(data => fetchCommitMessages(data, repo))
.catch(error => console.log(error))
};