-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-explorer.js
More file actions
178 lines (171 loc) · 6.03 KB
/
github-explorer.js
File metadata and controls
178 lines (171 loc) · 6.03 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* global $ */
let bearer;
const tr = document.createElement('tr');
const filter = 'filter-select filter-exact filter-onlyAvail mark-ignore';
const sorter = 'sorter-customDate';
const sort = 'sortInitialOrder-desc';
const headers = [['', 'Name'], ['', 'Description'], [filter, 'Language'], [filter, 'Type'], [sorter, 'Creation Date'], [sorter, 'Push Date'],
[sort, 'Watchers'], [sort, 'Stars'], [sort, 'Forks'], [sort, 'Issues'], [sort, 'PRs'], [sort, 'Projects'], [sort, 'Commits'], [sort, 'Branches'],
[sort, 'Tags'], [sort, 'Releases'], [sort, 'Packages'], [sort, 'Deployments']];
for (const header of headers) {
const th = document.createElement('th');
th.className = header[0];
th.innerHTML = header[1];
tr.appendChild(th);
}
document.getElementsByTagName('thead')[0].appendChild(tr);
window.fetch('https://gist.githubusercontent.com/mobikasaba/9621924d939b5c818aa25c4114e29abd/raw/293aa51fd8d1d9cefefc19eea117efbe8dc5e551/github-explorer')
.then(res => {
return res.text();
})
.then(res => {
bearer = res;
});
function text (text) {
return document.createTextNode(text === 'null' ? '' : text);
}
function element (t, url) {
const i = document.createElement('i');
i.setAttribute('class', 'fas fa-external-link-alt');
const a = document.createElement('a');
a.setAttribute('target', '_blank');
a.setAttribute('rel', 'noopener noreferrer');
a.setAttribute('href', url);
a.appendChild(i);
const span = document.createElement('span');
span.appendChild(text(t + ' '));
span.appendChild(a);
return span;
}
function query (owner, after) {
return `query {
rateLimit {
cost
remaining
resetAt
}
repositoryOwner(login: "${owner}") {
repositories(first: 100${after}) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
name
description
primaryLanguage {name}
owner {login}
isFork
createdAt
pushedAt
watchers {totalCount}
stargazers {totalCount}
forkCount
issues(states: OPEN) {totalCount}
pullRequests(states: OPEN) {totalCount}
projects(states: OPEN) {totalCount}
defaultBranchRef {
target {
... on Commit {
history {totalCount}
}
}
}
branches: refs(refPrefix: "refs/heads/") {totalCount}
tags: refs(refPrefix: "refs/tags/") {totalCount}
releases {totalCount}
packages {totalCount}
deployments {totalCount}
url
}
}
}
}
}`;
}
window.list = async function () {
const owner = document.getElementById('owner').value;
document.getElementById('loading').innerHTML = 'Loading';
let after = '';
let repos = [];
do {
await window.fetch('https://api.github.com/graphql', { method: 'POST', body: JSON.stringify({ query: query(owner, after) }), headers: { Authorization: 'Bearer ' + bearer } })
.then(res => {
return res.json();
})
.then(res => {
console.log(`Cost: ${res.data.rateLimit.cost} Remaining: ${res.data.rateLimit.remaining} Reset at: ${new Date(res.data.rateLimit.resetAt)}`);
res = res.data.repositoryOwner.repositories;
repos = repos.concat(res.edges);
if (res.pageInfo.hasNextPage) {
after = `, after: "${res.pageInfo.endCursor}"`;
} else {
after = '';
}
})
.catch(error => {
console.error(error);
after = '';
});
} while (after !== '');
$('table tbody').empty();
for (const repo of repos) {
const row = document.createElement('tr');
const fields = [element(repo.node.name, repo.node.url), text(repo.node.description),
text(repo.node.primaryLanguage === null ? '' : repo.node.primaryLanguage.name),
text(repo.node.owner.login.toLocaleLowerCase() === owner.toLocaleLowerCase() ? (repo.node.isFork ? 'Fork' : 'Owner') : 'Collaborator'),
text(new Date(repo.node.createdAt)), text(new Date(repo.node.pushedAt)), text(repo.node.watchers.totalCount),
text(repo.node.stargazers.totalCount), text(repo.node.forkCount), text(repo.node.issues.totalCount),
text(repo.node.pullRequests.totalCount), text(repo.node.projects.totalCount), text(repo.node.defaultBranchRef.target.history.totalCount),
text(repo.node.branches.totalCount), text(repo.node.tags.totalCount), text(repo.node.releases.totalCount), text(repo.node.packages.totalCount), text(repo.node.deployments.totalCount)];
for (const field of fields) {
const cell = document.createElement('td');
cell.appendChild(field);
row.appendChild(cell);
}
$('table tbody').append(row);
}
$('table').trigger('update');
document.getElementById('loading').innerHTML = '';
};
$(function () {
$('table').tablesorter({
theme: 'bootstrap',
sortReset: true,
sortList: [[0, 0]],
headerTemplate: '{content} {icon}',
widgets: ['uitheme', 'zebra', 'saveSort', 'resizable', 'filter', 'mark', 'print', 'columnSelector', 'stickyHeaders'],
widgetOptions: {
filter_cssFilter: 'form-control',
filter_external: '.search',
filter_reset: '.reset-filter',
filter_saveFilters: true,
print_styleSheet: 'https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.1/css/theme.bootstrap_4.min.css',
columnSelector_container: '#popover-target',
columnSelector_mediaqueryState: false
}
}).tablesorterPager({
container: $('.ts-pager'),
output: '{startRow} - {endRow} / {filteredRows} ({totalRows})'
});
$.tablesorter.addParser({
id: 'customDate',
format: s => {
return Date.parse(s);
},
type: 'numeric'
});
$('#popover').popover({
placement: 'right',
html: true,
content: $('#popover-target')
});
$('.reset-sort').click(function () {
$('table').trigger('saveSortReset').trigger('sortReset');
return false;
});
$('.print').click(function () {
$('table').trigger('printTable');
});
});