Skip to content

Commit 46997d4

Browse files
authored
feat: use @probot/adapter-aws-lambda-serverless (#2)
1 parent 6b24426 commit 46997d4

File tree

4 files changed

+67
-84
lines changed

4 files changed

+67
-84
lines changed

Diff for: handler.js

+8-39
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,10 @@
1-
"use strict";
1+
const {
2+
createLambdaFunction,
3+
createProbot,
4+
} = require("@probot/adapter-aws-lambda-serverless");
25

3-
const { createProbot } = require("probot");
4-
const app = require("./app");
6+
const appFn = require("./");
57

6-
const probot = createProbot();
7-
const loadingApp = probot.load(app);
8-
9-
module.exports.webhooks = async (event, context) => {
10-
try {
11-
await loadingApp;
12-
13-
// Ends function immediately after callback
14-
context.callbackWaitsForEmptyEventLoop = false;
15-
16-
// this could will be simpler once we ship `verifyAndParse()`
17-
// see https://github.com/octokit/webhooks.js/issues/379
18-
await probot.webhooks.verifyAndReceive({
19-
id:
20-
event.headers["X-GitHub-Delivery"] ||
21-
event.headers["x-github-delivery"],
22-
name: event.headers["X-GitHub-Event"] || event.headers["x-github-event"],
23-
signature:
24-
event.headers["X-Hub-Signature-256"] ||
25-
event.headers["x-hub-signature-256"],
26-
payload: JSON.parse(event.body),
27-
});
28-
29-
return {
30-
statusCode: 200,
31-
body: '{"ok":true}',
32-
};
33-
} catch (error) {
34-
console.log(error);
35-
36-
return {
37-
statusCode: error.status || 500,
38-
error: "ooops",
39-
};
40-
}
41-
};
8+
module.exports.webhooks = createLambdaFunction(appFn, {
9+
probot: createProbot(),
10+
});

Diff for: package-lock.json

+54-43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"test": "node test.js"
1010
},
1111
"dependencies": {
12-
"probot": "^11.0.5"
12+
"@probot/adapter-aws-lambda-serverless": "^2.0.0"
1313
},
1414
"repository": "https://github.com/probot/example-aws-lambda-serverless",
1515
"keywords": [],

Diff for: test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ const assert = require("uvu/assert");
44
const nock = require("nock");
55
nock.disableNetConnect();
66

7-
const { Probot, ProbotOctokit } = require("probot");
7+
const {
8+
Probot,
9+
ProbotOctokit,
10+
} = require("@probot/adapter-aws-lambda-serverless");
811

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

0 commit comments

Comments
 (0)