Skip to content

Commit c931385

Browse files
committed
use gettask
1 parent e28930a commit c931385

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/api/posthogClient.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RepositoryConfig, TaskRun } from "@shared/types";
1+
import type { LogEntry, RepositoryConfig, Task, TaskRun } from "@shared/types";
22
import { buildApiFetcher } from "./fetcher";
33
import { createApiClient, type Schemas } from "./generated";
44

@@ -126,7 +126,7 @@ export class PostHogAPIClient {
126126
return data;
127127
}
128128

129-
async listTaskRuns(taskId: string) {
129+
async listTaskRuns(taskId: string): Promise<TaskRun[]> {
130130
const teamId = await this.getTeamId();
131131
const url = new URL(
132132
`${this.api.baseUrl}/api/projects/${teamId}/tasks/${taskId}/runs/`,
@@ -163,17 +163,13 @@ export class PostHogAPIClient {
163163
return await response.json();
164164
}
165165

166-
async getTaskLogs(taskId: string): Promise<string> {
166+
async getTaskLogs(taskId: string): Promise<LogEntry[]> {
167167
try {
168-
const runs = await this.listTaskRuns(taskId);
169-
const latestRun = runs?.sort(
170-
(a: TaskRun, b: TaskRun) =>
171-
new Date(b.created_at).getTime() - new Date(a.created_at).getTime(),
172-
)[0];
173-
return latestRun?.log ?? "";
168+
const task = (await this.getTask(taskId)) as Task;
169+
return task?.latest_run?.log ?? [];
174170
} catch (err) {
175-
console.warn("Failed to fetch task logs from runs", err);
176-
return "";
171+
console.warn("Failed to fetch task logs from latest run", err);
172+
return [];
177173
}
178174
}
179175

src/shared/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ export interface Task {
2222
latest_run?: TaskRun;
2323
}
2424

25+
export interface LogEntry {
26+
type: string; // e.g., "info", "warning", "error", "success", "debug"
27+
message: string;
28+
[key: string]: unknown; // Allow additional fields
29+
}
30+
2531
export interface TaskRun {
2632
id: string;
2733
task: string; // Task ID
2834
team: number;
2935
branch: string | null;
3036
current_stage: string | null; // WorkflowStage ID
3137
status: "started" | "in_progress" | "completed" | "failed";
32-
log: string;
38+
log: LogEntry[]; // Array of log entry objects
3339
error_message: string | null;
3440
output: Record<string, unknown> | null; // Structured output (PR URL, commit SHA, etc.)
3541
state: Record<string, unknown>; // Intermediate run state (defaults to {}, never null)

0 commit comments

Comments
 (0)