@@ -14,8 +14,12 @@ const {
1414 PRBuild, BenchmarkRun, CommitBuild, HealthBuild,
1515 listBuilds, FailureAggregator, jobCache
1616} = require ( '../lib/ci/ci_result_parser' ) ;
17+ const {
18+ RunPRJob
19+ } = require ( '../lib/ci/run_ci' ) ;
1720const clipboardy = require ( 'clipboardy' ) ;
1821const { writeJson, writeFile } = require ( '../lib/file' ) ;
22+ const { getMergedConfig } = require ( '../lib/config' ) ;
1923
2024const { runPromise } = require ( '../lib/run' ) ;
2125const auth = require ( '../lib/auth' ) ;
@@ -70,6 +74,26 @@ const argv = yargs
7074 } ,
7175 handler
7276 } )
77+ . command ( {
78+ command : 'run <prid>' ,
79+ desc : 'Run CI for given PR' ,
80+ builder : ( yargs ) => {
81+ yargs
82+ . positional ( 'prid' , {
83+ describe : 'ID of the PR' ,
84+ type : 'number'
85+ } )
86+ . option ( 'owner' , {
87+ default : '' ,
88+ describe : 'GitHub repository owner'
89+ } )
90+ . option ( 'repo' , {
91+ default : '' ,
92+ describe : 'GitHub repository name'
93+ } ) ;
94+ } ,
95+ handler
96+ } )
7397 . command ( {
7498 command : 'url <url>' ,
7599 desc : 'Automatically detect CI type and show results' ,
@@ -147,6 +171,54 @@ const commandToType = {
147171 benchmark : BENCHMARK
148172} ;
149173
174+ class RunPRJobCommand {
175+ constructor ( cli , request , argv ) {
176+ this . cli = cli ;
177+ this . request = request ;
178+ this . dir = process . cwd ( ) ;
179+ this . argv = argv ;
180+ this . config = getMergedConfig ( this . dir ) ;
181+ }
182+
183+ get owner ( ) {
184+ return this . argv . owner || this . config . owner ;
185+ }
186+
187+ get repo ( ) {
188+ return this . argv . repo || this . config . repo ;
189+ }
190+
191+ get prid ( ) {
192+ return this . argv . prid ;
193+ }
194+
195+ async start ( ) {
196+ const {
197+ cli, request, prid, repo, owner
198+ } = this ;
199+ let validArgs = true ;
200+ if ( ! repo ) {
201+ validArgs = false ;
202+ cli . error ( 'GitHub repository is missing, please set it via ncu-config ' +
203+ 'or pass it via the --repo option' ) ;
204+ }
205+ if ( ! owner ) {
206+ cli . error ( 'GitHub owner is missing, please set it via ncu-config ' +
207+ 'or pass it via the --owner option' ) ;
208+ validArgs = false ;
209+ }
210+ if ( ! validArgs ) {
211+ this . cli . setExitCode ( 1 ) ;
212+ return ;
213+ }
214+ const jobRunner = new RunPRJob ( cli , request , owner , repo , prid ) ;
215+ if ( ! jobRunner . start ( ) ) {
216+ this . cli . setExitCode ( 1 ) ;
217+ process . exitCode = 1 ;
218+ }
219+ }
220+ }
221+
150222class CICommand {
151223 constructor ( cli , request , argv ) {
152224 this . cli = cli ;
@@ -343,6 +415,10 @@ async function main(command, argv) {
343415 let commandHandler ;
344416 // Prepare queue.
345417 switch ( command ) {
418+ case 'run' : {
419+ const jobRunner = new RunPRJobCommand ( cli , request , argv ) ;
420+ return jobRunner . start ( ) ;
421+ }
346422 case 'rate' : {
347423 commandHandler = new RateCommand ( cli , request , argv ) ;
348424 break ;
0 commit comments