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
108 lines (96 loc) · 3.28 KB
/
script.js
File metadata and controls
108 lines (96 loc) · 3.28 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
107
108
// GITHUB API
const username = 'Kyparn'
const API_USER = `https://api.github.com/users/${username}`
const API_REPO = `https://api.github.com/users/${username}/repos`
const projects = document.getElementById('projects')
const personData = document.getElementById('personData')
//token
const api_Token = apiToken || process.API_KEY
const options = {
method: 'GET',
headers: {
Authorization: `${apiToken}`,
},
}
//Prints out the user info in the HTML
const getUserData = () => {
fetch(API_USER)
.then((res) => res.json())
.then((user) => {
personData.innerHTML = `
<div class="info">
<img class="img" src="${user.avatar_url}">
<h2 class="userInfo"> ${user.name}</h2>
<h2 class="userInfo">${user.location}</h2>
<h2 class="userInfo">${user.bio}</h2>
</div>`
})
}
getUserData()
// Function to fetch my repositories
const getRepos = () => {
fetch(API_REPO, options)
.then((res) => res.json())
.then((data) => {
// This function filters out my projects from technigo
const repos = data.filter(
(repo) => repo.fork && repo.name.startsWith('project-'),
)
repos.forEach((repo) => {
//Her we create a unique ID for each of my forked repos and print them in the HTML
let projectID = repo.id
projects.innerHTML += `
<div class="repoInfo" id="${projectID}">
<img src="github.png" class="repoimg" alt="logo" width="25px" />
<p class="cardInfo">Project name:
${repo.name.replace('project-', '').replace('-', ' ')}
</p>
<p class="cardInfo" id="commit-${repo.name}"></p>
<p class="cardInfo">${new Date(repo.pushed_at).toDateString()}</p>
<p class="cardInfo">Branch : ${repo.default_branch}</p>
<p class="cardInfo"$> <a href="${
repo.html_url
}" target="blank">Repository ${repo.name}</a></p>
<p class="cardInfo" id="commit-${repo.name}"></p>
<p class="cardInfo" id="pull-request-${repo.name}">
Pull requests:</p>
</div>`
// Invoking function to get the number of commits for the projects
getCommits(repo, projectID)
})
getPullRequest(repos)
drawChart(repos.length)
})
}
// This function
const getPullRequest = (repos) => {
repos.forEach((repo) => {
fetch(
`https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`,
options,
)
.then((res) => res.json())
.then((data) => {
//Filter out my pullrequests
const pulls = data.find((pull) => pull.user.login === repo.owner.login)
const myPullRequests = data.filter((pullRequest) => {
return pullRequest.user.login === username
})
document.getElementById(
`pull-request-${repo.name}`,
).innerHTML = `Pull Request: ${myPullRequests.length}`
})
})
}
// Function to get commits and print them out
const getCommits = (projects, projectID) => {
const GIT_COMMIT_API = projects.commits_url.replace('{/sha}', '')
fetch(GIT_COMMIT_API, options)
.then((res) => res.json())
.then((data) => {
let numberOfCommits = data.length
document.getElementById(projectID).innerHTML += `
<p>Number of commits: ${numberOfCommits}</p>`
})
}
getRepos()