1
+ #!/usr/bin/env node
2
+
1
3
const https = require ( 'https' ) ;
2
4
const fs = require ( 'fs' ) ;
3
5
@@ -302,8 +304,6 @@ const stateManager = {
302
304
}
303
305
}
304
306
}
305
-
306
-
307
307
}
308
308
}
309
309
@@ -318,7 +318,7 @@ async function repostApprovalList() {
318
318
319
319
Object . entries ( state . repositories ) . forEach ( ( [ repo , data ] ) => {
320
320
Object . values ( data . pullRequests ) . forEach ( pr => {
321
- if ( pr . status === 'needs_approval' || pr . changesRequested ) {
321
+ if ( pr . status === 'needs_approval' || pr . status === 'changes_requested' ) {
322
322
needsApproval . push ( {
323
323
...pr ,
324
324
repository : repo
@@ -336,7 +336,7 @@ async function repostApprovalList() {
336
336
let message = '' ;
337
337
338
338
needsApproval . forEach ( pr => {
339
- const emoji = pr . changesRequested ? '🔧 ' : '' ;
339
+ const emoji = pr . status === 'changes_requested' ? '🔧 ' : '' ;
340
340
message += formatPRMessage ( pr . number , pr . author , pr . title , pr . repository , pr . approvals , emoji ) + '\n\n' ;
341
341
} ) ;
342
342
@@ -417,14 +417,22 @@ async function handlePRReview(event) {
417
417
}
418
418
419
419
async function handlePRChangesRequested ( event ) {
420
- const { prNumber, repo, reviewState } = event ;
420
+ const { prNumber, prAuthor, repo, prTitle, reviewState } = event ;
421
+
422
+ const approvalCount = await github . getReviews ( repo , prNumber ) ;
421
423
422
424
if ( reviewState !== 'changes_requested' ) {
423
425
return ;
424
426
}
425
427
426
428
await stateManager . updatePR ( repo , prNumber , {
427
- changesRequested : true ,
429
+ number : prNumber ,
430
+ title : prTitle ,
431
+ author : prAuthor ,
432
+ url : `https://github.com/${ repo } /pull/${ prNumber } ` ,
433
+ status : reviewState ,
434
+ approvals : approvalCount ,
435
+ createdAt : new Date ( ) . toISOString ( ) ,
428
436
} ) ;
429
437
430
438
await repostApprovalList ( ) ;
@@ -438,7 +446,7 @@ async function handlePRClosed(event) {
438
446
await repostApprovalList ( ) ;
439
447
}
440
448
441
- async function main ( ) {
449
+ async function run ( ) {
442
450
validateEnvironment ( ) ;
443
451
const event = loadEventData ( ) ;
444
452
@@ -468,4 +476,25 @@ async function main() {
468
476
}
469
477
}
470
478
471
- main ( ) ;
479
+ module . exports = {
480
+ CONFIG ,
481
+ ENV ,
482
+ validateEnvironment,
483
+ sleep,
484
+ loadEventData,
485
+ httpRequest,
486
+ github,
487
+ slack,
488
+ stateManager,
489
+ repostApprovalList,
490
+ formatPRMessage,
491
+ handlePROpened,
492
+ handlePRReview,
493
+ handlePRChangesRequested,
494
+ handlePRClosed,
495
+ run
496
+ }
497
+
498
+ if ( require . main === module ) {
499
+ run ( ) ;
500
+ }
0 commit comments