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
109 lines (98 loc) · 4.31 KB
/
script.js
File metadata and controls
109 lines (98 loc) · 4.31 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
97
98
99
100
101
102
103
104
105
106
const USER = 'dandeloid'
const REPOS_URL = `https://api.github.com/users/${USER}/repos`
const profileContainer = document.getElementById('profile')
const projectsContainer = document.getElementById('projects')
const pullContainer = document.getElementById('pullRequests')
//Fetch for profile name and profile picture
const getProfile = () => {
fetch (`https://api.github.com/users/${USER}`)
.then(response => response.json())
.then(data => {
profileContainer.innerHTML = `
<img class="profile-picture" src=${data.avatar_url}>
<div class = "profile-name">
<img class="github-icon" src="./github-icon-black.svg">
<a href="https://github.com/dandeloid" target="_blank" class="profile-title">${data.login}</a>
</div>
<p class="bio">"${data.bio}"</p>
<p class="location">Location - ${data.location}</p>
`
})
}
getProfile()
//Fetch for Technigo forked repos
const getRepos = () => {
fetch (REPOS_URL)
.then(response => response.json())
.then(data => {
const forkedRepos = data.filter(repo => repo.fork && repo.name.startsWith('project-'))
forkedRepos.forEach((repo) => {
projectsContainer.innerHTML += `
<div class="single-project">
<a href="${repo.html_url}" class="repo-name" target="_blank" style="text-transform: capitalize;">${repo.name}</a>
<p style="text-transform: capitalize;">Branch: ${repo.default_branch}</p>
<p class="last-push">Last push: ${repo.pushed_at.slice(0, 10)} - ${repo.pushed_at.slice(11, 16)}</p>
<p class="commit-text" id="commit-${repo.name}">Commits: </p>
<p class="comment-title"">Last comments: </p>
<p class="comment-text" id="comment1-${repo.name}"> </p>
<p class="comment-text" id="comment2-${repo.name}"> </p>
<p class="comment-text" id="comment3-${repo.name}"> </p>
</div>
`
})
drawChart(forkedRepos.length)
fetchPulls(forkedRepos)
commitComments(forkedRepos)
})
}
//Fetch pull request
const fetchPulls = (allRepositories) => {
allRepositories.forEach((repo) => {
const PULL_URL = `https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`
fetch(PULL_URL)
.then((response) => response.json())
.then((data) => {
const myPullRequest = data.find(pull => pull.user.login === repo.owner.login)
if (myPullRequest){
fetchCommits(myPullRequest.commits_url, repo.name)
} else {
document.getElementById(`commit-${repo.name}`).innerHTML = 'Commits: 0'
}
})
})
}
//Fetch nr of commits
const fetchCommits = (myCommitsUrl, RepoName) => {
fetch(myCommitsUrl)
.then((response) => response.json())
.then((data) => {
document.getElementById(`commit-${RepoName}`).innerHTML += data.length
})
}
//Fetch last commit messages
const commitComments = (forkedRepos) => {
forkedRepos.forEach((repo) => {
const COM_URL = `https://api.github.com/repos/dandeloid/${repo.name}/commits`
fetch(COM_URL)
.then((response) => response.json())
.then((data) => {
if (data[0].author.login === 'dandeloid'){
const commitDate1 = new Date (data[0].commit.committer.date).toDateString()
document.getElementById(`comment1-${repo.name}`).innerHTML += `${commitDate1}: "${data[0].commit.message}"`
}
if (data[1].author.login === 'dandeloid'){
const commitDate2 = new Date (data[1].commit.committer.date).toDateString()
document.getElementById(`comment2-${repo.name}`).innerHTML += `${commitDate2}: "${data[1].commit.message}"`
}
if (data[2].author.login === 'dandeloid'){
const commitDate3 = new Date (data[2].commit.committer.date).toDateString()
document.getElementById(`comment3-${repo.name}`).innerHTML += `${commitDate3}: "${data[2].commit.message}"`
}
else{
document.getElementById(`comment1-${repo.name}`).innerHTML += `No comments atm`
}
})
})
}
//Start fetching repository data
getRepos()