@@ -23,6 +23,7 @@ import {
2323import {
2424 RunPRJob
2525} from '../lib/ci/run_ci.js' ;
26+ import { ResumePRJob } from '../lib/ci/resume_ci.js' ;
2627import { writeJson , writeFile } from '../lib/file.js' ;
2728import { getMergedConfig } from '../lib/config.js' ;
2829import { runPromise } from '../lib/run.js' ;
@@ -134,6 +135,26 @@ const args = yargs(hideBin(process.argv))
134135 } ,
135136 handler
136137 } )
138+ . command ( {
139+ command : 'resume <prid>' ,
140+ desc : 'Resume the latest CI run for given PR' ,
141+ builder : ( yargs ) => {
142+ yargs
143+ . positional ( 'prid' , {
144+ describe : 'ID of the PR or URL to the PR' ,
145+ type : 'string'
146+ } )
147+ . option ( 'owner' , {
148+ default : '' ,
149+ describe : 'GitHub repository owner'
150+ } )
151+ . option ( 'repo' , {
152+ default : '' ,
153+ describe : 'GitHub repository name'
154+ } ) ;
155+ } ,
156+ handler
157+ } )
137158 . command ( {
138159 command : 'url <url>' ,
139160 desc : 'Automatically detect CI type and show results' ,
@@ -278,11 +299,13 @@ class RunPRJobCommand {
278299 return this . argv . prid ;
279300 }
280301
281- async start ( ) {
282- const {
283- cli, request, prid, repo, owner
284- } = this ;
302+ validate ( ) {
303+ const { cli, prid, repo, owner } = this ;
285304 let validArgs = true ;
305+ if ( ! Number . isSafeInteger ( prid ) || prid <= 0 ) {
306+ validArgs = false ;
307+ cli . error ( 'Pull request ID must be a positive integer' ) ;
308+ }
286309 if ( ! repo ) {
287310 validArgs = false ;
288311 cli . error ( 'GitHub repository is missing, please set it via ncu-config ' +
@@ -295,6 +318,13 @@ class RunPRJobCommand {
295318 }
296319 if ( ! validArgs ) {
297320 this . cli . setExitCode ( 1 ) ;
321+ }
322+ return validArgs ;
323+ }
324+
325+ async start ( ) {
326+ const { cli, request, prid, repo, owner } = this ;
327+ if ( ! this . validate ( ) ) {
298328 return ;
299329 }
300330 const { certifySafe, checkForDuplicates } = this . argv ;
@@ -308,6 +338,20 @@ class RunPRJobCommand {
308338 }
309339}
310340
341+ class ResumePRJobCommand extends RunPRJobCommand {
342+ async start ( ) {
343+ const { cli, request, prid, repo, owner } = this ;
344+ if ( ! this . validate ( ) ) {
345+ return ;
346+ }
347+ const jobRunner = new ResumePRJob ( cli , request , owner , repo , prid ) ;
348+ if ( ! ( await jobRunner . resume ( ) ) ) {
349+ cli . setExitCode ( 1 ) ;
350+ process . exitCode = 1 ;
351+ }
352+ }
353+ }
354+
311355class CICommand {
312356 constructor ( cli , request , argv ) {
313357 this . cli = cli ;
@@ -565,7 +609,8 @@ async function main(command, argv) {
565609 let commandHandler ;
566610 // Prepare queue.
567611 switch ( command ) {
568- case 'run' : {
612+ case 'run' :
613+ case 'resume' : {
569614 const maybeURL = URL . parse ( argv . prid ) ;
570615 if ( maybeURL ?. host === 'github.com' ) {
571616 const [ , owner , repo , , prid , , commit_sha ] = maybeURL . pathname . split ( '/' ) ;
@@ -575,7 +620,8 @@ async function main(command, argv) {
575620 argv . prid = prid ;
576621 }
577622 argv . prid = Number ( argv . prid ) ;
578- const jobRunner = new RunPRJobCommand ( cli , request , argv ) ;
623+ const Command = command === 'run' ? RunPRJobCommand : ResumePRJobCommand ;
624+ const jobRunner = new Command ( cli , request , argv ) ;
579625 return jobRunner . start ( ) ;
580626 }
581627 case 'rate' : {
0 commit comments