forked from probot/adapter-aws-lambda-serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda-function.js
31 lines (27 loc) · 906 Bytes
/
lambda-function.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module.exports = lambdaFunction;
const lowercaseKeys = require("lowercase-keys");
async function lambdaFunction(probot, event, context) {
try {
// lowercase all headers to respect headers insensitivity (RFC 7230 $3.2 'Header Fields', see issue #62)
const headersLowerCase = lowercaseKeys(event.headers);
// this will be simpler once we ship `verifyAndParse()`
// see https://github.com/octokit/webhooks.js/issues/379
await probot.webhooks.verifyAndReceive({
id: headersLowerCase["x-github-delivery"],
name: headersLowerCase["x-github-event"],
signature:
headersLowerCase["x-hub-signature-256"] ||
headersLowerCase["x-hub-signature"],
payload: event.body,
});
return {
statusCode: 200,
body: '{"ok":true}',
};
} catch (error) {
return {
statusCode: error.status || 500,
error: "ooops",
};
}
}