@@ -16,6 +16,26 @@ export const CI_PR_URL = `https://${CI_DOMAIN}/job/${CI_PR_NAME}/build`;
1616const CI_V8_NAME = CI_TYPES . get ( CI_TYPES_KEYS . V8 ) . jobName ;
1717export const CI_V8_URL = `https://${ CI_DOMAIN } /job/${ CI_V8_NAME } /build` ;
1818
19+ const REQUEST_CI_COMMENT = / ^ @ n o d e j s - g i t h u b - b o t .+ ( [ 0 - 9 a - f ] { 40 } ) $ / ;
20+
21+ async function findSafeFullCommitSHA ( cli , prData , request ) {
22+ // First, let's check if the head was approved.
23+ await Promise . all ( [ prData . getReviews ( ) , prData . getCommits ( ) ] ) ;
24+
25+ const approvedHead = new PRChecker ( cli , prData , request , { } ) . getApprovedTipOfHead ( ) ;
26+ if ( approvedHead ) return approvedHead ;
27+
28+ // Else, let's find out if a collaborator added a comment with a full commit SHA.
29+ await Promise . all ( [ prData . getCollaborators ( ) , prData . getComments ( ) ] ) ;
30+ const collaborators = Array . from ( prData . collaborators . values ( ) ,
31+ ( c ) => c . login . toLowerCase ( ) ) ;
32+ return prData . comments
33+ . findLast ( c =>
34+ collaborators . includes ( c . author . login . toLowerCase ( ) ) &&
35+ REQUEST_CI_COMMENT . test ( c . body ) )
36+ ?. body . match ( REQUEST_CI_COMMENT ) [ 1 ] ;
37+ }
38+
1939export class RunPRJob {
2040 constructor ( cli , request , owner , repo , prid , certifySafe ) {
2141 this . cli = cli ;
@@ -26,9 +46,7 @@ export class RunPRJob {
2646 this . prData = new PRData ( { prid, owner, repo } , cli , request ) ;
2747 this . certifySafe =
2848 certifySafe ||
29- Promise . all ( [ this . prData . getReviews ( ) , this . prData . getCommits ( ) ] ) . then ( ( ) =>
30- ( this . certifySafe = new PRChecker ( cli , this . prData , request , { } ) . getApprovedTipOfHead ( ) )
31- ) ;
49+ findSafeFullCommitSHA ( cli , this . prData , request ) . then ( ( h ) => ( this . certifySafe = h ) ) ;
3250 }
3351
3452 async getCrumb ( ) {
@@ -72,6 +90,8 @@ export class RunPRJob {
7290 const { cli, certifySafe } = this ;
7391
7492 if ( ! ( await certifySafe ) ) {
93+ cli . info ( 'If the tip of this PR looks safe, add a comment in the form of:' ) ;
94+ cli . info ( '@nodejs-github-bot test <commit-full-sha-or-URL>' ) ;
7595 cli . error ( 'Refusing to run CI on potentially unsafe PR' ) ;
7696 return false ;
7797 }
0 commit comments