Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions lambda-function.js
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 }),
};

}
1 change: 0 additions & 1 deletion views/probot.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module.exports.template = `
<h4 class="alt-h4 text-gray-light">Need help?</h4>
<div class="d-flex flex-justify-center mt-2">
<a href="https://probot.github.io/docs/" class="btn btn-outline mr-2">Documentation</a>
<a href="https://probot-slackin.herokuapp.com/" class="btn btn-outline">Chat on Slack</a>
</div>
</div>
</div>
Expand Down