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
143 lines (88 loc) · 3.1 KB
/
script.js
File metadata and controls
143 lines (88 loc) · 3.1 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
const personalInfo = document.getElementById('personalInfo');
const projectsContainer=document.getElementById('projects');
const USER='jessicatf';
const USER_URL = `https://api.github.com/users/${USER}`;
const REPOS_URL = `https://api.github.com/users/${USER}/repos`;
//User data
const getUserData = () => {
fetch(USER_URL)
.then((response) => response.json())
.then((data) => {
personalInfo.innerHTML = `
<div class="personal-info">
<img class="img" src="${data.avatar_url}">
<h2 class="info"> ${data.login}</h2>
</div
`
})
}
//get repositories from Technigo starting with "project"
const fetchRepositories = () => {
fetch(REPOS_URL)
.then ((res)=>res.json())
.then((data) => {
const technigoRepositories = data.filter(
(repo) => repo.name.includes('project-')&& repo.fork
);
drawChart(technigoRepositories.length)
technigoRepositories.forEach(repo=>{
projectsContainer.innerHTML += `
<div class="commits-row">
<a href="${repo.html_url}">
<h6>${repo.name} </h6></a>
<p>Default branch: ${repo.default_branch}</p>
<p>Recent push: ${new Date(repo.pushed_at).toDateString(
)}</p>
<p id="commit-${repo.name}">Commits amount: </p>
</div>
`;
});
fetchPullRequestsArray(technigoRepositories);
});
};
const fetchPullRequestsArray = (allRepositories) => {
allRepositories.forEach((repo) => {
const PULL_URL=`https://api.github.com/repos/Technigo/${repo.name}/pulls?per_page=100`
fetch(PULL_URL)
.then((res) => res.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 =
'No pull request or commits done.';
}
});
});
};
const fetchCommits = (myCommitsUrl,myRepoName) => {
fetch(myCommitsUrl)
.then((res)=>res.json())
.then((data)=> {
document.getElementById(`commit-${myRepoName}`).innerHTML+=data.length;
});
};
fetchRepositories();
getUserData();
/*Jennie
const projectsContainer=document.getElementById('projects')
const repoName= document.getElementById(repoName)
//Jennies
const getRepos = () => {
fetch(REPOS_URL,options)
.then(response =>response.json())
.then(data => {
console.log(data)
const repoName=data.forEach(repo => console.log(repo.name))
const forkedRepos = data.filter(repo =>
repo.fork && repo.name.startsWith('project-'))
forkedRepos.forEach(repo => projectsContainer.innerHTML += `<h3>${repo.name}</h3>` )
drawChart(forkedRepos.length)
getPullRequests (forkedRepos)
})
}
getRepos()
*/