Feature 2: Commit-Feed — Gitea-Webhook, Discord-Embeds, SQLite-Archiv
- Fastify-Webserver mit /health und /webhooks/gitea (HMAC-SHA256-Signaturprüfung, timing-safe) - Push-Commits werden in SQLite gespeichert (Dedupe per SHA) und als Embed gepostet - Dockerfile auf node:22-slim (glibc-Prebuilds für better-sqlite3), Port 3080 published - README: Anleitung für Cloudflare-DNS, Nginx Proxy Manager (bot.d4rkst3r.de) und Gitea-Webhook Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// SQLite-Anbindung (better-sqlite3, synchron & schnell) — Schema wird beim Start angelegt
|
||||
import Database from 'better-sqlite3';
|
||||
import { mkdirSync } from 'node:fs';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import { config } from './config.js';
|
||||
|
||||
const dbFile = resolve(config.dbPath);
|
||||
mkdirSync(dirname(dbFile), { recursive: true });
|
||||
|
||||
export const db = new Database(dbFile);
|
||||
db.pragma('journal_mode = WAL');
|
||||
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS commits (
|
||||
sha TEXT PRIMARY KEY,
|
||||
repo TEXT NOT NULL,
|
||||
branch TEXT NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
author_name TEXT,
|
||||
author_user TEXT,
|
||||
url TEXT,
|
||||
committed_at TEXT NOT NULL,
|
||||
received_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_commits_repo_time ON commits (repo, committed_at DESC);
|
||||
`);
|
||||
|
||||
const insertCommit = db.prepare(`
|
||||
INSERT OR IGNORE INTO commits (sha, repo, branch, message, author_name, author_user, url, committed_at)
|
||||
VALUES (@sha, @repo, @branch, @message, @author_name, @author_user, @url, @committed_at)
|
||||
`);
|
||||
|
||||
/** Commits eines Pushes speichern — bereits bekannte SHAs werden ignoriert. Gibt Anzahl neuer Zeilen zurück. */
|
||||
export const saveCommits = db.transaction((commits) => {
|
||||
let inserted = 0;
|
||||
for (const commit of commits) {
|
||||
inserted += insertCommit.run(commit).changes;
|
||||
}
|
||||
return inserted;
|
||||
});
|
||||
Reference in New Issue
Block a user