Files
websitedev/scripts/cms-publish.js
T
Do Siki d2ee13bb91
CI Pipeline with Test Management / 🧪 Run Tests & Generate Reports (push) Waiting to run
CI Pipeline with Test Management / 🐳 Docker Integration Tests (push) Blocked by required conditions
CI Pipeline with Test Management / 🏗️ Build Docker Image (push) Blocked by required conditions
CI Pipeline with Test Management / 📊 Generate Test Summary (push) Blocked by required conditions
Test Reporting & Gherkin Analysis / 🧪 Run Tests & Generate Reports (push) Waiting to run
Test Reporting & Gherkin Analysis / 📊 Analyze Test Coverage (push) Blocked by required conditions
Test Reporting & Gherkin Analysis / 🔄 Sync with Linear (push) Blocked by required conditions
Test Reporting & Gherkin Analysis / ⚡ Performance Monitoring (push) Blocked by required conditions
feat(cms): logo upload with preview, backup and audit
- 🎨 Logó page in the CMS bottom bar: replace the website header logo and
  the CMS login icon with a PNG upload (magic-byte validation, 1 MiB cap)
- the replaced logo gets a timestamped backup in .content-backups; every
  upload is audited (logo_updated)
- /logo.png?variant=header serves the header variant for the preview
- publish stages proto/public too, so logo changes ride the same
  commit+deploy pipeline as content
- route handling extracted to scripts/cms-logo.js to stay under the
  400-line limit
- integration test: upload+replace+backup, variant preview, 415/413/400,
  CSRF, auth

Closes MITHOME-65
2026-08-19 12:46:55 +02:00

44 lines
1.9 KiB
JavaScript

// Publish (git commit + push) command construction and result interpretation
// for the Content Editor. Extracted so it is unit-testable in isolation.
//
// WHY the shell shape:
// - `git diff --cached --quiet && echo MARKER || git commit` — commit only when
// staged changes exist; a skipped commit must NOT produce a failing exit code
// (that was the original bug: "nothing added to commit" surfaced as an error).
// - the MARKER echo is the only reliable signal for "no content changes": plain
// output matching ("Already up to date", "Everything up-to-date") also appears
// after REAL publishes (the pull prints it when the remote did not move), which
// used to misclassify genuine publishes as no-ops.
// - `git pull --rebase || (git rebase --abort; false)` — a failed rebase must be
// aborted, otherwise the repo stays mid-rebase and every later publish fails
// with "cannot pull with rebase".
const NO_CHANGES_MARKER = '__NO_CONTENT_CHANGES__';
function buildPublishCommand(commitMessage) {
return [
'git add .',
// WHY: logo uploads live in proto/public — outside the content cwd — so
// stage them too (tolerant: optional path in test throwaway repos).
'(git add ../public || true)',
`(git diff --cached --quiet && echo ${NO_CHANGES_MARKER} || git commit -m "${commitMessage}")`,
'(git pull --rebase origin main || (git rebase --abort; false))',
'git push origin main',
].join(' && ');
}
function interpretPublishResult(error, stdout, stderr) {
const hadChanges = !stdout.includes(NO_CHANGES_MARKER);
if (error) {
return { ok: false, hadChanges, result: 'error', error: stderr || stdout || error.message };
}
return {
ok: true,
hadChanges,
result: hadChanges ? 'ok' : 'no_changes',
output: hadChanges ? stdout : 'Nincs új változtatás.',
};
}
module.exports = { NO_CHANGES_MARKER, buildPublishCommand, interpretPublishResult };