From 401a85e1c99ab439b146b5b8af87a8c747bf10f2 Mon Sep 17 00:00:00 2001 From: Isaac Martinez Aceves <7004022+totahuanocotl@users.noreply.github.com> Date: Tue, 2 Jul 2024 21:34:15 +0100 Subject: [PATCH] Match existing hook without payload secret The exsiting hook matcher started failing for the scenario where the webhook does not define a payload_secret. It's content was set to undefined, and the _.isMatch function used to filter the hooks was returning undefined, as it didn't match any of the retrieved hooks, even when it should have. This resulted in an attempt to create the webhook, even if it exsited; github returned a 422 error. This changes the desired config, to not include the secret property if its value is undefined. With this change, the _.isMatch function is able to find the match, and correctly updates or no-ops the hook. The error returned by the resource before this changes looked like the following: ``` Error while calling Github: StatusCodeError Response Status: 422 Message: { "message": "Validation Failed", "errors": [ { "resource": "Hook", "code": "custom", "message": "Hook already exists on this repository" }, { "resource": "Hook", "code": "custom", "message": "Invalid config attribute: content-type" } ], "documentation_url": "https://docs.github.com/rest/repos/webhooks#create-a-repository-webhook", "status": "422" } ``` --- bin/out.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/out.js b/bin/out.js index 54a900b..58b31da 100755 --- a/bin/out.js +++ b/bin/out.js @@ -88,7 +88,7 @@ async function processWebhook(source, params) { const config = { 'url': url, 'content_type': params.payload_content_type ? params.payload_content_type : 'json', - 'secret': params.payload_secret + ...(params.payload_secret && {'secret': params.payload_secret}), }; const body = {