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,45 @@
|
||||
// Baut aus einem Gitea-Push ein hübsches Embed und postet es in den Commit-Kanal
|
||||
import { EmbedBuilder } from 'discord.js';
|
||||
import { config } from '../config.js';
|
||||
|
||||
const GITEA_GREEN = 0x609926;
|
||||
const MAX_COMMITS_SHOWN = 10;
|
||||
|
||||
/** Erste Zeile der Commit-Message, auf maxLen gekürzt */
|
||||
function firstLine(message, maxLen = 72) {
|
||||
const line = message.split('\n')[0].trim();
|
||||
return line.length > maxLen ? `${line.slice(0, maxLen - 1)}…` : line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push-Embed in den Commit-Kanal posten.
|
||||
* @param {import('discord.js').Client} client
|
||||
* @param {{ repo: string, repoUrl: string, branch: string, compareUrl: string|null,
|
||||
* pusherName: string, pusherAvatar: string|null,
|
||||
* commits: Array<{sha: string, message: string, url: string, author_name: string}> }} push
|
||||
*/
|
||||
export async function postPushEmbed(client, push) {
|
||||
const channel = await client.channels.fetch(config.commitChannelId);
|
||||
if (!channel?.isTextBased()) {
|
||||
throw new Error(`Commit-Kanal ${config.commitChannelId} nicht gefunden oder kein Textkanal`);
|
||||
}
|
||||
|
||||
const count = push.commits.length;
|
||||
const lines = push.commits.slice(0, MAX_COMMITS_SHOWN).map(
|
||||
(c) => `[\`${c.sha.slice(0, 7)}\`](${c.url}) ${firstLine(c.message)} — ${c.author_name}`
|
||||
);
|
||||
if (count > MAX_COMMITS_SHOWN) {
|
||||
lines.push(`… und ${count - MAX_COMMITS_SHOWN} weitere`);
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(GITEA_GREEN)
|
||||
.setAuthor({ name: push.pusherName, iconURL: push.pusherAvatar ?? undefined })
|
||||
.setTitle(`📦 ${count} ${count === 1 ? 'neuer Commit' : 'neue Commits'} in ${push.repo}`)
|
||||
.setURL(push.compareUrl || push.repoUrl)
|
||||
.setDescription(lines.join('\n'))
|
||||
.setFooter({ text: `Branch: ${push.branch}` })
|
||||
.setTimestamp();
|
||||
|
||||
await channel.send({ embeds: [embed] });
|
||||
}
|
||||
Reference in New Issue
Block a user