fix(notifications): apply the channel overrides set from Discord
`/notify set` stores the types listed in `NOTIFICATION_TYPES` (`releases`, `commits`, `pull_requests`) while the webhook handler looks them up under the Gitea event names (`release`, `push`, `pull_request`), so an override chosen from Discord was never found and the environment default always won. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 file changed
+19
-3
@@ -16,17 +16,33 @@ const defaultChannels = {
|
|||||||
community: env.channels.logs,
|
community: env.channels.logs,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `/notify` and the dashboard name the types after `NOTIFICATION_TYPES`, while the
|
||||||
|
* webhook handler names them after the Gitea event. Both spellings must resolve to
|
||||||
|
* the same channel, otherwise an override set from Discord is never applied (M9-T01).
|
||||||
|
*/
|
||||||
|
const TYPE_ALIASES = Object.freeze({
|
||||||
|
pull_request: 'pull_requests',
|
||||||
|
pull_requests: 'pull_request',
|
||||||
|
push: 'commits',
|
||||||
|
commits: 'push',
|
||||||
|
release: 'releases',
|
||||||
|
releases: 'release',
|
||||||
|
});
|
||||||
|
|
||||||
/** SQLite override first, then the environment default (M9-T01). */
|
/** SQLite override first, then the environment default (M9-T01). */
|
||||||
export function resolveChannelId(type, guildId = env.discord.guildId) {
|
export function resolveChannelId(type, guildId = env.discord.guildId) {
|
||||||
try {
|
try {
|
||||||
if (guildId) {
|
if (guildId) {
|
||||||
const override = getNotificationChannel(guildId, type);
|
for (const candidate of [type, TYPE_ALIASES[type]].filter(Boolean)) {
|
||||||
if (override?.channel_id) return override.channel_id;
|
const override = getNotificationChannel(guildId, candidate);
|
||||||
|
if (override?.channel_id) return override.channel_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// The database is unavailable (tests, early startup): use the environment.
|
// The database is unavailable (tests, early startup): use the environment.
|
||||||
}
|
}
|
||||||
return defaultChannels[type] ?? null;
|
return defaultChannels[type] ?? defaultChannels[TYPE_ALIASES[type]] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sends a notification payload to the channel configured for its type (M9). */
|
/** Sends a notification payload to the channel configured for its type (M9). */
|
||||||
|
|||||||
Reference in new issue
Block a user