mirror of
https://github.com/github/codeql-action.git
synced 2025-12-27 01:30:10 +08:00
38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
import { emitterEventNames } from "../generated/webhook-names.js";
|
|
function handleEventHandlers(state, webhookName, handler) {
|
|
if (!state.hooks[webhookName]) {
|
|
state.hooks[webhookName] = [];
|
|
}
|
|
state.hooks[webhookName].push(handler);
|
|
}
|
|
function receiverOn(state, webhookNameOrNames, handler) {
|
|
if (Array.isArray(webhookNameOrNames)) {
|
|
webhookNameOrNames.forEach(
|
|
(webhookName) => receiverOn(state, webhookName, handler)
|
|
);
|
|
return;
|
|
}
|
|
if (["*", "error"].includes(webhookNameOrNames)) {
|
|
const webhookName = webhookNameOrNames === "*" ? "any" : webhookNameOrNames;
|
|
const message = `Using the "${webhookNameOrNames}" event with the regular Webhooks.on() function is not supported. Please use the Webhooks.on${webhookName.charAt(0).toUpperCase() + webhookName.slice(1)}() method instead`;
|
|
throw new Error(message);
|
|
}
|
|
if (!emitterEventNames.includes(webhookNameOrNames)) {
|
|
state.log.warn(
|
|
`"${webhookNameOrNames}" is not a known webhook name (https://developer.github.com/v3/activity/events/types/)`
|
|
);
|
|
}
|
|
handleEventHandlers(state, webhookNameOrNames, handler);
|
|
}
|
|
function receiverOnAny(state, handler) {
|
|
handleEventHandlers(state, "*", handler);
|
|
}
|
|
function receiverOnError(state, handler) {
|
|
handleEventHandlers(state, "error", handler);
|
|
}
|
|
export {
|
|
receiverOn,
|
|
receiverOnAny,
|
|
receiverOnError
|
|
};
|