@@ -14,6 +14,8 @@ const {
1414 rejectingReviews,
1515 commentsWithCI,
1616 commentsWithLGTM,
17+ singleCommitAfterReview,
18+ multipleCommitsAfterReview,
1719 oddCommits,
1820 simpleCommits,
1921 collaborators,
@@ -38,13 +40,16 @@ describe('PRChecker', () => {
3840 let checkCIStub ;
3941 let authorIsNewStub ;
4042 let checkAuthorStub ;
43+ let checkCommitsAfterReviewStub ;
4144
4245 before ( ( ) => {
4346 checkReviewsStub = sinon . stub ( checker , 'checkReviews' ) ;
4447 checkPRWaitStub = sinon . stub ( checker , 'checkPRWait' ) ;
4548 checkCIStub = sinon . stub ( checker , 'checkCI' ) ;
4649 authorIsNewStub = sinon . stub ( checker , 'authorIsNew' ) . returns ( true ) ;
4750 checkAuthorStub = sinon . stub ( checker , 'checkAuthor' ) ;
51+ checkCommitsAfterReviewStub =
52+ sinon . stub ( checker , 'checkCommitsAfterReview' ) ;
4853 } ) ;
4954
5055 after ( ( ) => {
@@ -53,6 +58,7 @@ describe('PRChecker', () => {
5358 checkCIStub . restore ( ) ;
5459 authorIsNewStub . restore ( ) ;
5560 checkAuthorStub . restore ( ) ;
61+ checkCommitsAfterReviewStub . restore ( ) ;
5662 } ) ;
5763
5864 it ( 'should run necessary checks' , ( ) => {
@@ -63,6 +69,7 @@ describe('PRChecker', () => {
6369 assert . strictEqual ( checkCIStub . calledOnce , true ) ;
6470 assert . strictEqual ( authorIsNewStub . calledOnce , true ) ;
6571 assert . strictEqual ( checkAuthorStub . calledOnce , true ) ;
72+ assert . strictEqual ( checkCommitsAfterReviewStub . calledOnce , true ) ;
6673 } ) ;
6774 } ) ;
6875
@@ -300,4 +307,91 @@ describe('PRChecker', () => {
300307 assert . deepStrictEqual ( logger . logs , expectedLogs ) ;
301308 } ) ;
302309 } ) ;
310+
311+ describe ( 'checkCommitsAfterReview' , ( ) => {
312+ let logger = new TestLogger ( ) ;
313+
314+ afterEach ( ( ) => {
315+ logger . clear ( ) ;
316+ } ) ;
317+
318+ it ( 'should warn about commit pushed since the last review' , ( ) => {
319+ const { commits, reviews } = singleCommitAfterReview ;
320+
321+ const expectedLogs = {
322+ warn : [
323+ [ 'Changes were pushed since the last review:' ] ,
324+ [ '- single commit was pushed after review' ]
325+ ] ,
326+ info : [ ] ,
327+ trace : [ ] ,
328+ error : [ ]
329+ } ;
330+
331+ const checker = new PRChecker ( logger , {
332+ pr : firstTimerPR ,
333+ reviewers : allGreenReviewers ,
334+ comments : commentsWithLGTM ,
335+ collaborators,
336+ reviews,
337+ commits
338+ } ) ;
339+
340+ let status = checker . checkCommitsAfterReview ( ) ;
341+ assert . deepStrictEqual ( status , false ) ;
342+ assert . deepStrictEqual ( logger . logs , expectedLogs ) ;
343+ } ) ;
344+
345+ it ( 'should warn about multiple commits since the last review' , ( ) => {
346+ const { commits, reviews } = multipleCommitsAfterReview ;
347+
348+ const expectedLogs = {
349+ warn : [
350+ [ 'Changes were pushed since the last review:' ] ,
351+ [ '- src: add requested feature' ] ,
352+ [ '- nit: fix errors' ]
353+ ] ,
354+ info : [ ] ,
355+ trace : [ ] ,
356+ error : [ ]
357+ } ;
358+
359+ const checker = new PRChecker ( logger , {
360+ pr : firstTimerPR ,
361+ reviewers : allGreenReviewers ,
362+ comments : commentsWithLGTM ,
363+ collaborators,
364+ reviews,
365+ commits
366+ } ) ;
367+
368+ let status = checker . checkCommitsAfterReview ( ) ;
369+ assert . deepStrictEqual ( status , false ) ;
370+ assert . deepStrictEqual ( logger . logs , expectedLogs ) ;
371+ } ) ;
372+
373+ it ( 'should skip the check if there are no reviews' , ( ) => {
374+ const { commits } = multipleCommitsAfterReview ;
375+
376+ const expectedLogs = {
377+ warn : [ ] ,
378+ info : [ ] ,
379+ trace : [ ] ,
380+ error : [ ]
381+ } ;
382+
383+ const checker = new PRChecker ( logger , {
384+ pr : firstTimerPR ,
385+ reviewers : allGreenReviewers ,
386+ comments : commentsWithLGTM ,
387+ reviews : [ ] ,
388+ collaborators,
389+ commits
390+ } ) ;
391+
392+ let status = checker . checkCommitsAfterReview ( ) ;
393+ assert . deepStrictEqual ( status , true ) ;
394+ assert . deepStrictEqual ( logger . logs , expectedLogs ) ;
395+ } ) ;
396+ } ) ;
303397} ) ;
0 commit comments