Add /version/history endpoint to API.

Retrieves Git tag annotations.
This commit is contained in:
D. Berge
2025-07-26 10:58:42 +02:00
parent 5487a3a49b
commit a58cce8565
5 changed files with 62 additions and 2 deletions

View File

@@ -103,6 +103,42 @@ async function describe () {
});
}
/** Return version history, from git tags
*
*/
async function history (count=5, lines=15) {
return new Promise( (resolve, reject) => {
const separator2 = String(Math.random()).substring(2)+String(Math.random()).substring(2);
const separator1 = separator2.repeat(2);
const cmd = `for tag in $(git tag --sort=-version:refname |head -n ${count}); do printf "\n${separator1}\n"; echo "$tag"; printf "\n${separator2}\n"; git --no-pager tag -n${lines} "$tag"; done`;
exec(cmd, {cwd: __dirname}, (error, stdout, stderr) => {
if (error) {
reject(error);
}
if (stdout) {
const result = stdout
.split(separator1) // Separate each tag
.map(i => i.trim()) // Trim spaces
.filter(i => i) // Filter empty lines
.map(i => i // Now for each tag…
.split(separator2) // …separate the tag from the description
.map(i => i.trim()) // trim spaces in both
.filter( i => i) // and remove empty lines
)
resolve(Object.fromEntries(result));
// resolve(result.map( ([k, v]) => ({tag: k, notes: v}) ));
} else {
// Most likely not installed from Git, use the
// version number in package.json.
resolve()
}
})
});
}
function version_old () {
return pkg.version;
}
@@ -132,5 +168,6 @@ async function version () {
version.compatible = compatible;
version.name = app_name;
version.describe = describe;
version.history = history;
module.exports = version;