Skip to content

Commit

Permalink
Merge pull request #14 from jakebolam/patch-2
Browse files Browse the repository at this point in the history
fix: undefined event name in webhook handler
  • Loading branch information
tcbyrd authored Mar 16, 2019
2 parents 89e6352 + 8fdada0 commit 1abd262
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const loadProbot = appFn => {
return probot
}

const lowerCaseKeys = obj =>
Object.keys(obj).reduce((accumulator, key) =>
Object.assign(accumulator, {[key.toLocaleLowerCase()]: obj[key]}), {})

module.exports.serverless = appFn => {
return async (event, context) => {
// 🤖 A friendly homepage if there isn't a payload
Expand All @@ -42,7 +46,8 @@ module.exports.serverless = appFn => {
context.callbackWaitsForEmptyEventLoop = false

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

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

0 comments on commit 1abd262

Please sign in to comment.