|
3 | 3 | // Copyright (c) 2022 Seyon Rajagopal
|
4 | 4 | // -------------------------------------------
|
5 | 5 |
|
6 |
| - |
7 |
| -// To use a form instead of a specific user comment out the following 2 lines of code: |
8 |
| - |
9 |
| -window.onload = genRepo('qlibs'); |
10 |
| - |
11 |
| - |
12 |
| -function genRepo(user) { |
13 |
| - const testuser = /^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i; |
14 |
| - |
15 |
| - if (testuser.test(user) == false || user == "" || user == null) { |
16 |
| - $("#repo-box").append("<div class='error-box'><h1 class='error-msg'> Sorry the GitHub username appears to be invalid </h1></div>"); |
| 6 | +async function latest_release(repo_name) { |
| 7 | + try { |
| 8 | + const response = await fetch('https://api.github.com/repos/qlibs/' + repo_name + '/releases'); |
| 9 | + if (!response.ok) { |
| 10 | + console.error('Failed to fetch releases:', response.statusText); |
| 11 | + return ''; |
17 | 12 | }
|
18 | 13 |
|
19 |
| - else { |
20 |
| - |
21 |
| - var requestURL = 'https://api.github.com/users/' + user + '/repos'; |
22 |
| - var request = $.get(requestURL, function () { |
23 |
| - }) |
24 |
| - .done(function () { |
25 |
| - request = request.responseJSON; |
26 |
| - if (!Array.isArray(request) || !request.length) { |
27 |
| - $("#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>"); |
28 |
| - } |
29 |
| - else { |
30 |
| - for (i = 0; i < request.length; i++) { |
31 |
| - console.log(request[i]); |
32 |
| - var repo_url = request[i].html_url; |
33 |
| - var username = request[i].owner.login; |
34 |
| - var repo_name = request[i].name; |
35 |
| - var repo_description = request[i].description; |
36 |
| - var repo_language = request[i].language; |
37 |
| - var repo_stars = request[i].stargazers_count; |
38 |
| - var repo_forks = request[i].forks; |
39 |
| - |
40 |
| - if (repo_name.includes("github.io")) continue; |
41 |
| - if (repo_name.includes("qlibs")) continue; |
42 |
| - if (repo_name.includes(".github")) continue; |
| 14 | + const releases = await response.json(); |
| 15 | + if (Array.isArray(releases) && releases.length > 0) { |
| 16 | + console.log(releases); |
| 17 | + return releases[0].tag_name || ''; |
| 18 | + } else { |
| 19 | + return ''; |
| 20 | + } |
| 21 | + } catch (error) { |
| 22 | + console.error('Error fetching release data:', error); |
| 23 | + return ''; |
| 24 | + } |
| 25 | +} |
43 | 26 |
|
44 |
| - if (repo_language == null) { |
45 |
| - repo_language = "-"; |
46 |
| - } |
| 27 | +async function latest_release(repo_name) { |
| 28 | + const response = await fetch(`https://api.github.com/repos/qlibs/${repo_name}/releases/latest`); |
| 29 | + const data = await response.json(); |
| 30 | + return data.tag_name; |
| 31 | +} |
47 | 32 |
|
48 |
| - $("#repo-box").append("<a href='" + repo_url + "'><div class='repo-item'><h1 class='title'>" + |
49 |
| - "" + |
50 |
| - repo_name + "</h1><p class='description'>" + |
51 |
| - repo_description + |
52 |
| - "<br/><img src='https://img.shields.io/github/v/release/qlibs/" + repo_name + "'></img>" + |
53 |
| - " <div class='star'><span class='img' uk-icon='star' class='uk-icon'></span>" + |
54 |
| - repo_stars + " </div> <div class='fork'><span class='img' uk-icon='git-fork' class='uk-icon'></span>" + |
55 |
| - repo_forks + "</div></div></div>" + |
56 |
| - "</p>" |
57 |
| - ); |
58 |
| - } |
59 |
| - } |
60 |
| - }); |
61 |
| - } |
| 33 | +window.onload = function () { |
| 34 | + var request = $.get('https://api.github.com/users/qlibs/repos', function () { }) |
| 35 | + .done(function () { |
| 36 | + request = request.responseJSON; |
| 37 | + if (!Array.isArray(request) || !request.length) { |
| 38 | + $("#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>"); |
| 39 | + } |
| 40 | + else { |
| 41 | + for (i = 0; i < request.length; i++) { |
| 42 | + const repo_name = request[i].name; |
| 43 | + if (repo_name.includes("github.io")) continue; |
| 44 | + if (repo_name.includes("qlibs")) continue; |
| 45 | + if (repo_name.includes(".github")) continue; |
| 46 | + const repo_url = request[i].html_url; |
| 47 | + const repo_description = request[i].description; |
| 48 | + const repo_stars = request[i].stargazers_count; |
| 49 | + const repo_forks = request[i].forks; |
| 50 | + latest_release(repo_name).then(repo_release => { |
| 51 | + $("#repo-box").append("<a href='" + repo_url + "'><div class='repo-item'><h1 class='title'>" + |
| 52 | + "" + |
| 53 | + repo_name + "</h1><div style='color:darkgray'> ("+ repo_release +")</div> <p class='description'>" + |
| 54 | + repo_description + |
| 55 | + " <div class='star'><span class='img' uk-icon='star' class='uk-icon'></span>" + |
| 56 | + repo_stars + " </div> <div class='fork'><span class='img' uk-icon='git-fork' class='uk-icon'></span>" + |
| 57 | + repo_forks + "</div></div></div>" + |
| 58 | + "</p>" |
| 59 | + ); |
| 60 | + }) |
| 61 | + } |
| 62 | + } |
| 63 | + }); |
62 | 64 | }
|
0 commit comments