This repository was archived by the owner on Sep 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscript.js
More file actions
104 lines (85 loc) · 2.71 KB
/
script.js
File metadata and controls
104 lines (85 loc) · 2.71 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
var repositories = [];
var username;
function addLoadSVG(){
loadsvg = document.getElementById("load");
setimg = document.createElement("img");
setimg.setAttribute("src", "images/puff.svg");
setimg.setAttribute("width", "40");
loadsvg.appendChild(setimg);
}
function deleteLoadSVG(){
var element = document.querySelector("#load");
element.style.display = 'none';
}
function getUsername() {
username = document.getElementById("username").value;
addLoadSVG();
getRepositories(username);
}
function getRepositories(username){
const fetchPromise = fetch('https://api.github.com/users/' + username + '/repos');
fetchPromise.then(response => {
return response.json();
}).then(repos => {
listOfRepos(repos, username);
});
}
function listOfRepos(repos){
for (var i=0;i<repos.length;i++){
if (repos[i].fork == false){
name_of_repo = repos[i].full_name;
repositories.push(name_of_repo.slice(username.length + 1, name_of_repo.length));
}
}
getIssues();
}
function getIssues(){
for(var i=0;i<repositories.length;i++){
const fetchPromise = fetch('https://api.github.com/repos/' + username + '/' + repositories[i] + '/issues');
fetchPromise.then(response => {
return response.json();
}).then(issues => {
listOfIssues(issues);
});
}
}
/*function displayError(){
htmllist = document.getElementById("list");
var errorheading = document.createElement("h3");
var errortext = document.createTextNode("Ah! Looks like you currently don't have any open issues.");
errorheading.appendChild(errortext);
htmllist.appendChild(errorheading);
return false;
}*/
function listOfIssues(issues){
deleteLoadSVG();
if (issues.length !== 0){
for (var i=0;i<issues.length;i++){
if (issues[i] != null) {
htmllist = document.getElementById("list");
var todo = document.createElement("div");
todo.setAttribute("id", "todo");
//attach title/link to todo
var issuelink = document.createElement("a");
issuelink.setAttribute("href", issues[i].html_url);
var issueTitle = document.createTextNode(issues[i].title);
issuelink.appendChild(issueTitle);
todo.appendChild(issuelink);
//attach date to todo
var Tododate = document.createElement("div");
Tododate.setAttribute("id", "date");
var todo_date = document.createTextNode(issues[i].created_at.slice(0, 10));
Tododate.appendChild(todo_date);
todo.appendChild(Tododate);
//attach status to todo
var status = document.createElement("div");
status.setAttribute("id", "status");
var x = document.createTextNode(issues[i].state.charAt(0).toUpperCase() + issues[i].state.slice(1));
status.appendChild(x);
todo.appendChild(status);
//attach the todo to list
list.appendChild(todo);
}
}
}
}