@@ -530,6 +530,11 @@ export default class PRChecker {
530
530
} = this ;
531
531
const { maxCommits } = argv ;
532
532
533
+ if ( commits . length === 0 ) {
534
+ cli . warn ( 'No commits found' ) ;
535
+ return false ;
536
+ }
537
+
533
538
const reviewIndex = reviews . findLastIndex (
534
539
review => review . authorCanPushToRepository && review . state === 'APPROVED'
535
540
) ;
@@ -539,38 +544,21 @@ export default class PRChecker {
539
544
return false ;
540
545
}
541
546
542
- const reviewDate = reviews [ reviewIndex ] . publishedAt ;
543
-
544
- const afterCommits = [ ] ;
545
- commits . forEach ( ( commit ) => {
546
- commit = commit . commit ;
547
- if ( commit . committedDate > reviewDate ) {
548
- afterCommits . push ( commit ) ;
549
- }
550
- } ) ;
551
-
552
- const totalCommits = afterCommits . length ;
553
- if ( totalCommits === 0 && this . pr . timelineItems . updatedAt > reviewDate ) {
554
- // Some commits were pushed, but all the commits have a commit date prior
555
- // to the last review. It means that either that a long time elapsed
556
- // between the commit and the push, or that the clock on the dev machine
557
- // is wrong, or the commit date was forged.
558
- cli . warn ( 'Something was pushed to the Pull Request branch since the last approving review.' ) ;
559
- return false ;
560
- }
547
+ const reviewedCommitIndex = commits
548
+ . findLastIndex ( ( { commit } ) => commit . oid === reviews [ reviewIndex ] . commit . oid ) ;
561
549
562
- if ( totalCommits > 0 ) {
550
+ if ( reviewedCommitIndex !== commits . length - 1 ) {
563
551
cli . warn ( 'Commits were pushed since the last approving review:' ) ;
564
- const sliceLength = maxCommits === 0 ? totalCommits : - maxCommits ;
565
- afterCommits . slice ( sliceLength )
566
- . forEach ( commit => {
552
+ commits . slice ( Math . max ( reviewedCommitIndex + 1 , commits . length - maxCommits ) )
553
+ . forEach ( ( { commit } ) => {
567
554
cli . warn ( `- ${ commit . messageHeadline } ` ) ;
568
555
} ) ;
569
556
557
+ const totalCommits = commits . length - reviewedCommitIndex - 1 ;
570
558
if ( totalCommits > maxCommits ) {
571
559
const infoMsg = '...(use `' +
572
- `--max-commits ${ totalCommits } ` +
573
- '` to see the full list of commits)' ;
560
+ `--max-commits ${ totalCommits } ` +
561
+ '` to see the full list of commits)' ;
574
562
cli . warn ( infoMsg ) ;
575
563
}
576
564
0 commit comments