Skip to content

Commit

Permalink
Update webhook if events don't match (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinFigueroa authored and billimek committed Oct 7, 2019
1 parent bdab2d6 commit c27e45e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bin/out
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}`;

Expand Down

0 comments on commit c27e45e

Please sign in to comment.