-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (28 loc) · 1.24 KB
/
script.js
File metadata and controls
30 lines (28 loc) · 1.24 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
document.getElementById("commitForm").addEventListener("submit", async function (e) {
e.preventDefault();
const username = document.getElementById("username").value;
const repo = document.getElementById("repo").value;
const list = document.getElementById("commit-list");
list.innerHTML = "<p>Loading commits...</p>";
try{
const response = await fetch('https://api.github.com/repos/${username}/${repo}/commits');
if(!response.ok) {
throw new Error("Repository not found or is private!");
}
const data = await response.json();
if (data.length === 0) {
list.innerHTML = "<p>No commits found.</p>";
return;
}
data.slice(0,10).forEach(commit => {
const item = document.createElement("div");
item.className = "commit";
item.innerHTML =`<p><strong>Message:</strong> ${commit.commit.message}</p>
<p><strong>Author:</strong> ${commit.commit.author.name}</p>
<p><strong>Date:</strong> ${new Date(commit.commit.author.date).toLocaleString()}</p>`;
list.appendChild(item);
});
} catch (error) {
list.innerHTML ='<p>Error: ${error.message}</p>';
}
});