36 lines
1.4 KiB
JavaScript
36 lines
1.4 KiB
JavaScript
async function checkInstanceUpdateStatus() {
|
|
try {
|
|
const response = await fetch('/commits.json');
|
|
const text = await response.text();
|
|
const entries = JSON.parse(text);
|
|
const localCommit = document.getElementById('git_commit').dataset.value;
|
|
|
|
let statusMessage = '';
|
|
|
|
if (entries.length > 0) {
|
|
const commitHashes = Array.from(entries).map(entry => {
|
|
return entry.sha
|
|
});
|
|
|
|
const commitIndex = commitHashes.indexOf(localCommit);
|
|
|
|
if (commitIndex === 0) {
|
|
statusMessage = '✅ Instance is up to date.';
|
|
} else if (commitIndex > 0) {
|
|
statusMessage = `⚠️ This instance is not up to date and is ${commitIndex} commits old. Test and confirm on an up-to-date instance before reporting.`;
|
|
} else {
|
|
statusMessage = `⚠️ This instance is not up to date and is at least ${commitHashes.length} commits old. Test and confirm on an up-to-date instance before reporting.`;
|
|
}
|
|
} else {
|
|
statusMessage = '⚠️ Unable to fetch commit information.';
|
|
}
|
|
|
|
document.getElementById('update-status').innerText = statusMessage;
|
|
} catch (error) {
|
|
console.error('Error fetching commits:', error);
|
|
document.getElementById('update-status').innerText = '⚠️ Error checking update status.';
|
|
}
|
|
}
|
|
|
|
checkInstanceUpdateStatus();
|