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
102 lines (85 loc) · 3.03 KB
/
script.js
File metadata and controls
102 lines (85 loc) · 3.03 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
// DOM SELECTORS
const projectsContainer = document.getElementById('projects')
const header = document.getElementById('header')
const profile = document.getElementById('profile')
// GLOBAL VARIABLES
const username = 'joannalodell19'
let filteredRepo = [] // Probably not needed
// let reponame = ''
const API_URL = `https://api.github.com/users/${username}/repos`
const API_PROFILE = `https://api.github.com/users/${username}`
const API_TOKEN = TOKEN || process.env.API_KEY;
const options = {
method: 'GET',
headers: {
Authorization: `token ${API_TOKEN}`
}
}
const profilePic = () => {
fetch(API_PROFILE)
.then(res => res.json())
.then(data => {
// console.log(data)
picture = data.avatar_url
let profilePicture = `<div class = "photobox">
<img class = "photo" src="${picture}" />
<p>${username}</p>
</div>`;
return (profile.innerHTML += profilePicture)
})
}
profilePic()
const getRepos = () => {
fetch(API_URL)
.then(res => res.json())
.then(data => {
// console.log('unfiltered data', data)
const forkedRepos = data.filter(repo => repo.fork = true)
// console.log('data filtered by forks', forkedRepos)
const filteredRepo = forkedRepos.filter(repo => repo.name.startsWith('project-') === true)
// console.log('data filtered on projects', filteredRepo)
filteredRepo.forEach(repo => {
// console.log(repo.commits_url)
projectsContainer.innerHTML += `
<div class="repo" id=${repo.name}>
<a href="${repo.html_url}"><h3>${repo.name}</h3></a>
<p> Default branch: ${repo.default_branch}</p>
<p> Recent push: ${new Date(repo.pushed_at).toDateString()}</p>
<p id='commit-${repo.name}'> Number of commits: </p>
</div>
`
})
getPullRequests(filteredRepo);
drawChart(filteredRepo.length)
})
}
getRepos()
// Pull requests for each project
const getPullRequests = (repos) => {
repos.forEach((repo) => {
const PULLREQUEST_URL = `https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`;
fetch(PULLREQUEST_URL, options)
.then((res) => res.json())
.then((pull) => {
const myPullRequest = pull.find(
(pull) => pull.user.login === repo.owner.login
);
// If pull request done by user, getCommits function is invoked
if (myPullRequest) {
getCommits(myPullRequest.commits_url, repo.name);
} else {
document.getElementById(`commit-${repo.name}`).innerHTML =
"No pull request done by user";
}
});
});
};
const getCommits = (myCommitsUrl, myRepoName) => {
fetch(myCommitsUrl)
.then((res) => res.json())
.then((commit) => {
document.getElementById(`commit-${myRepoName}`).innerHTML +=
commit.length;
});
};
//myChart();