@octokit/webhooks
Version:
GitHub webhook events toolset for Node.js
34 lines (33 loc) • 1.15 kB
JavaScript
import { emitterEventNames } from "../generated/webhook-names.js";
function validateEventName(eventName, options = {}) {
if (typeof eventName !== "string") {
throw new TypeError("eventName must be of type string");
}
if (eventName === "*") {
throw new TypeError(
`Using the "*" event with the regular Webhooks.on() function is not supported. Please use the Webhooks.onAny() method instead`
);
}
if (eventName === "error") {
throw new TypeError(
`Using the "error" event with the regular Webhooks.on() function is not supported. Please use the Webhooks.onError() method instead`
);
}
if (options.onUnknownEventName === "ignore") {
return;
}
if (!emitterEventNames.includes(eventName)) {
if (options.onUnknownEventName !== "warn") {
throw new TypeError(
`"${eventName}" is not a known webhook name (https://developer.github.com/v3/activity/events/types/)`
);
} else {
(options.log || console).warn(
`"${eventName}" is not a known webhook name (https://developer.github.com/v3/activity/events/types/)`
);
}
}
}
export {
validateEventName
};