1.0 KB38 lines
Blame
1import { hubRequest } from "../api.js";
2import { getRepoSlug } from "../config.js";
3
4interface LogEntry {
5 stream: string;
6 content: string;
7 created_at: string;
8}
9
10export async function ciLogs(args: string[]) {
11 const slug = await getRepoSlug(args);
12
13 // Positional args: <run-id> <step-idx>
14 const positional = args.filter((a) => !a.startsWith("--") && args[args.indexOf(a) - 1] !== "--repo");
15 const runId = positional[0];
16 const stepIdx = positional[1];
17
18 if (!runId || stepIdx === undefined) {
19 console.error("Usage: grove ci logs <run-id> <step-index> [--repo <owner/repo>]");
20 process.exit(1);
21 }
22
23 const { logs } = await hubRequest<{ logs: LogEntry[] }>(
24 `/api/repos/${slug}/canopy/runs/${runId}/logs/${stepIdx}`
25 );
26
27 if (logs.length === 0) {
28 console.log("No logs for this step.");
29 return;
30 }
31
32 for (const entry of logs) {
33 const prefix = entry.stream === "stderr" ? "\x1b[31m" : "";
34 const reset = prefix ? "\x1b[0m" : "";
35 process.stdout.write(`${prefix}${entry.content}${reset}`);
36 }
37}
38