Skip to content

Commit a54e360

Browse files
authored
task complete: 91bae7b3-0211-4d51-9dbe-382b856819e8 (#216)
1 parent c119250 commit a54e360

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

packages/cli/bin/tps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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;

packages/cli/src/commands/pulse.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff 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

572582
export 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": {

packages/cli/test/pulse.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
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+
249276
describe("pollOnce", () => {
250277
test("new PR triggers opened mail to reviewers", () => {
251278
const config = makeConfig();

0 commit comments

Comments
 (0)