Analyse: Runner-Auftrag
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
813c56e6a4
commit
62f196f705
2 files changed
+110
-3
No files matched your search
@@ -3,7 +3,8 @@ import { promisify } from 'node:util'
|
||||
import fs from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
import { config } from '../config.js'
|
||||
import { listDocuments, updateDocument, Query } from './appwriteAdmin.js'
|
||||
import { listDocuments, updateDocument, getDocument, Query } from './appwriteAdmin.js'
|
||||
import { getFeatureDoc } from './siteFeatures.js'
|
||||
import { withLocks } from './keyedLock.js'
|
||||
import { giteaFetch, splitRepo } from './giteaClient.js'
|
||||
import { envKey, decryptEnv, maskLog } from './previewEnv.js'
|
||||
@@ -669,7 +670,7 @@ async function followRun({ repoFullName, project, token, runId, subdomain, job,
|
||||
}
|
||||
if (run.result === 'dev') {
|
||||
await patchProject(repoFullName, project, { ...base, previewState: 'sleeping' })
|
||||
try { await runnerClient.startDev(subdomain, { ...job, mode: 'dev', displayName: undefined }) } catch (err) {
|
||||
try { await runnerClient.startDev(subdomain, { ...job, mode: 'dev', displayName: undefined, analytics: undefined }) } catch (err) {
|
||||
console.error('[previewDeploy] Dev-Registrierung fehlgeschlagen:', err.message)
|
||||
}
|
||||
} else {
|
||||
@@ -696,6 +697,36 @@ async function followRun({ repoFullName, project, token, runId, subdomain, job,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyse-Feld fuer den Build-Auftrag: nur bei aktiver Funktion 'analyse', oeffentlichem Projekt mit Subdomain
|
||||
* und vollstaendigen Datenschutz-Angaben (Firma + E-Mail Pflicht, Adresse optional). Sonst null.
|
||||
* Wirft nie: der Build darf an der Analyse nicht scheitern.
|
||||
*/
|
||||
async function buildAnalytics(project) {
|
||||
try {
|
||||
if (!project?.$id || project.isPublic !== true || !project.subdomain || !project.customerId) return null
|
||||
const feature = await getFeatureDoc(project.customerId, project.$id, 'analyse')
|
||||
if (!feature || feature.state !== 'active' || !feature.siteKey) return null
|
||||
let customer = null
|
||||
try {
|
||||
customer = await getDocument(config.collections.customers, project.customerId)
|
||||
} catch (err) {
|
||||
if (err.status !== 404) throw err
|
||||
}
|
||||
const company = String(customer?.companyName || customer?.name || '').trim()
|
||||
const email = String(customer?.email || '').trim()
|
||||
if (!company || !email) {
|
||||
console.warn(`[previewDeploy] Analyse fuer Projekt ${project.$id} uebersprungen: Firma oder E-Mail fehlt`)
|
||||
return null
|
||||
}
|
||||
const address = [String(customer.street || '').trim(), `${customer.postalCode || ''} ${customer.city || ''}`.trim()].filter(Boolean).join(', ')
|
||||
return { siteKey: feature.siteKey, color: feature.accentColor || '#111111', privacy: { company, address, email } }
|
||||
} catch (err) {
|
||||
console.warn(`[previewDeploy] Analyse-Abfrage fuer Projekt ${project?.$id} fehlgeschlagen: ${err.message}`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function runDeployViaRunner(repoFullName, branch, previewConfig, { project, sha } = {}) {
|
||||
const subdomain = previewConfig.subdomain || repoFullName.split('/').pop()
|
||||
// Platz fuer diesen Aufruf sofort belegen (vor jedem await): aeltere Verfolger scheiden aus
|
||||
@@ -736,6 +767,7 @@ async function runDeployViaRunner(repoFullName, branch, previewConfig, { project
|
||||
...(previewConfig.index ? { index: previewConfig.index } : {}),
|
||||
...(displayName ? { displayName } : {}),
|
||||
env,
|
||||
analytics: await buildAnalytics(doc),
|
||||
}
|
||||
const { runId } = await runnerClient.submitBuild(job)
|
||||
if (current()) await patchProject(repoFullName, doc, { previewState: 'building', previewError: warning })
|
||||
|
||||
Reference in new issue
Block a user