Files
d4rkbot/tools/test-webhook.mjs
T
D4rkst3randClaude Opus 4.8 1ed50a6561 Portainer-Deployment: Env-Interpolation statt env_file, lokales Webhook-Test-Skript
- docker-compose.yml: Variablen per Interpolation (lokal aus .env, in Portainer aus Stack-Env)
- tools/test-webhook.mjs: signierte Fake-Testzustellung gegen die lokale Instanz
- README: Portainer-Anleitung präzisiert (Git-Auth für privates Repo, Pull and redeploy)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 23:43:24 +02:00

49 lines
1.5 KiB
JavaScript

// 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());