@@ -16,6 +16,26 @@ export const CI_PR_URL = `https://${CI_DOMAIN}/job/${CI_PR_NAME}/build`;
16
16
const CI_V8_NAME = CI_TYPES . get ( CI_TYPES_KEYS . V8 ) . jobName ;
17
17
export const CI_V8_URL = `https://${ CI_DOMAIN } /job/${ CI_V8_NAME } /build` ;
18
18
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
+
19
39
export class RunPRJob {
20
40
constructor ( cli , request , owner , repo , prid , certifySafe ) {
21
41
this . cli = cli ;
@@ -26,9 +46,7 @@ export class RunPRJob {
26
46
this . prData = new PRData ( { prid, owner, repo } , cli , request ) ;
27
47
this . certifySafe =
28
48
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 ) ) ;
32
50
}
33
51
34
52
async getCrumb ( ) {
@@ -72,6 +90,8 @@ export class RunPRJob {
72
90
const { cli, certifySafe } = this ;
73
91
74
92
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>' ) ;
75
95
cli . error ( 'Refusing to run CI on potentially unsafe PR' ) ;
76
96
return false ;
77
97
}
0 commit comments