Files
2026-10-01 10:10:39 +00:00

34 lines
1.2 KiB
JavaScript

// Neubau einer Preview/Live-Seite anstossen (WOMS-Preview-Block, Website-Analyse ein/aus)
import { getRepoInfo } from './giteaAdmin.js'
import { runDeploy, fetchPreviewConfig } from './previewDeploy.js'
const BUSY = 'Server ausgelastet, versuche es gleich noch mal'
export async function previewBranchOf(doc) {
return doc.previewBranch || (await getRepoInfo(doc.repoFullName).catch(() => null))?.defaultBranch || 'main'
}
// Neubau anstossen (wie beim Bearbeiten/Reaktivieren eines Projekts)
export async function triggerRebuild(doc) {
const repo = doc.repoFullName
const branch = await previewBranchOf(doc)
const found = await fetchPreviewConfig(repo, branch).catch(() => null)
const cfg = {
enabled: true,
type: 'static',
displayName: doc.projectName,
...(found || {}),
branch,
subdomain: doc.subdomain,
}
const result = await runDeploy(repo, branch, cfg, { project: doc })
// runDeploy meldet Runner-Fehler im Ergebnis; Schutzschalter (503) an WOMS durchreichen
if (result?.error && /Server ausgelastet/.test(result.error)) {
const err = new Error(BUSY)
err.status = 503
err.expected = true
throw err
}
return result
}