-
Notifications
You must be signed in to change notification settings - Fork 262
Expand file tree
/
Copy pathfetchFileContent.ts
More file actions
35 lines (28 loc) · 1.36 KB
/
fetchFileContent.ts
File metadata and controls
35 lines (28 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { sourcebot_context, sourcebot_pr_payload } from "@/features/agents/review-agent/types";
import { getFileSource } from "@/features/search/fileSourceApi";
import { fileSourceResponseSchema } from "@/features/search/types";
import { isServiceError } from "@/lib/utils";
import { createLogger } from "@sourcebot/shared";
const logger = createLogger('fetch-file-content');
export const fetchFileContent = async (pr_payload: sourcebot_pr_payload, filename: string): Promise<sourcebot_context> => {
logger.debug("Executing fetch_file_content");
const repoPath = pr_payload.hostDomain + "/" + pr_payload.owner + "/" + pr_payload.repo;
const fileSourceRequest = {
path: filename,
repo: repoPath,
}
logger.debug(JSON.stringify(fileSourceRequest, null, 2));
const response = await getFileSource(fileSourceRequest);
if (isServiceError(response)) {
throw new Error(`Failed to fetch file content for ${filename} from ${repoPath}: ${response.message}`);
}
const fileSourceResponse = fileSourceResponseSchema.parse(response);
const fileContent = fileSourceResponse.source;
const fileContentContext: sourcebot_context = {
type: "file_content",
description: `The content of the file ${filename}`,
context: fileContent,
}
logger.debug("Completed fetch_file_content");
return fileContentContext;
}