Files
FWS-DiscordBot/src/services/notifications/gitea-notifications.js
T
BlackAngelTV a5280ce205 feat(notifications): dispatch Gitea webhooks through the notification service
A guild can reroute a notification type to its own channel from SQLite, with the environment values as fallback, without editing the configuration or restarting the bot.
2026-09-15 14:50:41 +02:00

32 lines
1.0 KiB
JavaScript

import { GITEA_EVENT_TYPES } from '../../config/constants.js';
import { issueEmbed, pullRequestEmbed, pushEmbed, releaseEmbed, refEmbed } from '../gitea/gitea-embeds.js';
/**
* Maps a raw Gitea webhook to `{ type, embed }`, or returns null when the event
* should not be published (M9-T03).
*/
export function buildGiteaNotification(event, payload) {
const type = GITEA_EVENT_TYPES[event];
if (!type) return null;
switch (event) {
case 'issues':
return { type, embed: issueEmbed(payload.issue ?? payload) };
case 'pull_request':
return { type, embed: pullRequestEmbed(payload.pull_request ?? payload) };
case 'push':
if (!payload.commits?.length) return null;
return { type, embed: pushEmbed(payload) };
case 'create':
case 'delete':
return {
type,
embed: refEmbed(payload, payload.ref_type && event === 'delete' ? 'deleted' : 'created'),
};
case 'release':
return { type, embed: releaseEmbed(payload.release ?? payload) };
default:
return null;
}
}