@@ -181,12 +181,17 @@ export class GithubApp {
181
181
options . getRouter ( "/reconfigure" ) . get (
182
182
"/" ,
183
183
asyncHandler ( async ( req : express . Request , res : express . Response ) => {
184
- const gh = await app . auth ( ) ;
185
- const data = await gh . apps . getAuthenticated ( ) ;
186
- const slug = data . data . slug ;
187
-
188
- const state = req . query . state ;
189
- res . redirect ( `https://github.com/apps/${ slug } /installations/new?state=${ state } ` ) ;
184
+ try {
185
+ const gh = await app . auth ( ) ;
186
+ const data = await gh . apps . getAuthenticated ( ) ;
187
+ const slug = data . data . slug ;
188
+
189
+ const state = req . query . state ;
190
+ res . redirect ( `https://github.com/apps/${ slug } /installations/new?state=${ state } ` ) ;
191
+ } catch ( error ) {
192
+ console . error ( error , { error } ) ;
193
+ res . status ( 500 ) . send ( "GitHub App is not configured." ) ;
194
+ }
190
195
} ) ,
191
196
) ;
192
197
options . getRouter &&
@@ -398,6 +403,12 @@ export class GithubApp {
398
403
const span = TraceContext . startSpan ( "GithubApp.handlePullRequest" , { } ) ;
399
404
span . setTag ( "request" , ctx . id ) ;
400
405
406
+ const event = await this . webhookEvents . createEvent ( {
407
+ type : ctx . name ,
408
+ status : "received" ,
409
+ rawEvent : JSON . stringify ( ctx . payload ) ,
410
+ } ) ;
411
+
401
412
try {
402
413
const installationId = ctx . payload . installation ?. id ;
403
414
const cloneURL = ctx . payload . repository . clone_url ;
@@ -423,14 +434,37 @@ export class GithubApp {
423
434
user = r . user ;
424
435
project = r . project ;
425
436
426
- const prebuildStartPromise = await this . onPrStartPrebuild ( { span } , ctx , config , context , user , project ) ;
427
- if ( prebuildStartPromise ) {
428
- await this . onPrAddCheck ( { span } , config , ctx , prebuildStartPromise ) ;
437
+ await this . webhookEvents . updateEvent ( event . id , {
438
+ authorizedUserId : user . id ,
439
+ projectId : project ?. id ,
440
+ cloneUrl : context . repository . cloneUrl ,
441
+ branch : context . ref ,
442
+ commit : context . revision ,
443
+ } ) ;
444
+
445
+ const prebuildStartResult = await this . onPrStartPrebuild ( { span } , ctx , config , context , user , project ) ;
446
+ if ( prebuildStartResult ) {
447
+ await this . webhookEvents . updateEvent ( event . id , {
448
+ prebuildStatus : "prebuild_triggered" ,
449
+ status : "processed" ,
450
+ prebuildId : prebuildStartResult . prebuildId ,
451
+ } ) ;
452
+
453
+ await this . onPrAddCheck ( { span } , config , ctx , prebuildStartResult ) ;
429
454
this . onPrAddBadge ( config , ctx ) ;
430
455
await this . onPrAddComment ( config , ctx ) ;
456
+ } else {
457
+ await this . webhookEvents . updateEvent ( event . id , {
458
+ prebuildStatus : "ignored_unconfigured" ,
459
+ status : "processed" ,
460
+ } ) ;
431
461
}
432
462
} catch ( e ) {
433
463
TraceContext . setError ( { span } , e ) ;
464
+ await this . webhookEvents . updateEvent ( event . id , {
465
+ prebuildStatus : "prebuild_trigger_failed" ,
466
+ status : "processed" ,
467
+ } ) ;
434
468
throw e ;
435
469
} finally {
436
470
span . finish ( ) ;
0 commit comments