/
repo_terminator.html
82 lines (73 loc) · 2.76 KB
/
repo_terminator.html
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
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
#results li { margin-bottom: 5px; }
</style>
</head>
<body>
<p>Create a new <a href="https://github.com/settings/applications#personal-access-tokens" target="_blank">github access token</a> with 'delete_repo' privilege.</p>
<label>Username<input type="text" id="username" /></label><br />
<label>Token<input type="text" id="token" /></label><br />
<button id="get_repos">Get Repos</button>
<button id="select_all">Select All</button>
<div id="results"></div>
<div id="actions"></div>
<script>
var username, token;
$("#get_repos").on("click", function () { get_repos(); });
$("#select_all").on("click", function () {
$("input[type='checkbox']").click();
});
var get_repos = function () {
username = $("#username").val();
token = $("#token").val();
$.ajax({
dataType: "json",
url: "https://api.github.com/users/" + username + "/repos",
headers: { "Authorization": "token " + token },
success: function (data) {
$ul = $("<ul/>", { id: "repos" });
$(data).each( function (index, item) {
text = "<label for='" + item.name + "'>" + item.name + "<br />" + item.description + "</label>"
$li = $("<li/>", { html: text }).appendTo($ul);
$li.prepend($("<input/>", { type: "checkbox", id: item.name }));
});
$remove_button = $("<button/>", { id: "remove", text: "REMOVE" });
$remove_button.on("click", function () {
var to_delete = [];
$("#repos input:checked").each( function (index, element) {
to_delete.push($(element).attr("id"));
});
remove_repos(to_delete);
});
$("#results").empty().append($ul)
$("#actions").empty().append($remove_button);
}
});
};
var remove_repos = function (names) {
$.when(
$(names).each( function (index, name) {
return remove_repo(name);
})
).done(function () {
$("#actions").after($("<div />", { id: "done", text: "DONE" }));
$("#done").fadeOut(3000, function() { $(this).remove() });
});
};
var remove_repo = function (name) {
return $.ajax({
dataType: "json",
type: "DELETE",
url: "https://api.github.com/repos/" + username + "/" + name,
headers: { "Authorization": "token " + token },
success: function (data) {
console.log("deleted: " + name);
}
});
};
</script>
</body>
</html>