Repository: octokit/webhooks.js
Pull request #519 (2021-03-30 14:36:59)

fix: use `options.onUnhandledRequest` in `createNodeMiddleware(webhooks, options)`


Patch:
diff --git a/README.md b/README.md
index a6bd9be..28dbc77 100644
--- a/README.md
+++ b/README.md
@@ -646,6 +646,8 @@ If there are actions for a webhook, events are emitted for both, the webhook nam
 | [`deploy_key`](https://developer.github.com/v3/activity/events/types/#deploykeyevent)                                        | `created`<br>`deleted`                                                                                                                                                                                                                                                                               |
 | [`deployment`](https://developer.github.com/v3/activity/events/types/#deploymentevent)                                       | `created`                                                                                                                                                                                                                                                                                            |
 | [`deployment_status`](https://developer.github.com/v3/activity/events/types/#deploymentstatusevent)                          | `created`                                                                                                                                                                                                                                                                                            |
+| [`discussion`](https://developer.github.com/v3/activity/events/types/#discussionevent)                                       | `answered`<br>`category_changed`<br>`created`<br>`deleted`<br>`edited`<br>`locked`<br>`pinned`<br>`transfered`<br>`unanswered`<br>`unlocked`<br>`unpinned`                                                                                                                                           |
+| [`discussion_comment`](https://developer.github.com/v3/activity/events/types/#discussioncommentevent)                        | `created`<br>`deleted`<br>`edited`                                                                                                                                                                                                                                                                   |
 | [`fork`](https://developer.github.com/v3/activity/events/types/#forkevent)                                                   |                                                                                                                                                                                                                                                                                                      |
 | [`github_app_authorization`](https://developer.github.com/v3/activity/events/types/#githubappauthorizationevent)             | `revoked`                                                                                                                                                                                                                                                                                            |
 | [`gollum`](https://developer.github.com/v3/activity/events/types/#gollumevent)                                               |                                                                                                                                                                                                                                                                                                      |
diff --git a/package-lock.json b/package-lock.json
index a75de9b..fec42b7 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1629,9 +1629,9 @@
       }
     },
     "@octokit/webhooks-definitions": {
-      "version": "3.65.5",
-      "resolved": "https://registry.npmjs.org/@octokit/webhooks-definitions/-/webhooks-definitions-3.65.5.tgz",
-      "integrity": "sha512-cQxHFYIrOHINEaw/dE8qrZKCmrJ7h8OOj8ZKeMq9KtP9ueBr9VdHKddbG4OMYEVHtylGSlGsvYT6GZBPYJe8OQ=="
+      "version": "3.66.0",
+      "resolved": "https://registry.npmjs.org/@octokit/webhooks-definitions/-/webhooks-definitions-3.66.0.tgz",
+      "integrity": "sha512-M9yDSBPd2KfevwMv2zdarpVyaQXJAEi6h71Bx8cnG0Zdl7pgx8SVMGeUUIY0dPmYPwl9IGzT8OphFwb2q0A9QQ=="
     },
     "@pika/babel-plugin-esm-import-rewrite": {
       "version": "0.6.1",
diff --git a/package.json b/package.json
index 339e485..8515736 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,7 @@
   "prettier": {},
   "dependencies": {
     "@octokit/request-error": "^2.0.2",
-    "@octokit/webhooks-definitions": "3.65.5",
+    "@octokit/webhooks-definitions": "3.66.0",
     "aggregate-error": "^3.1.0",
     "debug": "^4.0.0"
   },
diff --git a/src/generated/webhook-names.ts b/src/generated/webhook-names.ts
index 772d052..c1b216f 100644
--- a/src/generated/webhook-names.ts
+++ b/src/generated/webhook-names.ts
@@ -31,6 +31,22 @@ export const emitterEventNames = [
   "deployment.created",
   "deployment_status",
   "deployment_status.created",
+  "discussion",
+  "discussion.answered",
+  "discussion.category_changed",
+  "discussion.created",
+  "discussion.deleted",
+  "discussion.edited",
+  "discussion.locked",
+  "discussion.pinned",
+  "discussion.transfered",
+  "discussion.unanswered",
+  "discussion.unlocked",
+  "discussion.unpinned",
+  "discussion_comment",
+  "discussion_comment.created",
+  "discussion_comment.deleted",
+  "discussion_comment.edited",
   "fork",
   "github_app_authorization",
   "github_app_authorization.revoked",
diff --git a/src/middleware/node/middleware.ts b/src/middleware/node/middleware.ts
index 499a1c7..106e95d 100644
--- a/src/middleware/node/middleware.ts
+++ b/src/middleware/node/middleware.ts
@@ -5,7 +5,6 @@ import { WebhookEventName } from "@octokit/webhooks-definitions/schema";
 import { Webhooks } from "../../index";
 import { WebhookEventHandlerError } from "../../types";
 import { MiddlewareOptions } from "./types";
-import { onUnhandledRequestDefault } from "./on-unhandled-request-default";
 import { getMissingHeaders } from "./get-missing-headers";
 import { getPayload } from "./get-payload";
 
@@ -21,8 +20,7 @@ export async function middleware(
   const isUnknownRoute = request.method !== "POST" || pathname !== options.path;
   const isExpressMiddleware = typeof next === "function";
   if (!isExpressMiddleware && isUnknownRoute) {
-    options.log.debug(`not found: ${request.method} ${request.url}`);
-    return onUnhandledRequestDefault(request, response);
+    return options.onUnhandledRequest(request, response);
   }
 
   const missingHeaders = getMissingHeaders(request).join(", ");


Test patch:
diff --git a/test/integration/node-middleware.test.ts b/test/integration/node-middleware.test.ts
index 737bbff..fcf9ae1 100644
--- a/test/integration/node-middleware.test.ts
+++ b/test/integration/node-middleware.test.ts
@@ -154,6 +154,43 @@ describe("createNodeMiddleware(webhooks)", () => {
     server.close();
   });
 
+  test("custom non-found handler", async () => {
+    const webhooks = new Webhooks({
+      secret: "mySecret",
+    });
+
+    const server = createServer(
+      createNodeMiddleware(webhooks, {
+        onUnhandledRequest(_request, response) {
+          response.writeHead(404);
+          response.end("nope");
+        },
+      })
+    ).listen();
+
+    // @ts-expect-error complains about { port } although it's included in returned AddressInfo interface
+    const { port } = server.address();
+
+    const response = await fetch(
+      `http://localhost:${port}/api/github/webhooks`,
+      {
+        method: "PUT",
+        headers: {
+          "X-GitHub-Delivery": "123e4567-e89b-12d3-a456-426655440000",
+          "X-GitHub-Event": "push",
+          "X-Hub-Signature-256": signatureSha256,
+        },
+        body: "invalid",
+      }
+    );
+
+    expect(response.status).toEqual(404);
+
+    await expect(response.text()).resolves.toEqual("nope");
+
+    server.close();
+  });
+
   test("Handles missing headers", async () => {
     const webhooks = new Webhooks({
       secret: "mySecret",