forked from seyon123/list-github-repos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
63 lines (52 loc) · 3.07 KB
/
script.js
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
// -------------------------------------------
// Author: Seyon Rajagopal
// Copyright (c) 2022 Seyon Rajagopal
// -------------------------------------------
// To use a form instead of a specific user comment out the following 2 lines of code:
var user = document.domain.split('.', 1); // alternatively, manually enter a different user than yourself using var user = 'alternate_username';
window.onload = genRepo(user);
function genRepo(user) {
const testuser = /^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i;
if (testuser.test(user) == false || user == "" || user == null) {
$("#repo-box").append("<div class='error-box'><h1 class='error-msg'> Sorry the GitHub username appears to be invalid </h1></div>");
}
else {
var requestURL = 'https://api.github.com/users/' + user + '/repos';
var request = $.get(requestURL, function () {
})
.done(function () {
request = request.responseJSON;
if (!Array.isArray(request) || !request.length) {
$("#repo-box").append("<div class='error-box'><h1 class='error-msg'> Sorry the GitHub username entered has no repos or does't exist </h1></div>");
}
else {
for (i = 0; i < request.length; i++) {
// variables from api request
var repo_url = request[i].html_url;
var username = request[i].owner.login;
var repo_name = request[i].name;
var repo_description = request[i].description;
var repo_language = request[i].language;
//var repo_stars = request[i].stargazers_count;
//var repo_forks = request[i].forks;
// replaces null values to be better represented when displayed
if (repo_description == null) {
repo_description = "<i>No Description</i>";
}
if (repo_language == null) {
repo_language = "-";
}
// Puts repo information into div
$("#repo-box").append("<a href='" + repo_url + "' target='_blank'><div class='repo-item'><h1 class='title'>" +
username + "/" +
repo_name + "</h1><p class='description'>" +
repo_description + "</p>" + "<div class='bottom'><div class='language'><span class='img' uk-icon='code' class='uk-icon'></span>" +
repo_language + "</div></div></div>");
//repo_language + "</div> <div class='star'><span class='img' uk-icon='star' class='uk-icon'></span>" +
//repo_stars + " </div> <div class='fork'><span class='img' uk-icon='git-fork' class='uk-icon'></span>" +
//repo_forks + "</div></div></div>");
}
}
});
}
}