Files
freeCodeCamp/probot/presolver/node_modules/@octokit/webhooks/event-handler/on.js
2018-12-05 11:23:55 +05:30

21 lines
622 B
JavaScript

module.exports = receiverOn
const webhookNames = require('../lib/webhook-names.json')
function receiverOn (state, webhookNameOrNames, handler) {
if (Array.isArray(webhookNameOrNames)) {
webhookNameOrNames.forEach(webhookName => receiverOn(state, webhookName, handler))
return
}
if (webhookNames.indexOf(webhookNameOrNames) === -1) {
console.warn(`"${webhookNameOrNames}" is not a known webhook name (https://developer.github.com/v3/activity/events/types/)`)
}
if (!state.hooks[webhookNameOrNames]) {
state.hooks[webhookNameOrNames] = []
}
state.hooks[webhookNameOrNames].push(handler)
}