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
85 lines (75 loc) · 2.62 KB
/
script.js
File metadata and controls
85 lines (75 loc) · 2.62 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
// DOM selectors
const projectsContainer = document.getElementById('projects')
const username = 'CamillaHallberg'
let reponame = ''
// Authentication
const API_TOKEN = TOKEN || process.env.API_KEY;
const options = {
method: 'GET',
headers: {
Authorization: `${API_TOKEN}`
}
}
// API's
const API_USER = `https://api.github.com/users/${username}`
const API_URL_REPO = `https://api.github.com/users/${username}/repos`
// Function to fetch my user data
const getUser = () => {
fetch(API_USER, options)
.then(res => res.json())
.then(user => {
userData.innerHTML = `
<div class="avatar">
<img class="img" src="${user.avatar_url}" alt="user image">
</div>
<div class="info">
<h3>${user.login}</h3>
<h4>${user.bio}</h4>
<h4>Location: ${user.location}</h4>
</div>`
})
}
getUser()
// Function to fetch my repositories
const getRepos = () => {
fetch(API_URL_REPO, options)
.then(res => res.json())
.then(data => {
// Filter to get only my forked repos from Technigo
const forkedRepos = data.filter((repo) => repo.fork && repo.name.startsWith('project-'))
forkedRepos.forEach((repo) => {
// Creating unique ID for each forked repo
let projectID = repo.id
projectsContainer.innerHTML += `
<div class="projects-card" id="${projectID}">
<h3><a href="${repo.html_url}">${repo.name}</a></h3>
<p class="default-branch">Branch: ${repo.default_branch}</p>
<p>Latest push: ${new Date(repo.pushed_at).toDateString()}</p>
</div>`
// Invoking function to get the number of commits for the projects
getCommits(repo, projectID)
})
getPullRequests(forkedRepos)
drawChart(forkedRepos.length)
})
}
const getPullRequests = (forkedRepos) => {
forkedRepos.forEach(repo => {
fetch(`https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=150`, options)
.then(res => res.json())
.then(data => {
const pulls = data.find((pull) => pull.user.login === repo.owner.login);
})
})
}
const getCommits = (projectsContainer, projectID) => {
const GIT_COMMIT_API = projectsContainer.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()