@@ -5,18 +5,24 @@ import {
55 CI_TYPES ,
66 CI_TYPES_KEYS
77} from './ci_type_parser.js' ;
8+ import PRData from '../pr_data.js' ;
9+ import { debuglog } from '../verbosity.js' ;
810
911export const CI_CRUMB_URL = `https://${ CI_DOMAIN } /crumbIssuer/api/json` ;
1012const CI_PR_NAME = CI_TYPES . get ( CI_TYPES_KEYS . PR ) . jobName ;
1113export const CI_PR_URL = `https://${ CI_DOMAIN } /job/${ CI_PR_NAME } /build` ;
1214
15+ const CI_V8_NAME = CI_TYPES . get ( CI_TYPES_KEYS . V8 ) . jobName ;
16+ export const CI_V8_URL = `https://${ CI_DOMAIN } /job/${ CI_V8_NAME } /build` ;
17+
1318export class RunPRJob {
1419 constructor ( cli , request , owner , repo , prid ) {
1520 this . cli = cli ;
1621 this . request = request ;
1722 this . owner = owner ;
1823 this . repo = repo ;
1924 this . prid = prid ;
25+ this . prData = new PRData ( { prid, owner, repo } , cli , request ) ;
2026 }
2127
2228 async getCrumb ( ) {
@@ -43,6 +49,18 @@ export class RunPRJob {
4349 return payload ;
4450 }
4551
52+ get v8Payload ( ) {
53+ const payload = new FormData ( ) ;
54+ payload . append ( 'json' , JSON . stringify ( {
55+ parameter : [
56+ { name : 'GITHUB_ORG' , value : this . owner } ,
57+ { name : 'REPO_NAME' , value : this . repo } ,
58+ { name : 'GIT_REMOTE_REF' , value : `refs/pull/${ this . prid } /head` }
59+ ]
60+ } ) ) ;
61+ return payload ;
62+ }
63+
4664 async start ( ) {
4765 const { cli } = this ;
4866 cli . startSpinner ( 'Validating Jenkins credentials' ) ;
@@ -71,7 +89,29 @@ export class RunPRJob {
7189 return false ;
7290 }
7391 cli . stopSpinner ( 'PR CI job successfully started' ) ;
92+
93+ // check if the job need a v8 build and trigger it
94+ await this . prData . getPR ( ) ;
95+ const labels = this . prData . pr . labels ;
96+ if ( labels . nodes . map ( i => i . name ) . includes ( 'v8 engine' ) ) {
97+ cli . startSpinner ( 'Starting V8 CI job' ) ;
98+ const response = await this . request . fetch ( CI_V8_URL , {
99+ method : 'POST' ,
100+ headers : {
101+ 'Jenkins-Crumb' : crumb
102+ } ,
103+ body : this . v8Payload
104+ } ) ;
105+ if ( response . status !== 201 ) {
106+ cli . stopSpinner (
107+ `Failed to start V8 CI: ${ response . status } ${ response . statusText } ` ,
108+ this . cli . SPINNER_STATUS . FAILED ) ;
109+ return false ;
110+ }
111+ cli . stopSpinner ( 'V8 CI job successfully started' ) ;
112+ }
74113 } catch ( err ) {
114+ debuglog ( err ) ;
75115 cli . stopSpinner ( 'Failed to start CI' , this . cli . SPINNER_STATUS . FAILED ) ;
76116 return false ;
77117 }
0 commit comments