-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
367 lines (332 loc) · 15.3 KB
/
index.html
File metadata and controls
367 lines (332 loc) · 15.3 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Synctributor</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
<style>
html, body { font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, 'Helvetica Neue', Arial, 'Noto Sans', 'Apple Color Emoji', 'Segoe UI Emoji'; }
.nb-card { border-width: 4px; box-shadow: 6px 6px 0 0 rgba(0,0,0,1); }
.nb-btn { border-width: 4px; box-shadow: 6px 6px 0 0 rgba(0,0,0,1); transition: transform .05s ease; }
.nb-btn:active { transform: translate(2px,2px); box-shadow: 4px 4px 0 0 rgba(0,0,0,1); }
.nb-input { border-width: 4px; box-shadow: 4px 4px 0 0 rgba(0,0,0,1); }
.mono { font-variant-numeric: tabular-nums; }
.grid-autofill { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
</style>
</head>
<body class="bg-yellow-200 min-h-screen">
<header class="max-w-6xl mx-auto px-4 pt-8">
<div class="nb-card bg-white border-black rounded-2xl p-6">
<div class="flex flex-col md:flex-row md:items-center md:items-end gap-4">
<div class="flex-1 text-center md:text-start">
<h1 class="text-3xl md:text-4xl font-extrabold tracking-tight ">Synctributor</h1>
<p class="text-gray-700 font-semibold mt-2">GitHub Org Contributor Ranker</p>
</div>
<a href="https://github.com/SynchronizesTeams/Synctributor" target="_blank" class="nb-btn bg-green-300 border-black rounded-xl px-4 py-2 font-bold hover:brightness-110 text-center">Open GitHub</a>
</div>
</div>
</header>
<main class="max-w-6xl mx-auto px-4 mt-6 pb-24">
<!-- Controls -->
<section class="nb-card bg-pink-200 border-black rounded-2xl p-6">
<form id="controlForm" class="grid md:grid-cols-2 gap-4">
<div>
<label class="block font-bold mb-2">Organization</label>
<input id="orgInput" class="nb-input bg-white mb-2 border-black rounded-xl px-4 py-2 w-full" placeholder="SynchronizesTeams" value="SynchronizesTeams" />
<p class="text-sm text-gray-800 mt-1">Nama organisasi GitHub (case sensitive sesuai GitHub, biasanya PascalCase/TitleCase). Untuk org private, butuh token.</p>
</div>
<div>
<label class="block font-bold mb-2">GitHub Token (opsional)</label>
<input id="tokenInput" type="password" class="nb-input mb-2 bg-white border-black rounded-xl px-4 py-2 w-full" placeholder="ghp_..." />
<p class="text-sm text-gray-800 mt-1">Tambahkan token agar bebas rate limit & akses private repo (scope: <code class="mono">read:org</code>, <code class="mono">repo</code> jika perlu).</p>
</div>
<div class="flex items-center gap-3">
<input id="includePrivate" type="checkbox" class="w-5 h-5 border-4 border-black" />
<label for="includePrivate" class="font-bold">Sertakan private repos</label>
</div>
<div class="flex items-center gap-3">
<input id="dedupeBots" type="checkbox" class="w-5 h-5 border-4 border-black" checked />
<label for="dedupeBots" class="font-bold">Abaikan akun bot</label>
</div>
<div class="md:col-span-2 flex flex-wrap items-center gap-3 mt-2">
<button id="runBtn" class="nb-btn bg-blue-300 border-black rounded-xl px-5 py-2 font-extrabold">Analyze</button>
<button id="exportBtn" type="button" class="nb-btn bg-white border-black rounded-xl px-5 py-2 font-extrabold" disabled>Export CSV</button>
<div id="status" class="font-bold text-gray-900"></div>
</div>
</form>
</section>
<!-- Progress -->
<section id="progressWrap" class="hidden mt-6">
<div class="nb-card bg-white border-black rounded-2xl p-6">
<div class="flex items-center justify-between">
<p class="font-extrabold">Progress</p>
<p class="mono" id="progressText">0%</p>
</div>
<div class="w-full h-6 bg-gray-100 border-4 border-black rounded-xl overflow-hidden mt-3">
<div id="progressBar" class="h-full bg-blue-400" style="width:0%"></div>
</div>
<p id="progressNote" class="text-sm text-gray-700 mt-2">Menyiapkan…</p>
</div>
</section>
<!-- Summary Cards -->
<section id="summary" class="hidden mt-6 grid grid-autofill gap-4">
<div class="nb-card bg-lime-200 border-black rounded-2xl p-5">
<p class="text-sm font-bold">Repos scanned</p>
<p id="sumRepos" class="text-3xl font-extrabold mono">0</p>
</div>
<div class="nb-card bg-amber-200 border-black rounded-2xl p-5">
<p class="text-sm font-bold">Unique contributors</p>
<p id="sumContrib" class="text-3xl font-extrabold mono">0</p>
</div>
<div class="nb-card bg-sky-200 border-black rounded-2xl p-5">
<p class="text-sm font-bold">Top contributor</p>
<div id="sumTop" class="text-xl font-extrabold mono">—</div>
</div>
</section>
<!-- Table -->
<section id="tableWrap" class="hidden mt-6">
<div class="nb-card bg-white border-black rounded-2xl p-6">
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-3">
<h2 class="text-2xl font-extrabold">Leaderboard</h2>
<input id="searchInput" class="nb-input bg-white border-black rounded-xl px-4 py-2 w-full md:w-80" placeholder="Cari username…" />
</div>
<div class="overflow-x-auto mt-4">
<table class="min-w-full border-4 border-black">
<thead class="bg-yellow-200">
<tr>
<th class="border-4 border-black px-4 py-2 text-left">#</th>
<th class="border-4 border-black px-4 py-2 text-left">User</th>
<th class="border-4 border-black px-4 py-2 text-left cursor-pointer" id="thCommits">Commits ▲▼</th>
<th class="border-4 border-black px-4 py-2 text-left">Repos Contributed</th>
</tr>
</thead>
<tbody id="tbody"></tbody>
</table>
</div>
</div>
</section>
<!-- Footer Note -->
<p class="text-center text-sm text-gray-700 mt-8">Powered by <span class="font-extrabold">SynchronizeTeams</span> • Built with GitHub REST API </p>
</main>
<script>
const orgInput = document.getElementById('orgInput');
const tokenInput = document.getElementById('tokenInput');
const includePrivate = document.getElementById('includePrivate');
const dedupeBots = document.getElementById('dedupeBots');
const runBtn = document.getElementById('runBtn');
const exportBtn = document.getElementById('exportBtn');
const statusEl = document.getElementById('status');
const progressWrap = document.getElementById('progressWrap');
const progressBar = document.getElementById('progressBar');
const progressText = document.getElementById('progressText');
const progressNote = document.getElementById('progressNote');
const summary = document.getElementById('summary');
const sumRepos = document.getElementById('sumRepos');
const sumContrib = document.getElementById('sumContrib');
const sumTop = document.getElementById('sumTop');
const tableWrap = document.getElementById('tableWrap');
const tbody = document.getElementById('tbody');
const searchInput = document.getElementById('searchInput');
const thCommits = document.getElementById('thCommits');
let leaderboard = []; // [{login, commits, repos:Set, avatar_url, html_url}]
let reposCache = []; // for CSV export context
function headers() {
const token = tokenInput.value.trim();
const h = { 'Accept': 'application/vnd.github+json' };
if (token) h['Authorization'] = `Bearer ${token}`;
return h;
}
function setProgress(done, total, note='') {
if (total === 0) total = 1; // avoid NaN
const pct = Math.round((done/total) * 100);
progressWrap.classList.remove('hidden');
progressBar.style.width = pct + '%';
progressText.textContent = pct + '%';
progressNote.textContent = note;
}
async function fetchAllPages(url) {
const out = [];
let page = 1;
while (true) {
const u = new URL(url);
u.searchParams.set('per_page', '100');
u.searchParams.set('page', String(page));
const res = await fetch(u.toString(), { headers: headers() });
if (res.status === 202) {
// GitHub may be computing statistics; small delay then retry same page
await new Promise(r => setTimeout(r, 1200));
continue;
}
if (!res.ok) {
const text = await res.text();
throw new Error(`HTTP ${res.status} on ${u}: ${text}`);
}
const arr = await res.json();
if (!Array.isArray(arr) || arr.length === 0) break;
out.push(...arr);
// If less than 100, last page
if (arr.length < 100) break;
page++;
}
return out;
}
async function getRepos(org, includePrivate) {
const type = includePrivate ? 'all' : 'public';
return await fetchAllPages(`https://api.github.com/orgs/${org}/repos?type=${type}&sort=updated`);
}
async function getContributors(owner, repo) {
// Use /contributors which includes anonymous=false by default
// Note: For forks with no commits, may return 204 No Content; handled by fetchAllPages logic via OK check
return await fetchAllPages(`https://api.github.com/repos/${owner}/${repo}/contributors`);
}
function isBot(login) {
return /\[bot\]$/.test(login) || /-bot$/.test(login) || login.toLowerCase().includes('bot');
}
function renderTable(data) {
tbody.innerHTML = '';
data.forEach((row, i) => {
const tr = document.createElement('tr');
tr.innerHTML = `
<td class="border-4 border-black px-3 py-2 mono">${i+1}</td>
<td class="border-4 border-black px-3 py-2">
<a class="font-extrabold hover:underline" href="${row.html_url}" target="_blank">
<div class="flex items-center gap-3">
<img src="${row.avatar_url}" class="w-8 h-8 border-4 border-black" alt="${row.login}" />
<span>${row.login}</span>
</div>
</a>
</td>
<td class="border-4 border-black px-3 py-2 mono font-extrabold">${row.commits}</td>
<td class="border-4 border-black px-3 py-2 mono">${row.repos.size}</td>
`;
tbody.appendChild(tr);
});
tableWrap.classList.remove('hidden');
}
function updateSummary() {
sumRepos.textContent = String(reposCache.length);
sumContrib.textContent = String(leaderboard.length);
if (leaderboard[0]) {
sumTop.innerHTML = `<a href="${leaderboard[0].html_url}" class="underline" target="_blank">${leaderboard[0].login}</a> · <span class="mono">${leaderboard[0].commits} commits</span>`;
} else {
sumTop.textContent = '—';
}
summary.classList.remove('hidden');
}
function toCSV(rows) {
const header = ['rank','login','commits','repos_count','profile_url'];
const lines = [header.join(',')];
rows.forEach((r,i)=>{
const line = [i+1, r.login, r.commits, r.repos.size, r.html_url]
.map(v => typeof v === 'string' && v.includes(',') ? `"${v.replace(/"/g,'""')}"` : v)
.join(',');
lines.push(line);
});
return lines.join('\n');
}
function downloadCSV(filename, text) {
const blob = new Blob([text], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
// Simple concurrency pool
async function mapLimited(items, limit, fn, onProgress) {
let i = 0, done = 0;
const results = new Array(items.length);
const workers = new Array(Math.min(limit, items.length)).fill(0).map(async () => {
while (true) {
const idx = i++;
if (idx >= items.length) break;
try {
results[idx] = await fn(items[idx], idx);
} catch (e) {
results[idx] = { error: e };
}
done++;
onProgress && onProgress(done, items.length);
}
});
await Promise.all(workers);
return results;
}
async function analyze() {
leaderboard = [];
reposCache = [];
tbody.innerHTML = '';
summary.classList.add('hidden');
tableWrap.classList.add('hidden');
exportBtn.disabled = true;
const org = orgInput.value.trim();
if (!org) { alert('Isi nama Organization terlebih dahulu.'); return; }
statusEl.textContent = 'Mengambil daftar repos...';
setProgress(0, 1, 'Load repos');
let repos;
try {
repos = await getRepos(org, includePrivate.checked);
} catch (e) {
console.error(e);
alert('Gagal mengambil repos: ' + e.message);
return;
}
if (!repos || repos.length === 0) {
statusEl.textContent = 'Tidak ada repo ditemukan.';
setProgress(1, 1, 'Selesai');
return;
}
reposCache = repos;
statusEl.textContent = `Memindai ${repos.length} repos untuk contributors...`;
const contribMap = new Map(); // login -> {login, commits, repos:Set, avatar_url, html_url}
const ignoreBots = dedupeBots.checked;
await mapLimited(repos, 5, async (repo) => {
const contributors = await getContributors(repo.owner.login, repo.name);
for (const c of contributors) {
if (!c || !c.login) continue;
if (ignoreBots && isBot(c.login)) continue;
const login = c.login;
const contributions = Number(c.contributions || 0);
if (!contribMap.has(login)) {
contribMap.set(login, { login, commits: 0, repos: new Set(), avatar_url: c.avatar_url, html_url: `https://github.com/${login}` });
}
const entry = contribMap.get(login);
entry.commits += contributions;
entry.repos.add(repo.name);
}
}, (done,total)=>{
setProgress(done, total, `Repos processed: ${done}/${total}`);
});
leaderboard = Array.from(contribMap.values()).sort((a,b)=> b.commits - a.commits);
renderTable(leaderboard);
updateSummary();
statusEl.textContent = 'Selesai.';
exportBtn.disabled = leaderboard.length === 0;
}
runBtn.addEventListener('click', (e)=>{ e.preventDefault(); analyze(); });
// Search filter
searchInput.addEventListener('input', () => {
const q = searchInput.value.trim().toLowerCase();
const filtered = leaderboard.filter(r => r.login.toLowerCase().includes(q));
renderTable(filtered);
});
// Sort by commits toggle
let commitsAsc = false;
thCommits.addEventListener('click', () => {
commitsAsc = !commitsAsc;
const sorted = [...leaderboard].sort((a,b)=> commitsAsc ? (a.commits - b.commits) : (b.commits - a.commits));
renderTable(sorted);
});
exportBtn.addEventListener('click', () => {
if (leaderboard.length === 0) return;
const csv = toCSV(leaderboard);
const org = orgInput.value.trim() || 'organization';
downloadCSV(`${org}-contributors.csv`, csv);
});
</script>
</body>
</html>