From b0b7a24c92ecb9bacc1ec213d6155357086e85db Mon Sep 17 00:00:00 2001 From: Gregory Hendrickson Date: Fri, 9 Jun 2023 17:02:31 -0700 Subject: [PATCH] s --- static-html-directory/script.js | 47 ++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/static-html-directory/script.js b/static-html-directory/script.js index 4adf66a..2eaf09c 100644 --- a/static-html-directory/script.js +++ b/static-html-directory/script.js @@ -1,24 +1,27 @@ -const commitInfoElement = document.getElementById('commit-info'); - -fetch('https://api.github.com/repos/ghndrx/docker-test-image/commits') - .then(response => response.json()) - .then(data => { - if (data.length > 0) { - const latestCommit = data[0]; - const commitMessage = latestCommit.commit.message; - const commitAuthor = latestCommit.commit.author.name; - const commitDate = new Date(latestCommit.commit.author.date).toLocaleString(); - - commitInfoElement.innerHTML = ` -

Message: ${commitMessage}

-

Author: ${commitAuthor}

-

Date: ${commitDate}

- `; - } else { - commitInfoElement.innerHTML = '

No commits found.

'; +window.addEventListener('DOMContentLoaded', async () => { + const repository = 'ghndrx/docker-test-image'; // Replace with your desired repository + + try { + const response = await fetch(`https://api.github.com/repos/${repository}/commits`); + const commits = await response.json(); + + const commitList = document.getElementById('commit-list'); + + if (commits.length > 0) { + commits.forEach(commit => { + const commitElement = document.createElement('div'); + commitElement.classList.add('commit'); + commitElement.innerHTML = ` +

${commit.commit.author.name}

+

${commit.commit.message}

+ `; + commitList.appendChild(commitElement); + }); + } else { + commitList.innerHTML = '

No commits found.

'; + } + } catch (error) { + console.error('Error fetching commits:', error); } - }) - .catch(error => { - commitInfoElement.innerHTML = '

Error loading commit information.

'; - console.error(error); }); + \ No newline at end of file