Skip to content

Commit

Permalink
feat: deprecate createWebhooksApi() (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy1339 committed Mar 28, 2021
1 parent f5f55b6 commit f8f3d15
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ class Webhooks<TTransformed> {
}
}

const createWebhooksApi = Webhooks.prototype.constructor;
/** @deprecated `createWebhooksApi()` is deprecated and will be removed in a future release of `@octokit/webhooks`, please use the `Webhooks` class instead */
const createWebhooksApi = <TTransformed>(options: Options<TTransformed>) => {
console.error(
"[@octokit/webhooks] `createWebhooksApi()` is deprecated and will be removed in a future release of `@octokit/webhooks`, please use the `Webhooks` class instead"
);
return new Webhooks<TTransformed>(options);
};

export {
createEventHandler,
Expand Down
6 changes: 0 additions & 6 deletions test/typescript-validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Webhooks,
createEventHandler,
createMiddleware,
createWebhooksApi,
sign,
verify,
EmitterWebhookEvent,
Expand Down Expand Up @@ -78,11 +77,6 @@ export default async function () {
},
});

// Check named exports of new API work
createWebhooksApi({
secret: "blah",
});

createEventHandler({ secret: "blah" });

createMiddleware({
Expand Down
12 changes: 12 additions & 0 deletions test/unit/deprecation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createWebhooksApi } from "../../src";

describe("Deprecated methods", () => {
test("createWebhooksApi", () => {
const spy = jest.spyOn(console, "error");
createWebhooksApi({ secret: "foo" });
expect(spy).toBeCalledWith(
"[@octokit/webhooks] `createWebhooksApi()` is deprecated and will be removed in a future release of `@octokit/webhooks`, please use the `Webhooks` class instead"
);
spy.mockClear();
});
});

0 comments on commit f8f3d15

Please sign in to comment.