-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display whether or not the instance is up to date on error (#310)
- Loading branch information
Showing
4 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
async function checkInstanceUpdateStatus() { | ||
try { | ||
const response = await fetch('/commits.atom'); | ||
const text = await response.text(); | ||
const parser = new DOMParser(); | ||
const xmlDoc = parser.parseFromString(text, "application/xml"); | ||
const entries = xmlDoc.getElementsByTagName('entry'); | ||
const localCommit = document.getElementById('git_commit').dataset.value; | ||
|
||
let statusMessage = ''; | ||
|
||
if (entries.length > 0) { | ||
const commitHashes = Array.from(entries).map(entry => { | ||
const id = entry.getElementsByTagName('id')[0].textContent; | ||
return id.split('/').pop(); | ||
}); | ||
|
||
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters