Skip to content

Commit 1abd262

Browse files
authored
Merge pull request #14 from jakebolam/patch-2
fix: undefined event name in webhook handler
2 parents 89e6352 + 8fdada0 commit 1abd262

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ const loadProbot = appFn => {
2121
return probot
2222
}
2323

24+
const lowerCaseKeys = obj =>
25+
Object.keys(obj).reduce((accumulator, key) =>
26+
Object.assign(accumulator, {[key.toLocaleLowerCase()]: obj[key]}), {})
27+
2428
module.exports.serverless = appFn => {
2529
return async (event, context) => {
2630
// 🤖 A friendly homepage if there isn't a payload
@@ -42,7 +46,8 @@ module.exports.serverless = appFn => {
4246
context.callbackWaitsForEmptyEventLoop = false
4347

4448
// Determine incoming webhook event type
45-
const e = event.headers['x-github-event'] || event.headers['X-GitHub-Event']
49+
const headers = lowerCaseKeys(event.headers)
50+
const e = headers['x-github-event']
4651

4752
// Convert the payload to an Object if API Gateway stringifies it
4853
event.body = (typeof event.body === 'string') ? JSON.parse(event.body) : event.body

0 commit comments

Comments
 (0)