@@ -92,8 +92,11 @@ const github = {
92
92
'User-Agent' : 'Node.js'
93
93
} ;
94
94
95
- const reviews = await httpRequest ( CONFIG . GITHUB_API_BASE , path , 'GET' , headers ) ;
96
- return reviews . filter ( review => review . state === 'APPROVED' ) . length ;
95
+ const reviews = await httpRequest ( CONFIG . GITHUB_API_BASE , path , 'GET' , headers ) ,
96
+ approved = reviews . filter ( review => review . state === 'APPROVED' ) . length ,
97
+ changesRequested = reviews . filter ( review => review . state === 'CHANGES_REQUESTED' ) . length ;
98
+
99
+ return { approved, changesRequested } ;
97
100
}
98
101
} ;
99
102
@@ -318,12 +321,10 @@ async function repostApprovalList() {
318
321
319
322
Object . entries ( state . repositories ) . forEach ( ( [ repo , data ] ) => {
320
323
Object . values ( data . pullRequests ) . forEach ( pr => {
321
- if ( pr . status === 'needs_approval' || pr . status === 'changes_requested' ) {
322
- needsApproval . push ( {
323
- ...pr ,
324
- repository : repo
325
- } ) ;
326
- }
324
+ needsApproval . push ( {
325
+ ...pr ,
326
+ repository : repo
327
+ } ) ;
327
328
} ) ;
328
329
} ) ;
329
330
@@ -336,7 +337,7 @@ async function repostApprovalList() {
336
337
let message = '' ;
337
338
338
339
needsApproval . forEach ( pr => {
339
- const emoji = pr . status === 'changes_requested' ? '🔧 ' : '' ;
340
+ const emoji = pr . changesRequested ? '🔧 ' : '' ;
340
341
message += formatPRMessage ( pr . number , pr . author , pr . title , pr . repository , pr . approvals , emoji ) + '\n\n' ;
341
342
} ) ;
342
343
@@ -358,26 +359,26 @@ async function repostApprovalList() {
358
359
}
359
360
}
360
361
361
- function formatPRMessage ( prNumber , prAuthor , prTitle , repo , approvalCount , emoji = '' ) {
362
+ function formatPRMessage ( prNumber , prAuthor , prTitle , repo , approvedCount , emoji = '' ) {
362
363
const truncatedTitle = prTitle . length > ENV . titleMaxLength
363
364
? prTitle . slice ( 0 , ENV . titleMaxLength ) + '…'
364
365
: prTitle ;
365
366
const prLink = `https://github.com/${ repo } /pull/${ prNumber } ` ;
366
367
367
- return `(${ approvalCount } of ${ ENV . requiredApprovals } approvals) PR #${ prNumber } by ${ prAuthor } :\n${ emoji } <${ prLink } |${ truncatedTitle } >` ;
368
+ return `(${ approvedCount } of ${ ENV . requiredApprovals } approvals) PR #${ prNumber } by ${ prAuthor } :\n${ emoji } <${ prLink } |${ truncatedTitle } >` ;
368
369
}
369
370
370
371
async function handlePROpened ( event ) {
371
372
const { prNumber, prAuthor, prTitle, repo } = event ;
372
- const approvalCount = await github . getReviews ( repo , prNumber ) ;
373
+ const { approvedCount , changesRequestedCount } = await github . getReviews ( repo , prNumber ) ;
373
374
374
375
await stateManager . updatePR ( repo , prNumber , {
375
376
number : prNumber ,
376
377
title : prTitle ,
377
378
author : prAuthor ,
378
379
url : `https://github.com/${ repo } /pull/${ prNumber } ` ,
379
- status : 'needs_approval' ,
380
- approvals : approvalCount ,
380
+ changesRequested : changesRequestedCount > 0 ,
381
+ approvals : approvedCount ,
381
382
createdAt : new Date ( ) . toISOString ( ) ,
382
383
} )
383
384
@@ -392,25 +393,17 @@ async function handlePRReview(event) {
392
393
return ;
393
394
}
394
395
395
- if ( reviewState !== 'approved' ) {
396
- return ;
397
- }
398
-
399
- const approvalCount = await github . getReviews ( repo , prNumber ) ;
396
+ const { approvedCount, changesRequestedCount } = await github . getReviews ( repo , prNumber ) ;
400
397
401
- if ( approvalCount >= ENV . requiredApprovals ) {
402
- if ( reviewState !== 'changes_requested' ) {
403
- // post standalone approval message
404
- const message = formatPRMessage ( prNumber , prAuthor , prTitle , repo , approvalCount , '✅✅ ' ) ;
405
- await slack . postMessage ( ENV . slackChannelId , message ) ;
398
+ if ( ( approvedCount >= ENV . requiredApprovals ) && changesRequestedCount === 0 ) {
399
+ // post standalone approval message
400
+ const message = formatPRMessage ( prNumber , prAuthor , prTitle , repo , approvedCount , '✅✅ ' ) ;
401
+ await slack . postMessage ( ENV . slackChannelId , message ) ;
406
402
407
- // remove from state
408
- await stateManager . removePR ( repo , prNumber )
409
- }
403
+ // remove from state
404
+ await stateManager . removePR ( repo , prNumber )
410
405
} else {
411
- await stateManager . updatePR ( repo , prNumber , {
412
- approvals : approvalCount ,
413
- } )
406
+ await stateManager . updatePR ( repo , prNumber , { approvals : approvedCount } )
414
407
}
415
408
416
409
await repostApprovalList ( ) ;
@@ -419,7 +412,7 @@ async function handlePRReview(event) {
419
412
async function handlePRChangesRequested ( event ) {
420
413
const { prNumber, prAuthor, repo, prTitle, reviewState } = event ;
421
414
422
- const approvalCount = await github . getReviews ( repo , prNumber ) ;
415
+ const { approvedCount } = await github . getReviews ( repo , prNumber ) ;
423
416
424
417
if ( reviewState !== 'changes_requested' ) {
425
418
return ;
@@ -430,8 +423,8 @@ async function handlePRChangesRequested(event) {
430
423
title : prTitle ,
431
424
author : prAuthor ,
432
425
url : `https://github.com/${ repo } /pull/${ prNumber } ` ,
433
- status : reviewState ,
434
- approvals : approvalCount ,
426
+ changesRequested : true ,
427
+ approvals : approvedCount ,
435
428
createdAt : new Date ( ) . toISOString ( ) ,
436
429
} ) ;
437
430
0 commit comments