previewDeploy: private Repos per Token klonen (authedCloneUrl)

Anonymer git clone scheiterte bei privaten Gitea-Repos
("could not read Username"). Clone nutzt jetzt config.gitea.apiToken
via oauth2-Basic-Auth; Token wird aus Fehlermeldungen maskiert.
This commit is contained in:
webklar
2026-07-12 20:49:56 +00:00
parent b6f5ea11ec
commit 943c6307c8

View File

@@ -55,18 +55,43 @@ export function defaultPreviewConfig(repoFullName) {
}
}
async function cloneRepo(cloneUrl, targetDir, branch) {
/**
* Baut aus einer Gitea-Clone-URL eine authentifizierte URL, damit auch PRIVATE
* Repos geklont werden koennen. Ohne Token bleibt die URL unveraendert (anonymer
* Clone fuer oeffentliche Repos).
*/
function authedCloneUrl(cloneUrl, token) {
if (!token) return cloneUrl
try {
const u = new URL(cloneUrl)
u.username = 'oauth2'
u.password = token
return u.toString()
} catch {
return cloneUrl
}
}
async function cloneRepo(cloneUrl, targetDir, branch, token = '') {
await fs.rm(targetDir, { recursive: true, force: true })
await fs.mkdir(targetDir, { recursive: true })
await execFileAsync('git', [
'clone',
'--depth',
'1',
'--branch',
branch,
cloneUrl,
targetDir,
])
try {
await execFileAsync('git', [
'clone',
'--depth',
'1',
'--branch',
branch,
authedCloneUrl(cloneUrl, token),
targetDir,
])
} catch (err) {
// Token niemals in Logs/Fehlermeldungen durchreichen.
if (token && err && typeof err.message === 'string') {
err.message = err.message.split(token).join('***')
}
throw err
}
}
async function deployStatic(sourceDir, targetDir, indexSubdir = '') {
@@ -233,7 +258,7 @@ export async function runDeploy(repoFullName, branch, previewConfig) {
const workDir = path.join(process.cwd(), 'preview-data', repoFullName.replace(/\//g, '_'))
const targetDir = path.join(config.preview.deployRoot, subdomain)
await cloneRepo(cloneUrl, workDir, branch)
await cloneRepo(cloneUrl, workDir, branch, config.gitea.apiToken)
if (previewConfig.type === 'node_build') {
await deployNodeBuild(workDir, targetDir)