File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1005,6 +1005,7 @@ async function main() {
10051005 action : ( rest [ 0 ] as "start" | "status" | "list" | undefined ) ?? "start" ,
10061006 dryRun : Boolean ( cli . flags [ "dry-run" ] ) ,
10071007 interval : cli . flags . interval ? Number ( cli . flags . interval ) : undefined ,
1008+ json : Boolean ( cli . flags . json ) ,
10081009 repo : cli . flags . repo as string | undefined ,
10091010 } ) ;
10101011 break ;
Original file line number Diff line number Diff line change @@ -531,13 +531,22 @@ export async function startPollLoop(
531531// Subcommands
532532// ---------------------------------------------------------------------------
533533
534- function printStatus ( ) : void {
535- const state = loadState ( ) ;
534+ export function printStatus ( args : Pick < PulseArgs , "json" > = { } , state = loadState ( ) ) : void {
536535 if ( ! state . lastPollAt ) {
537536 console . log ( "Pulse has not run yet." ) ;
538537 return ;
539538 }
540539 const active = Object . values ( state . instances ) . filter ( ( i ) => i . state !== "merged" ) ;
540+ if ( args . json ) {
541+ console . log (
542+ JSON . stringify ( {
543+ lastPollAt : state . lastPollAt ,
544+ activeCount : active . length ,
545+ active,
546+ } ) ,
547+ ) ;
548+ return ;
549+ }
541550 console . log ( `Last poll: ${ state . lastPollAt } ` ) ;
542551 console . log ( `Active PRs: ${ active . length } ` ) ;
543552 for ( const inst of active ) {
@@ -567,6 +576,7 @@ export interface PulseArgs {
567576 repo ?: string ;
568577 interval ?: number ;
569578 dryRun ?: boolean ;
579+ json ?: boolean ;
570580}
571581
572582export async function runPulse ( args : PulseArgs ) : Promise < void > {
@@ -584,7 +594,7 @@ export async function runPulse(args: PulseArgs): Promise<void> {
584594 break ;
585595 }
586596 case "status" : {
587- printStatus ( ) ;
597+ printStatus ( { json : args . json } ) ;
588598 break ;
589599 }
590600 case "list" : {
Original file line number Diff line number Diff line change 44 handleTransition ,
55 checkReminders ,
66 pollOnce ,
7+ printStatus ,
78 pruneState ,
89 startPollLoop ,
910 type PrInstance ,
@@ -246,6 +247,32 @@ describe("checkReminders", () => {
246247 } ) ;
247248} ) ;
248249
250+ describe ( "printStatus" , ( ) => {
251+ test ( "prints JSON status when requested" , ( ) => {
252+ const state = makeState ( {
253+ "pr:tpsdev-ai/cli#42" : makeInstance ( ) ,
254+ } ) ;
255+ const logs : string [ ] = [ ] ;
256+ const originalLog = console . log ;
257+ console . log = ( value ?: unknown ) => {
258+ logs . push ( String ( value ) ) ;
259+ } ;
260+
261+ try {
262+ printStatus ( { json : true } , state ) ;
263+ } finally {
264+ console . log = originalLog ;
265+ }
266+
267+ expect ( logs ) . toHaveLength ( 1 ) ;
268+ const parsed = JSON . parse ( logs [ 0 ] ) ;
269+ expect ( parsed . lastPollAt ) . toBe ( state . lastPollAt ) ;
270+ expect ( parsed . activeCount ) . toBe ( 1 ) ;
271+ expect ( Array . isArray ( parsed . active ) ) . toBe ( true ) ;
272+ expect ( parsed . active [ 0 ] . prNumber ) . toBe ( 42 ) ;
273+ } ) ;
274+ } ) ;
275+
249276describe ( "pollOnce" , ( ) => {
250277 test ( "new PR triggers opened mail to reviewers" , ( ) => {
251278 const config = makeConfig ( ) ;
You can’t perform that action at this time.
0 commit comments