diff --git a/bin/out b/bin/out index 3d1d826..8de8658 100755 --- a/bin/out +++ b/bin/out @@ -60,6 +60,8 @@ async function processWebhook(source, params) { case 'create': if (existingHook == null) { createWebhook(webhookEndpoint, 'POST', source.github_token, body); + } else if (existingHook.events !== body.events) { + updateWebhook(`${webhookEndpoint}/${existingHook.id}`, 'PATCH', source.github_token, body) } else { log('Webhook already exists'); emit(existingHook); @@ -95,6 +97,20 @@ function createWebhook(webhookEndpoint, method, githubToken, body) { }); } +function updateWebhook(webhookEndpoint, method, githubToken, body) { + const bodyString = JSON.stringify(body); + + callGithub(webhookEndpoint, method, githubToken, bodyString) + .then(res => { + log(`Successfully updated webhook: ${res.body}`); + emit(JSON.parse(res.body)); + }) + .catch(error => { + log(error.stack); + process.exit(1); + }); +} + function deleteWebhook(webhookEndpoint, webhook, githubToken) { const deleteUri = `${webhookEndpoint}/${webhook.id}`;