Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/bin/tps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ async function main() {
action: (rest[0] as "start" | "status" | "list" | undefined) ?? "start",
dryRun: Boolean(cli.flags["dry-run"]),
interval: cli.flags.interval ? Number(cli.flags.interval) : undefined,
json: Boolean(cli.flags.json),
repo: cli.flags.repo as string | undefined,
});
break;
Expand Down
16 changes: 13 additions & 3 deletions packages/cli/src/commands/pulse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,22 @@ export async function startPollLoop(
// Subcommands
// ---------------------------------------------------------------------------

function printStatus(): void {
const state = loadState();
export function printStatus(args: Pick<PulseArgs, "json"> = {}, state = loadState()): void {
if (!state.lastPollAt) {
console.log("Pulse has not run yet.");
return;
}
const active = Object.values(state.instances).filter((i) => i.state !== "merged");
if (args.json) {
console.log(
JSON.stringify({
lastPollAt: state.lastPollAt,
activeCount: active.length,
active,
}),
);
return;
}
console.log(`Last poll: ${state.lastPollAt}`);
console.log(`Active PRs: ${active.length}`);
for (const inst of active) {
Expand Down Expand Up @@ -567,6 +576,7 @@ export interface PulseArgs {
repo?: string;
interval?: number;
dryRun?: boolean;
json?: boolean;
}

export async function runPulse(args: PulseArgs): Promise<void> {
Expand All @@ -584,7 +594,7 @@ export async function runPulse(args: PulseArgs): Promise<void> {
break;
}
case "status": {
printStatus();
printStatus({ json: args.json });
break;
}
case "list": {
Expand Down
27 changes: 27 additions & 0 deletions packages/cli/test/pulse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
handleTransition,
checkReminders,
pollOnce,
printStatus,
pruneState,
startPollLoop,
type PrInstance,
Expand Down Expand Up @@ -246,6 +247,32 @@ describe("checkReminders", () => {
});
});

describe("printStatus", () => {
test("prints JSON status when requested", () => {
const state = makeState({
"pr:tpsdev-ai/cli#42": makeInstance(),
});
const logs: string[] = [];
const originalLog = console.log;
console.log = (value?: unknown) => {
logs.push(String(value));
};

try {
printStatus({ json: true }, state);
} finally {
console.log = originalLog;
}

expect(logs).toHaveLength(1);
const parsed = JSON.parse(logs[0]);
expect(parsed.lastPollAt).toBe(state.lastPollAt);
expect(parsed.activeCount).toBe(1);
expect(Array.isArray(parsed.active)).toBe(true);
expect(parsed.active[0].prNumber).toBe(42);
});
});

describe("pollOnce", () => {
test("new PR triggers opened mail to reviewers", () => {
const config = makeConfig();
Expand Down
Loading