Skip to content

Commit

Permalink
refactor: remove lib/ folder (#127)
Browse files Browse the repository at this point in the history
* πŸ“¦ refactor(index.js): move index.js from lib/ to src/
* πŸ“¦ refactor(webhook-names): move webhook-names.json from lib/ to src/
* πŸ“¦ refactor(scripts-folder): move scripts folder outside src/ (we don't want to expose it when publi
* πŸ’Ž style(path): fix redundant required path
* πŸ“– docs(README): update import paths for event-handler, middleware, sign, verify on READMEs
  • Loading branch information
oscard0m committed Apr 28, 2020
1 parent 7054d1a commit 1804f39
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 33 deletions.
13 changes: 0 additions & 13 deletions lib/index.js

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Table = require("table-builder");

const WEBOOOKS = require("@octokit/webhooks-definitions");

// update lib/webhook-names.json
// update src/webhook-names.json
const newWebhookNames = WEBOOOKS.reduce(
(list, event) => {
list.push(
Expand All @@ -16,7 +16,7 @@ const newWebhookNames = WEBOOOKS.reduce(
["*", "error"]
).sort();
writeFileSync(
"lib/webhook-names.json",
"src/webhook-names.json",
JSON.stringify([...newWebhookNames], null, 2) + "\n"
);

Expand Down
6 changes: 3 additions & 3 deletions src/event-handler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ If you implement the route to receive webhook events from GitHub yourself then y
## Example

```js
const EventHandler = require('@octokit/webhooks/event-handler')
const eventHandler = new EventHandler({
const { createEventHandler } = require('@octokit/webhooks')
const eventHandler = createEventHandler({
async transform (event) {
// optionally transform passed event before handlers are called
return event
Expand All @@ -27,7 +27,7 @@ eventHandler.receive({
If you receive events through a publicly accessible URL, make sure to verify that the event request is coming from GitHub:

```js
const verify = require('@octokit/webhooks/verify')
const { verify } = require('@octokit/webhooks')
const secret = 'mysecret'

if (!verify(secret, request.payload, request.headers['x-hub-signature'])) {
Expand Down
2 changes: 1 addition & 1 deletion src/event-handler/on.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = receiverOn;

const webhookNames = require("../../lib/webhook-names.json");
const webhookNames = require("../webhook-names.json");

function receiverOn(state, webhookNameOrNames, handler) {
if (Array.isArray(webhookNameOrNames)) {
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = deprecate(

const { createEventHandler } = require("./event-handler");
const middleware = require("./middleware/middleware");
const { createMiddleware } = require("./middleware");
const { sign } = require("./sign");
const { verify } = require("./verify");
const verifyAndReceive = require("./middleware/verify-and-receive");
Expand All @@ -33,4 +34,8 @@ function createWebhooksApi(options) {
};
}

module.exports.createEventHandler = createEventHandler;
module.exports.createMiddleware = createMiddleware;
module.exports.createWebhooksApi = createWebhooksApi;
module.exports.sign = sign;
module.exports.verify = verify;
4 changes: 2 additions & 2 deletions src/middleware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
If you only need the middleware with access to the `.sign()`, `.verify()` or the receiver’s `.receive()` method, you can use the webhooks middleware directly

```js
const Middleware = require('@octokit/webhooks/middleware')
const middleware = new Middleware({
const { createMiddleware } = require('@octokit/webhooks')
const middleware = createMiddleware({
secret: 'mysecret',
path: '/github-webhooks'
})
Expand Down
2 changes: 1 addition & 1 deletion src/sign/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The `sign` method can be used as a standalone method.

```js
const sign = require('@octokit/webhooks/sign')
const { sign } = require('@octokit/webhooks')
const signature = sign(secret, eventPayload)
// string like "sha1=d03207e4b030cf234e3447bac4d93add4c6643d8"
```
Expand Down
2 changes: 1 addition & 1 deletion src/verify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The `verify` method can be used as a standalone method.

```js
const verify = require('@octokit/webhooks/verify')
const { verify } = require('@octokit/webhooks')
const matchesSignature = verify(secret, eventData, signature)
// true or false
```
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/integration/event-handler-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require("tap").test;

const { createEventHandler } = require("../../lib");
const { createEventHandler } = require("../../src");
const pushEventPayload = require("../fixtures/push-payload");
const installationCreatedPayload = require("../fixtures/installation-created-payload");

Expand Down
2 changes: 1 addition & 1 deletion test/integration/middleware-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Buffer = require("buffer").Buffer;
const test = require("tap").test;
const simple = require("simple-mock");

const { createMiddleware } = require("../../lib");
const { createMiddleware } = require("../../src");

const headers = {
"x-github-delivery": "123e4567-e89b-12d3-a456-426655440000",
Expand Down
2 changes: 1 addition & 1 deletion test/integration/sign-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require("tap").test;

const { sign } = require("../../lib");
const { sign } = require("../../src");

const eventPayload = {
foo: "bar",
Expand Down
10 changes: 5 additions & 5 deletions test/integration/smoke-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { mock } = require("simple-mock");

test("@octokit/webhooks", (t) => {
const emitWarningMock = mock(process, "emitWarning");
const { createWebhooksApi } = require("../../lib");
const { createWebhooksApi } = require("../../src");
const api = createWebhooksApi({ secret: "mysecret" });

t.type(api.sign, "function");
Expand All @@ -22,7 +22,7 @@ test('require("@octokit/webhooks").sign', (t) => {
const emitWarningMock = mock(process, "emitWarning");

t.doesNotThrow(() => {
const { sign } = require("../../lib");
const { sign } = require("../../src");
sign("1234", {});
});
t.false(emitWarningMock.called);
Expand All @@ -34,7 +34,7 @@ test('require("@octokit/webhooks").verify', (t) => {
const emitWarningMock = mock(process, "emitWarning");

t.doesNotThrow(() => {
const { verify } = require("../../lib");
const { verify } = require("../../src");
verify("1234", {}, "randomSignature");
});
t.false(emitWarningMock.called);
Expand All @@ -46,7 +46,7 @@ test('require("@octokit/webhooks").createEventHandler', (t) => {
const emitWarningMock = mock(process, "emitWarning");

t.doesNotThrow(() => {
const { createEventHandler } = require("../../lib");
const { createEventHandler } = require("../../src");
createEventHandler();
});
t.false(emitWarningMock.called);
Expand All @@ -58,7 +58,7 @@ test('require("@octokit/webhooks).createMiddleware")', (t) => {
const emitWarningMock = mock(process, "emitWarning");

t.doesNotThrow(() => {
const { createMiddleware } = require("../../lib");
const { createMiddleware } = require("../../src");
createMiddleware({ secret: "1234" });
});
t.false(emitWarningMock.called);
Expand Down
2 changes: 1 addition & 1 deletion test/integration/verify-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require("tap").test;

const { verify } = require("../../lib");
const { verify } = require("../../src");

const eventPayload = {
foo: "bar",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/middleware-constructor-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require("tap").test;

const { createMiddleware } = require("../../lib");
const { createMiddleware } = require("../../src");

test("options: none", (t) => {
t.throws(createMiddleware);
Expand Down

0 comments on commit 1804f39

Please sign in to comment.