mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 08:37:07 +00:00
Add /version/history endpoint to API.
Retrieves Git tag annotations.
This commit is contained in:
@@ -83,7 +83,10 @@ app.map({
|
||||
post: [ mw.user.logout ]
|
||||
},
|
||||
'/version': {
|
||||
get: [ mw.auth.operations, mw.version.get ]
|
||||
get: [ mw.auth.operations, mw.version.get ],
|
||||
'/history': {
|
||||
get: [ /*mw.auth.user,*/ mw.version.history.get ],
|
||||
}
|
||||
},
|
||||
'/': {
|
||||
get: [ mw.openapi.get ]
|
||||
|
||||
15
lib/www/server/api/middleware/version/history/get.js
Normal file
15
lib/www/server/api/middleware/version/history/get.js
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
const version = require('../../../../lib/version');
|
||||
|
||||
module.exports = async function (req, res, next) {
|
||||
|
||||
try {
|
||||
const v = await version.history(req.query.count, req.query.lines);
|
||||
res.status(200).json(v);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
return;
|
||||
}
|
||||
next();
|
||||
|
||||
};
|
||||
4
lib/www/server/api/middleware/version/history/index.js
Normal file
4
lib/www/server/api/middleware/version/history/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
module.exports = {
|
||||
get: require('./get'),
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
|
||||
module.exports = {
|
||||
get: require('./get')
|
||||
get: require('./get'),
|
||||
history: require('./history'),
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user