-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-commits.html
More file actions
801 lines (739 loc) · 22.8 KB
/
Copy pathgithub-commits.html
File metadata and controls
801 lines (739 loc) · 22.8 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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>GitHub Commits Viewer</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: Helvetica, -apple-system, BlinkMacSystemFont, "Segoe UI",
Arial, sans-serif;
line-height: 1.6;
max-width: 980px;
margin: 0 auto;
padding: 20px;
color: #24292e;
background: #ffffff;
}
h1 {
border-bottom: 1px solid #eaecef;
padding-bottom: 0.3em;
margin-top: 0;
font-size: 32px;
font-weight: 600;
}
.controls {
display: flex;
gap: 8px;
align-items: flex-end;
margin-bottom: 16px;
flex-wrap: wrap;
}
.input-group {
flex: 1;
min-width: 300px;
}
.input-group label {
display: block;
margin-bottom: 6px;
font-size: 14px;
font-weight: 600;
color: #24292e;
}
.input-group input {
width: 100%;
padding: 8px 12px;
font-size: 14px;
font-family: Helvetica, -apple-system, BlinkMacSystemFont, "Segoe UI",
Arial, sans-serif;
border: 1px solid #e1e4e8;
border-radius: 6px;
background: #ffffff;
color: #24292e;
}
.input-group input:focus {
outline: none;
border-color: #0366d6;
box-shadow: 0 0 0 3px rgba(3, 102, 214, 0.1);
}
.input-group .help-text {
font-size: 12px;
color: #586069;
margin-top: 4px;
}
.btn {
background: #fafbfc;
color: #24292e;
padding: 8px 12px;
border-radius: 6px;
border: 1px solid rgba(27, 31, 35, 0.15);
cursor: pointer;
font-size: 14px;
line-height: 20px;
text-decoration: none;
font-family: Helvetica, -apple-system, BlinkMacSystemFont, "Segoe UI",
Arial, sans-serif;
white-space: nowrap;
}
.btn:hover {
background: #f3f4f6;
}
.btn.primary {
background: #0366d6;
color: #fff;
border: 1px solid rgba(27, 31, 35, 0.15);
}
.btn.primary:hover {
background: #0256c5;
}
.btn.secondary {
background: #fafbfc;
color: #24292e;
border: 1px solid rgba(27, 31, 35, 0.15);
}
.btn.secondary:hover {
background: #f3f4f6;
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.btn.secondary:disabled:hover {
background: #fafbfc;
}
.btn.primary:disabled:hover {
background: #0366d6;
}
.panel {
background: #f6f8fa;
padding: 16px;
border-radius: 6px;
border: 1px solid #e1e4e8;
margin-bottom: 16px;
}
.panel h2 {
margin-top: 0;
margin-bottom: 12px;
font-size: 20px;
font-weight: 600;
color: #24292e;
cursor: pointer;
user-select: none;
display: flex;
align-items: center;
}
.panel h2::before {
content: "▼";
display: inline-block;
margin-right: 8px;
transition: transform 0.2s;
font-size: 12px;
}
.panel h2.collapsed::before {
transform: rotate(-90deg);
}
.panel-content {
transition: max-height 0.3s ease;
overflow: hidden;
}
.panel-content.collapsed {
display: none;
}
.back-link {
display: inline-block;
margin-bottom: 16px;
color: #0366d6;
text-decoration: none;
font-size: 14px;
}
.back-link:hover {
text-decoration: underline;
}
.info {
font-size: 13px;
color: #586069;
margin-bottom: 12px;
}
.empty-state {
color: #586069;
font-style: italic;
text-align: center;
padding: 40px 20px;
}
.error-message {
background: #ffeef0;
color: #86181d;
padding: 12px;
border-radius: 6px;
border: 1px solid #f97583;
margin-bottom: 16px;
font-size: 14px;
}
.success-message {
background: #dcffe4;
color: #144620;
padding: 12px;
border-radius: 6px;
border: 1px solid #34d058;
margin-bottom: 16px;
font-size: 14px;
}
.commits-list {
background: #ffffff;
border-radius: 6px;
border: 1px solid #e1e4e8;
}
.commit-item {
padding: 16px;
border-bottom: 1px solid #e1e4e8;
transition: background 0.2s;
}
.commit-item:last-child {
border-bottom: none;
}
.commit-item:hover {
background: #f6f8fa;
}
.commit-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 8px;
gap: 12px;
flex-wrap: wrap;
}
.commit-message {
font-weight: 600;
color: #24292e;
font-size: 14px;
margin-bottom: 4px;
word-break: break-word;
}
.commit-sha {
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo,
monospace;
font-size: 12px;
color: #0366d6;
background: #f6f8fa;
padding: 2px 6px;
border-radius: 3px;
text-decoration: none;
white-space: nowrap;
}
.commit-sha:hover {
text-decoration: underline;
}
.commit-author {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
}
.commit-avatar {
width: 20px;
height: 20px;
border-radius: 50%;
border: 1px solid #e1e4e8;
}
.commit-author-name {
font-size: 13px;
color: #24292e;
font-weight: 500;
}
.commit-date {
font-size: 12px;
color: #586069;
}
.commit-stats {
display: flex;
gap: 16px;
font-size: 12px;
color: #586069;
margin-top: 8px;
}
.commit-stat {
display: flex;
align-items: center;
gap: 4px;
}
.commit-stat.additions {
color: #28a745;
}
.commit-stat.deletions {
color: #d73a49;
}
.commit-stat.files {
color: #6f42c1;
}
.loading {
text-align: center;
padding: 40px 20px;
color: #586069;
}
.loading::after {
content: "...";
animation: dots 1.5s steps(4, end) infinite;
}
@keyframes dots {
0%,
20% {
content: ".";
}
40% {
content: "..";
}
60%,
100% {
content: "...";
}
}
.actions {
display: flex;
gap: 8px;
margin-bottom: 12px;
flex-wrap: wrap;
}
.options {
background: #ffffff;
padding: 12px;
border-radius: 6px;
border: 1px solid #e1e4e8;
margin-bottom: 12px;
}
.option-group {
margin-bottom: 12px;
}
.option-group:last-child {
margin-bottom: 0;
}
.option-group label {
display: block;
margin-bottom: 6px;
font-size: 14px;
font-weight: 600;
color: #24292e;
}
.option-group input[type="number"] {
width: 100%;
padding: 6px 12px;
font-size: 14px;
font-family: Helvetica, -apple-system, BlinkMacSystemFont, "Segoe UI",
Arial, sans-serif;
border: 1px solid #e1e4e8;
border-radius: 6px;
background: #ffffff;
color: #24292e;
}
.option-group input[type="number"]:focus {
outline: none;
border-color: #0366d6;
}
.option-description {
font-size: 12px;
color: #586069;
margin-top: 4px;
}
.btn-group {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
@media (max-width: 768px) {
.commit-header {
flex-direction: column;
}
.controls {
flex-direction: column;
align-items: stretch;
flex-wrap: wrap;
}
.input-group {
width: 100%;
}
}
</style>
</head>
<body>
<a href="index.html" class="back-link">← Back to Browser Tools</a>
<h1>GitHub Commits Viewer</h1>
<div class="controls">
<div class="input-group">
<label for="repoUrl">Repository URL or Owner/Repo</label>
<input
type="text"
id="repoUrl"
placeholder="https://github.com/owner/repo or owner/repo"
/>
</div>
<button id="fetchBtn" class="btn primary">Fetch Commits</button>
<button id="clearBtn" class="btn secondary">Clear</button>
</div>
<div class="help-text" style="margin-bottom: 16px">
Enter a GitHub repository URL or just owner/repo (e.g.,
virtualarchitectures/Browser-Tools)
</div>
<div id="errorMsg" class="error-message" style="display: none"></div>
<div id="successMsg" class="success-message" style="display: none"></div>
<div id="optionsPanel" class="panel" style="display: none">
<h2 id="optionsHeader">Options</h2>
<div id="optionsContent" class="panel-content">
<div class="options">
<div class="option-group">
<label for="commitLimit">Number of commits to fetch</label>
<input
type="number"
id="commitLimit"
min="1"
max="100"
value="30"
/>
<div class="option-description">
Maximum 100 commits per request (GitHub API limit)
</div>
</div>
</div>
</div>
</div>
<div id="resultsPanel" class="panel" style="display: none">
<h2 id="resultsHeader">
<span id="resultsTitle">Commits</span>
</h2>
<div id="resultsContent" class="panel-content">
<div class="actions">
<button id="downloadJsonBtn" class="btn primary">
Download JSON
</button>
<button id="downloadCsvBtn" class="btn primary">Download CSV</button>
<button id="downloadMarkdownBtn" class="btn primary">
Download Markdown
</button>
</div>
<div class="info">
<span id="commitCount">0 commits</span> loaded from
<span id="repoName"></span>
</div>
<div id="commitsList" class="commits-list"></div>
</div>
</div>
<script>
/* =========================
DOM Elements
========================= */
const repoUrlInput = document.getElementById("repoUrl");
const fetchBtn = document.getElementById("fetchBtn");
const errorMsg = document.getElementById("errorMsg");
const successMsg = document.getElementById("successMsg");
const optionsPanel = document.getElementById("optionsPanel");
const optionsHeader = document.getElementById("optionsHeader");
const optionsContent = document.getElementById("optionsContent");
const resultsPanel = document.getElementById("resultsPanel");
const resultsHeader = document.getElementById("resultsHeader");
const resultsContent = document.getElementById("resultsContent");
const resultsTitle = document.getElementById("resultsTitle");
const commitsList = document.getElementById("commitsList");
const commitCount = document.getElementById("commitCount");
const repoName = document.getElementById("repoName");
const commitLimit = document.getElementById("commitLimit");
const downloadJsonBtn = document.getElementById("downloadJsonBtn");
const downloadCsvBtn = document.getElementById("downloadCsvBtn");
const downloadMarkdownBtn = document.getElementById(
"downloadMarkdownBtn"
);
const clearBtn = document.getElementById("clearBtn");
/* =========================
State
========================= */
let currentCommits = [];
let currentRepo = "";
/* =========================
Utility Functions
========================= */
function showError(message) {
errorMsg.textContent = message;
errorMsg.style.display = "block";
successMsg.style.display = "none";
}
function showSuccess(message) {
successMsg.textContent = message;
successMsg.style.display = "block";
errorMsg.style.display = "none";
}
function hideMessages() {
errorMsg.style.display = "none";
successMsg.style.display = "none";
}
function parseRepoUrl(input) {
input = input.trim();
// If it's already in owner/repo format
if (/^[^/]+\/[^/]+$/.test(input)) {
return input;
}
// Try to extract from GitHub URL
const patterns = [
/github\.com\/([^/]+\/[^/]+)/,
/github\.com\/([^/]+\/[^/]+)\.git/,
];
for (const pattern of patterns) {
const match = input.match(pattern);
if (match) {
return match[1].replace(/\.git$/, "");
}
}
return null;
}
function formatDate(dateString) {
const date = new Date(dateString);
const now = new Date();
const diffMs = now - date;
const diffMins = Math.floor(diffMs / 60000);
const diffHours = Math.floor(diffMs / 3600000);
const diffDays = Math.floor(diffMs / 86400000);
if (diffMins < 1) return "just now";
if (diffMins < 60)
return `${diffMins} minute${diffMins > 1 ? "s" : ""} ago`;
if (diffHours < 24)
return `${diffHours} hour${diffHours > 1 ? "s" : ""} ago`;
if (diffDays < 30)
return `${diffDays} day${diffDays > 1 ? "s" : ""} ago`;
return date.toLocaleDateString("en-US", {
year: "numeric",
month: "short",
day: "numeric",
});
}
function truncateMessage(message) {
const firstLine = message.split("\n")[0];
return firstLine.length > 100
? firstLine.substring(0, 100) + "..."
: firstLine;
}
/* =========================
API Functions
========================= */
async function fetchCommits(repo, limit = 30) {
const apiUrl = `https://api.github.com/repos/${repo}/commits?per_page=${limit}`;
try {
const response = await fetch(apiUrl);
if (!response.ok) {
if (response.status === 404) {
throw new Error("Repository not found. Please check the URL.");
} else if (response.status === 403) {
throw new Error(
"API rate limit exceeded. Please try again later."
);
} else {
throw new Error(`GitHub API error: ${response.status}`);
}
}
const commits = await response.json();
return commits;
} catch (error) {
if (error.message.includes("Failed to fetch")) {
throw new Error(
"Network error. Please check your internet connection."
);
}
throw error;
}
}
/* =========================
Display Functions
========================= */
function displayCommits(commits, repo) {
currentCommits = commits;
currentRepo = repo;
commitsList.innerHTML = "";
if (!commits || commits.length === 0) {
commitsList.innerHTML =
'<div class="empty-state">No commits found</div>';
return;
}
commits.forEach((commit) => {
const commitItem = document.createElement("div");
commitItem.className = "commit-item";
const sha = commit.sha.substring(0, 7);
const message = truncateMessage(commit.commit.message);
const author = commit.commit.author.name;
const date = formatDate(commit.commit.author.date);
const avatarUrl = commit.author
? commit.author.avatar_url
: `https://github.com/identicons/${commit.commit.author.email}.png`;
const commitUrl = commit.html_url;
commitItem.innerHTML = `
<div class="commit-header">
<div>
<div class="commit-message">${escapeHtml(message)}</div>
<div class="commit-author">
<img src="${avatarUrl}" alt="${escapeHtml(
author
)}" class="commit-avatar" />
<span class="commit-author-name">${escapeHtml(author)}</span>
<span class="commit-date">committed ${date}</span>
</div>
</div>
<a href="${commitUrl}" target="_blank" class="commit-sha" title="View on GitHub">${sha}</a>
</div>
`;
commitsList.appendChild(commitItem);
});
// Update info
commitCount.textContent = `${commits.length} commit${
commits.length !== 1 ? "s" : ""
}`;
repoName.textContent = repo;
// Show results panel
resultsPanel.style.display = "block";
}
function escapeHtml(text) {
const div = document.createElement("div");
div.textContent = text;
return div.innerHTML;
}
function commitsToCSV(commits, repo) {
const headers = ["Author", "Date", "Message", "Commit Link"];
const csvLines = [headers.join(",")];
commits.forEach((commit) => {
const author = escapeCSVField(commit.commit.author.name);
const date = escapeCSVField(commit.commit.author.date);
const message = escapeCSVField(
commit.commit.message.replace(/\n/g, " ")
);
const link = escapeCSVField(commit.html_url);
csvLines.push([author, date, message, link].join(","));
});
return csvLines.join("\n");
}
function escapeCSVField(field) {
const str = String(field);
if (str.includes(",") || str.includes('"') || str.includes("\n")) {
return '"' + str.replace(/"/g, '""') + '"';
}
return str;
}
function commitsToMarkdown(commits, repo) {
let markdown = `# Commits for ${repo}\n\n`;
markdown += "| Author | Date | Message | Link |\n";
markdown += "|--------|------|---------|------|\n";
commits.forEach((commit) => {
const author = commit.commit.author.name.replace(/\|/g, "\\|");
const date = commit.commit.author.date;
const message = commit.commit.message
.split("\n")[0]
.replace(/\|/g, "\\|");
const sha = commit.sha.substring(0, 7);
const link = `[${sha}](${commit.html_url})`;
markdown += `| ${author} | ${date} | ${message} | ${link} |\n`;
});
return markdown;
}
/* =========================
Event Handlers
========================= */
fetchBtn.addEventListener("click", async () => {
hideMessages();
const input = repoUrlInput.value;
const repo = parseRepoUrl(input);
if (!repo) {
showError(
"Invalid repository format. Please enter a valid GitHub URL or owner/repo."
);
return;
}
const limit = parseInt(commitLimit.value) || 30;
// Show loading state
fetchBtn.disabled = true;
fetchBtn.textContent = "Fetching...";
commitsList.innerHTML = '<div class="loading">Loading commits</div>';
try {
const commits = await fetchCommits(repo, limit);
displayCommits(commits, repo);
showSuccess(
`Successfully loaded ${commits.length} commit${
commits.length !== 1 ? "s" : ""
} from ${repo}`
);
// Show options panel after first fetch
if (optionsPanel.style.display === "none") {
optionsPanel.style.display = "block";
}
} catch (error) {
showError(error.message);
commitsList.innerHTML = "";
resultsPanel.style.display = "none";
} finally {
fetchBtn.disabled = false;
fetchBtn.textContent = "Fetch Commits";
}
});
// Allow Enter key to trigger fetch
repoUrlInput.addEventListener("keypress", (e) => {
if (e.key === "Enter") {
fetchBtn.click();
}
});
// Download JSON button
downloadJsonBtn.addEventListener("click", () => {
const json = JSON.stringify(currentCommits, null, 2);
const blob = new Blob([json], { type: "application/json" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `${currentRepo.replace("/", "-")}-commits.json`;
a.click();
URL.revokeObjectURL(url);
showSuccess("JSON file downloaded!");
});
// Download CSV button
downloadCsvBtn.addEventListener("click", () => {
const csv = commitsToCSV(currentCommits, currentRepo);
const blob = new Blob([csv], { type: "text/csv" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `${currentRepo.replace("/", "-")}-commits.csv`;
a.click();
URL.revokeObjectURL(url);
showSuccess("CSV file downloaded!");
});
// Download Markdown button
downloadMarkdownBtn.addEventListener("click", () => {
const markdown = commitsToMarkdown(currentCommits, currentRepo);
const blob = new Blob([markdown], { type: "text/markdown" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `${currentRepo.replace("/", "-")}-commits.md`;
a.click();
URL.revokeObjectURL(url);
showSuccess("Markdown file downloaded!");
});
// Clear button
clearBtn.addEventListener("click", () => {
currentCommits = [];
currentRepo = "";
commitsList.innerHTML = "";
resultsPanel.style.display = "none";
repoUrlInput.value = "";
hideMessages();
});
// Panel collapse/expand
optionsHeader.addEventListener("click", () => {
optionsHeader.classList.toggle("collapsed");
optionsContent.classList.toggle("collapsed");
});
resultsHeader.addEventListener("click", () => {
resultsHeader.classList.toggle("collapsed");
resultsContent.classList.toggle("collapsed");
});
/* =========================
Initialization
========================= */
// Set default repository for demo purposes
repoUrlInput.value = "";
repoUrlInput.focus();
</script>
</body>
</html>