Ungültiges Forgejo-Token automatisch erneuern
This commit is contained in:
1 parent
712acdf2e5
commit
1062890099
2 files changed
+6
-5
No files matched your search
@@ -56,18 +56,18 @@ export async function forgejoUp() {
|
||||
"--password", FORGEJO_PASSWORD, "--email", "renovate@localhost", "--must-change-password=false");
|
||||
}
|
||||
|
||||
// Token wiederverwenden, solange Forgejo es kennt (nach Neuaufsetzen von Forgejo ist es ungültig)
|
||||
const tokenFile = path.join(STATE_DIR, "token");
|
||||
if (!fs.existsSync(tokenFile) || !fs.readFileSync(tokenFile, "utf8").trim()) {
|
||||
let token = fs.existsSync(tokenFile) ? fs.readFileSync(tokenFile, "utf8").trim() : "";
|
||||
if (!token || !(await fetch(`${FORGEJO_URL}/api/v1/user`, { headers: { Authorization: `token ${token}` } })).ok) {
|
||||
log("Erzeuge Access-Token");
|
||||
const token = forgejoCli("admin", "user", "generate-access-token", "--username", FORGEJO_USER,
|
||||
token = forgejoCli("admin", "user", "generate-access-token", "--username", FORGEJO_USER,
|
||||
"--token-name", `renovate-${Date.now()}`, "--scopes", "all", "--raw").trim();
|
||||
fs.writeFileSync(tokenFile, token);
|
||||
}
|
||||
const token = fs.readFileSync(tokenFile, "utf8").trim();
|
||||
const headers = { Authorization: `token ${token}`, "Content-Type": "application/json" };
|
||||
|
||||
const repoRes = await fetch(`${FORGEJO_URL}/api/v1/repos/${FORGEJO_USER}/${FORGEJO_REPO}`, { headers });
|
||||
if (repoRes.status === 401) throw new Error(`Token ungültig – ${tokenFile} löschen und erneut starten`);
|
||||
if (!repoRes.ok) {
|
||||
log(`Lege Repository ${FORGEJO_USER}/${FORGEJO_REPO} an`);
|
||||
const res = await fetch(`${FORGEJO_URL}/api/v1/user/repos`, {
|
||||
|
||||
Reference in new issue
Block a user