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

‎handler.js‎

Lines changed: 8 additions & 39 deletions
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-
constapp=require("./app");
6+
constappFn=require("./");
57

6-
constprobot=createProbot();
7-
constloadingApp=probot.load(app);
8-
9-
module.exports.webhooks=async(event,context)=>{
10-
try{
11-
awaitloadingApp;
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-
awaitprobot.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+
});

‎package-lock.json‎

Lines changed: 54 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
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": [],

‎test.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ const assert = require("uvu/assert");
44
constnock=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
constapp=require("./app");
1013

0 commit comments

Comments
(0)