Skip to content

Commit

Permalink
feat: use @probot/adapter-aws-lambda-serverless (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m authored Feb 10, 2021
1 parent 6b24426 commit 46997d4
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 84 deletions.
47 changes: 8 additions & 39 deletions handler.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,10 @@
"use strict";
const {
createLambdaFunction,
createProbot,
} = require("@probot/adapter-aws-lambda-serverless");

const { createProbot } = require("probot");
const app = require("./app");
const appFn = require("./");

const probot = createProbot();
const loadingApp = probot.load(app);

module.exports.webhooks = async (event, context) => {
try {
await loadingApp;

// Ends function immediately after callback
context.callbackWaitsForEmptyEventLoop = false;

// this could will be simpler once we ship `verifyAndParse()`
// see https://github.com/octokit/webhooks.js/issues/379
await probot.webhooks.verifyAndReceive({
id:
event.headers["X-GitHub-Delivery"] ||
event.headers["x-github-delivery"],
name: event.headers["X-GitHub-Event"] || event.headers["x-github-event"],
signature:
event.headers["X-Hub-Signature-256"] ||
event.headers["x-hub-signature-256"],
payload: JSON.parse(event.body),
});

return {
statusCode: 200,
body: '{"ok":true}',
};
} catch (error) {
console.log(error);

return {
statusCode: error.status || 500,
error: "ooops",
};
}
};
module.exports.webhooks = createLambdaFunction(appFn, {
probot: createProbot(),
});
97 changes: 54 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test": "node test.js"
},
"dependencies": {
"probot": "^11.0.5"
"@probot/adapter-aws-lambda-serverless": "^2.0.0"
},
"repository": "https://github.com/probot/example-aws-lambda-serverless",
"keywords": [],
Expand Down
5 changes: 4 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const assert = require("uvu/assert");
const nock = require("nock");
nock.disableNetConnect();

const { Probot, ProbotOctokit } = require("probot");
const {
Probot,
ProbotOctokit,
} = require("@probot/adapter-aws-lambda-serverless");

const app = require("./app");

Expand Down

0 comments on commit 46997d4

Please sign in to comment.