@@ -221,12 +221,14 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
221
221
github . apps . listInstallations . endpoint . merge ( { per_page : 100 } )
222
222
)
223
223
robot . log . debug ( `installations: ${ JSON . stringify ( installations ) } ` )
224
- if ( installations . length > 0 ) {
225
- const installation = installations [ 0 ]
224
+ const installation = installations . find ( inst => inst . account . login === env . GH_ORG )
225
+ if ( installation ) {
226
226
const github = await robot . auth ( installation . id )
227
227
const app = await github . apps . getAuthenticated ( )
228
228
appSlug = app . data . slug
229
229
robot . log . debug ( `Validated the app is configured properly = \n${ JSON . stringify ( app . data , null , 2 ) } ` )
230
+ } else {
231
+ robot . log . error ( `No installation found for organization: ${ env . GH_ORG } ` )
230
232
}
231
233
}
232
234
@@ -238,8 +240,8 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
238
240
github . apps . listInstallations . endpoint . merge ( { per_page : 100 } )
239
241
)
240
242
241
- if ( installations . length > 0 ) {
242
- const installation = installations [ 0 ]
243
+ const installation = installations . find ( inst => inst . account . login === env . GH_ORG )
244
+ if ( installation ) {
243
245
const github = await robot . auth ( installation . id )
244
246
const context = {
245
247
payload : {
@@ -250,6 +252,8 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
250
252
repo : ( ) => { return { repo : env . ADMIN_REPO , owner : installation . account . login } }
251
253
}
252
254
return syncAllSettings ( false , context )
255
+ } else {
256
+ robot . log . error ( `No installation found for organization: ${ env . GH_ORG } ` )
253
257
}
254
258
return null
255
259
}
0 commit comments