-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abab4d3
commit 21610ac
Showing
2 changed files
with
28 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,38 @@ | ||
module.exports = lambdaFunction; | ||
|
||
const lowercaseKeys = require("lowercase-keys"); | ||
const { template } = require("./views/probot"); | ||
|
||
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 { | ||
if (event.httpMethod === "GET" && event.path === "/probot") { | ||
const res = { | ||
statusCode: 200, | ||
body: '{"ok":true}', | ||
}; | ||
} catch (error) { | ||
return { | ||
statusCode: error.status || 500, | ||
error: "ooops", | ||
headers: { | ||
"Content-Type": "text/html", | ||
}, | ||
body: template, | ||
}; | ||
return res; | ||
} | ||
|
||
// 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: JSON.stringify({ ok: true }), | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters