Skip to content

Commit

Permalink
fix: testing deno compatibility be removing import from "http"
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Apr 11, 2021
1 parent 38345f8 commit 662f35c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/middleware/node/get-missing-headers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { IncomingMessage } from "http";
// remove type imports from http for Deno compatibility
// see https://github.com/octokit/octokit.js/issues/24#issuecomment-817361886
// import { IncomingMessage } from "http";
type IncomingMessage = any;

const WEBHOOK_HEADERS = [
"x-github-event",
Expand Down
19 changes: 11 additions & 8 deletions src/middleware/node/get-payload.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { WebhookEvent } from "@octokit/webhooks-definitions/schema";
// @ts-ignore to address #245
import AggregateError from "aggregate-error";
import { IncomingMessage } from "http";

declare module "http" {
interface IncomingMessage {
body?: WebhookEvent;
}
}
// remove type imports from http for Deno compatibility
// see https://github.com/octokit/octokit.js/issues/24#issuecomment-817361886
// import { IncomingMessage } from "http";
// declare module "http" {
// interface IncomingMessage {
// body?: WebhookEvent | unknown;
// }
// }
type IncomingMessage = any;

export function getPayload(request: IncomingMessage): Promise<WebhookEvent> {
// If request.body already exists we can stop here
Expand All @@ -21,8 +24,8 @@ export function getPayload(request: IncomingMessage): Promise<WebhookEvent> {
request.setEncoding("utf8");

// istanbul ignore next
request.on("error", (error) => reject(new AggregateError([error])));
request.on("data", (chunk) => (data += chunk));
request.on("error", (error: Error) => reject(new AggregateError([error])));
request.on("data", (chunk: string) => (data += chunk));
request.on("end", () => {
try {
resolve(JSON.parse(data));
Expand Down
6 changes: 5 additions & 1 deletion src/middleware/node/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { IncomingMessage, ServerResponse } from "http";
// remove type imports from http for Deno compatibility
// see https://github.com/octokit/octokit.js/issues/24#issuecomment-817361886
// import { IncomingMessage, ServerResponse } from "http";
type IncomingMessage = any;
type ServerResponse = any;

import { WebhookEventName } from "@octokit/webhooks-definitions/schema";

Expand Down
6 changes: 5 additions & 1 deletion src/middleware/node/on-unhandled-request-default.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { IncomingMessage, ServerResponse } from "http";
// remove type imports from http for Deno compatibility
// see https://github.com/octokit/octokit.js/issues/24#issuecomment-817361886
// import { IncomingMessage, ServerResponse } from "http";
type IncomingMessage = any;
type ServerResponse = any;

export function onUnhandledRequestDefault(
request: IncomingMessage,
Expand Down
6 changes: 5 additions & 1 deletion src/middleware/node/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { IncomingMessage, ServerResponse } from "http";
// remove type imports from http for Deno compatibility
// see https://github.com/octokit/octokit.js/issues/24#issuecomment-817361886
// import { IncomingMessage, ServerResponse } from "http";
type IncomingMessage = any;
type ServerResponse = any;

import { Logger } from "../../createLogger";

Expand Down

0 comments on commit 662f35c

Please sign in to comment.