Releases from git tags and WHATS-NEW.md; docs, changelog (1.4.0)
The Hub reads the Cross Events repo's v* tags (each a release, the newest the latest version) and the client notes from WHATS-NEW.md as of the newest tag, every 15 minutes and on Sync now. Urgent/security in a version heading marks it urgent. Repo address, notes path and an optional encrypted token on the Releases page; manual releases only when no repo is set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ const licenceToken = require('../utils/licenceToken');
|
||||
const { smtpConfigured, testSmtp } = require('../utils/mail');
|
||||
const { VERSION_RE, sortReleases, syncLatestVersion } = require('../utils/releases');
|
||||
const { emailNotice } = require('../utils/notices');
|
||||
const { parseRepoUrl, syncReleases } = require('../utils/releaseSync');
|
||||
|
||||
const router = express.Router();
|
||||
router.use(protect);
|
||||
@@ -21,7 +22,7 @@ const smtpTestLimiter = rateLimit({ windowMs: 15 * 60 * 1000, max: 10, standardH
|
||||
const wrap = fn => (req, res) => fn(req, res).catch(e => {
|
||||
const status = e.status || 500;
|
||||
if (status >= 500) console.error('[admin]', e);
|
||||
res.status(status).json({ message: status >= 500 ? 'Something went wrong.' : e.message });
|
||||
res.status(status).json({ message: status >= 500 && !e.status ? 'Something went wrong.' : e.message });
|
||||
});
|
||||
const bad = (message, status = 400) => Object.assign(new Error(message), { status });
|
||||
const text = (v, max = 500) => (v == null || String(v).trim() === '' ? null : String(v).trim().slice(0, max));
|
||||
@@ -228,7 +229,8 @@ router.get('/audit', wrap(async (req, res) => {
|
||||
|
||||
// ─── Releases ─────────────────────────────────────────────────────────────────
|
||||
// What's new in each Cross Events version. Installs on an older version see the notes; the highest
|
||||
// version is the latest (latest_version), so adding one tells installs an update is out.
|
||||
// version is the latest (latest_version), so adding one tells installs an update is out. With a git
|
||||
// repository set (Releases page), releases come from its tags and WHATS-NEW.md only.
|
||||
|
||||
router.get('/releases', wrap(async (req, res) => {
|
||||
const [releases, installs] = await Promise.all([
|
||||
@@ -253,6 +255,22 @@ function releaseData(body, { partial = false } = {}) {
|
||||
return data;
|
||||
}
|
||||
|
||||
async function manualReleases() {
|
||||
if (parseRepoUrl((await getSettings()).release_repo_url)) throw bad('Releases come from git: tag the version and edit WHATS-NEW.md, then Sync now.');
|
||||
}
|
||||
|
||||
router.post('/releases/sync', wrap(async (req, res) => {
|
||||
if (!parseRepoUrl((await getSettings()).release_repo_url)) throw bad('Set the git repository first.');
|
||||
let result;
|
||||
try {
|
||||
result = await syncReleases();
|
||||
} catch (e) {
|
||||
throw bad(e.message, 502);
|
||||
}
|
||||
await audit(req, 'releases_synced', null, result);
|
||||
res.json(result);
|
||||
}));
|
||||
|
||||
const releaseError = e => {
|
||||
if (e.code === 'P2002') throw bad('There is already a release with that version.', 409);
|
||||
if (e.code === 'P2025') throw bad('Release not found', 404);
|
||||
@@ -260,6 +278,7 @@ const releaseError = e => {
|
||||
};
|
||||
|
||||
router.post('/releases', wrap(async (req, res) => {
|
||||
await manualReleases();
|
||||
const release = await prisma.release.create({ data: releaseData(req.body) }).catch(releaseError);
|
||||
const latest = await syncLatestVersion();
|
||||
await audit(req, 'release_added', release.id, { version: release.version, urgent: release.urgent });
|
||||
@@ -267,6 +286,7 @@ router.post('/releases', wrap(async (req, res) => {
|
||||
}));
|
||||
|
||||
router.put('/releases/:id', wrap(async (req, res) => {
|
||||
await manualReleases();
|
||||
const data = releaseData(req.body, { partial: true });
|
||||
const release = await prisma.release.update({ where: { id: req.params.id }, data }).catch(releaseError);
|
||||
const latest = await syncLatestVersion();
|
||||
@@ -275,6 +295,7 @@ router.put('/releases/:id', wrap(async (req, res) => {
|
||||
}));
|
||||
|
||||
router.delete('/releases/:id', wrap(async (req, res) => {
|
||||
await manualReleases();
|
||||
const release = await prisma.release.delete({ where: { id: req.params.id } }).catch(releaseError);
|
||||
const latest = await syncLatestVersion();
|
||||
await audit(req, 'release_deleted', release.id, { version: release.version });
|
||||
@@ -365,16 +386,20 @@ function checkSmtp(values) {
|
||||
|
||||
// What the audit log records: never the password, only that it changed.
|
||||
function auditValues(values) {
|
||||
const { smtp_pass, smtp_pass_clear, ...rest } = values;
|
||||
const { smtp_pass, smtp_pass_clear, release_repo_token, release_repo_token_clear, ...rest } = values;
|
||||
if (smtp_pass_clear) rest.smtp_pass = '(removed)';
|
||||
else if (smtp_pass) rest.smtp_pass = '(changed)';
|
||||
if (release_repo_token_clear) rest.release_repo_token = '(removed)';
|
||||
else if (release_repo_token) rest.release_repo_token = '(changed)';
|
||||
return rest;
|
||||
}
|
||||
|
||||
router.put('/settings', wrap(async (req, res) => {
|
||||
// The latest version follows the Releases page.
|
||||
// The latest version follows the Releases page; the sync writes its own status.
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const { latest_version, ...values } = req.body?.settings || {};
|
||||
const { latest_version, release_synced_at, release_sync_error, ...values } = req.body?.settings || {};
|
||||
if (values.release_repo_url && !parseRepoUrl(values.release_repo_url)) throw bad('The repository address looks like https://git.example.com/owner/repo.');
|
||||
if (values.release_notes_path != null && !String(values.release_notes_path).trim()) values.release_notes_path = 'WHATS-NEW.md';
|
||||
checkSmtp(values);
|
||||
const settings = await setSettings(values);
|
||||
await audit(req, 'settings_updated', null, auditValues(values));
|
||||
|
||||
Reference in New Issue
Block a user