Infra: write gitea git-credentials line with the deployment's own scheme

This commit is contained in:
2026-11-01 19:46:29 +08:00
parent 4379973775
commit e8b91abb2c
+4 -2
View File
@@ -31,9 +31,11 @@ async function writeGiteaCredentials(file: string, gitea: GiteaAccount,
env: Record<string, string | undefined>): Promise<void> {
const token = env[gitea.tokenEnv] ?? ''
if (!token) throw new SetupError('giteaTokenMissing', { name: gitea.tokenEnv })
const host = new URL(gitea.url).host
const origin = new URL(gitea.url).origin
const scheme = origin.slice(0, origin.indexOf('://'))
const host = origin.slice(origin.indexOf('://') + 3)
const temporary = `${file}.${process.pid}.tmp`
await writeFile(temporary, `https://${encodeURIComponent(gitea.login)}:${encodeURIComponent(token)}@${host}\n`, { mode: 0o600 })
await writeFile(temporary, `${scheme}://${encodeURIComponent(gitea.login)}:${encodeURIComponent(token)}@${host}\n`, { mode: 0o600 })
await rename(temporary, file)
}