Skip to content

Commit 5f68c28

Browse files
authored
style: standard (#49)
1 parent 5685871 commit 5f68c28

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

index.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ const { template } = require('./views/probot')
55

66
let probot
77

8-
const loadProbot = appFn => {
9-
probot = probot || new Probot({
10-
id: process.env.APP_ID,
11-
secret: process.env.WEBHOOK_SECRET,
12-
privateKey: findPrivateKey()
13-
})
8+
const loadProbot = (appFn) => {
9+
probot =
10+
probot ||
11+
new Probot({
12+
id: process.env.APP_ID,
13+
secret: process.env.WEBHOOK_SECRET,
14+
privateKey: findPrivateKey()
15+
})
1416

1517
if (typeof appFn === 'string') {
1618
appFn = resolve(appFn)
@@ -22,10 +24,13 @@ const loadProbot = appFn => {
2224
}
2325

2426
const lowerCaseKeys = (obj = {}) =>
25-
Object.keys(obj).reduce((accumulator, key) =>
26-
Object.assign(accumulator, { [key.toLocaleLowerCase()]: obj[key] }), {})
27+
Object.keys(obj).reduce(
28+
(accumulator, key) =>
29+
Object.assign(accumulator, { [key.toLocaleLowerCase()]: obj[key] }),
30+
{}
31+
)
2732

28-
module.exports.serverless = appFn => {
33+
module.exports.serverless = (appFn) => {
2934
return async (event, context) => {
3035
// 🤖 A friendly homepage if there isn't a payload
3136
if (event.httpMethod === 'GET' && event.path === '/probot') {
@@ -61,7 +66,8 @@ module.exports.serverless = appFn => {
6166
}
6267

6368
// Convert the payload to an Object if API Gateway stringifies it
64-
event.body = (typeof event.body === 'string') ? JSON.parse(event.body) : event.body
69+
event.body =
70+
typeof event.body === 'string' ? JSON.parse(event.body) : event.body
6571

6672
// Bail for null body
6773
if (!event.body) {
@@ -72,20 +78,21 @@ module.exports.serverless = appFn => {
7278
}
7379

7480
// Do the thing
75-
console.log(`Received event ${e}${event.body.action ? ('.' + event.body.action) : ''}`)
81+
console.log(
82+
`Received event ${e}${event.body.action ? '.' + event.body.action : ''}`
83+
)
7684
if (event) {
7785
try {
7886
await probot.receive({
7987
name: e,
8088
payload: event.body
8189
})
82-
const res = {
90+
return {
8391
statusCode: 200,
8492
body: JSON.stringify({
8593
message: `Received ${e}.${event.body.action}`
8694
})
8795
}
88-
return res
8996
} catch (err) {
9097
console.error(err)
9198
return {
@@ -95,11 +102,7 @@ module.exports.serverless = appFn => {
95102
}
96103
} else {
97104
console.error({ event, context })
98-
throw 'unknown error'
99-
}
100-
return {
101-
statusCode: 200,
102-
body: 'Nothing to do.'
105+
throw new Error('unknown error')
103106
}
104107
}
105108
}

0 commit comments

Comments
 (0)