// Simuliert eine Gitea-Testzustellung gegen die lokale Bot-Instanz. // Nutzung: node tools/test-webhook.mjs (Bot muss laufen: npm run dev) import 'dotenv/config'; import crypto from 'node:crypto'; const secret = process.env.GITEA_WEBHOOK_SECRET; if (!secret) { console.error('GITEA_WEBHOOK_SECRET fehlt in der .env'); process.exit(1); } const port = process.env.HTTP_PORT || 3080; const url = `http://localhost:${port}/webhooks/gitea`; const sha = crypto.randomBytes(20).toString('hex'); // zufällige SHA → Dedupe greift nicht const payload = JSON.stringify({ ref: 'refs/heads/main', compare_url: 'https://git.d4rkst3r.de/D4rkst3r/EcoGame', repository: { full_name: 'D4rkst3r/EcoGame (Test)', html_url: 'https://git.d4rkst3r.de/D4rkst3r/EcoGame', }, pusher: { username: 'D4rkst3r' }, sender: { avatar_url: null }, commits: [ { id: sha, message: 'Testzustellung — wenn du das im Discord siehst, funktioniert der Commit-Feed 🎉', url: `https://git.d4rkst3r.de/D4rkst3r/EcoGame/commit/${sha}`, author: { name: 'D4rkst3r', username: 'D4rkst3r' }, timestamp: new Date().toISOString(), }, ], }); const signature = crypto.createHmac('sha256', secret).update(payload).digest('hex'); const res = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/json', 'x-gitea-event': 'push', 'x-gitea-signature': signature, }, body: payload, }); console.log(`${res.status} →`, await res.json());