Skip to content

Commit ef978fd

Browse files
committed
feedback
1 parent 79dd288 commit ef978fd

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

packages/web/src/app/api/(server)/source/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const POST = async (request: NextRequest) => {
2727
}
2828

2929

30-
const postSource = (request: FileSourceRequest, domain: string) => sew(() =>
30+
export const postSource = (request: FileSourceRequest, domain: string) => sew(() =>
3131
withAuth(async (session) =>
3232
withOrgMembership(session, domain, async ({ orgId }) => {
3333
const response = await getFileSource(request, orgId);

packages/web/src/features/agents/review-agent/nodes/fetchFileContent.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { sourcebot_context, sourcebot_pr_payload } from "@/features/agents/review-agent/types";
22
import { fileSourceResponseSchema } from "@/features/search/schemas";
33
import { base64Decode } from "@/lib/utils";
4+
import { postSource } from "@/app/api/(server)/source/route";
5+
import { isServiceError } from "@/lib/utils";
46

57
export const fetchFileContent = async (pr_payload: sourcebot_pr_payload, filename: string): Promise<sourcebot_context> => {
68
console.log("Executing fetch_file_content");
@@ -12,21 +14,12 @@ export const fetchFileContent = async (pr_payload: sourcebot_pr_payload, filenam
1214
}
1315
console.log(JSON.stringify(fileSourceRequest, null, 2));
1416

15-
const response = await fetch('http://localhost:3000/api/source', {
16-
method: 'POST',
17-
headers: {
18-
'Content-Type': 'application/json',
19-
'X-Org-Domain': '~'
20-
},
21-
body: JSON.stringify(fileSourceRequest)
22-
});
23-
24-
if (!response.ok) {
25-
throw new Error(`Failed to fetch file content for ${filename} from ${repoPath}: ${response.statusText}`);
17+
const response = await postSource(fileSourceRequest, "~");
18+
if (isServiceError(response)) {
19+
throw new Error(`Failed to fetch file content for ${filename} from ${repoPath}: ${response.message}`);
2620
}
2721

28-
const responseData = await response.json();
29-
const fileSourceResponse = fileSourceResponseSchema.parse(responseData);
22+
const fileSourceResponse = fileSourceResponseSchema.parse(response);
3023
const fileContent = base64Decode(fileSourceResponse.source);
3124

3225
const fileContentContext: sourcebot_context = {

packages/web/src/features/agents/review-agent/nodes/githubPrParser.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ export const githubPrParser = async (octokit: Octokit, payload: WebhookEventDefi
1010
throw new Error("Installation not found in github payload");
1111
}
1212

13-
const diff = await octokit.request(payload.pull_request.patch_url);
14-
const parsedDiff: parse.File[] = parse(diff.data);
13+
let parsedDiff: parse.File[] = [];
14+
try {
15+
const diff = await octokit.request(payload.pull_request.patch_url);
16+
parsedDiff = parse(diff.data);
17+
} catch (error) {
18+
console.error("Error fetching diff: ", error);
19+
throw error;
20+
}
1521

1622
const sourcebotFileDiffs: (sourcebot_file_diff | null)[] = parsedDiff.map((file) => {
1723
if (!file.from || !file.to) {
@@ -20,8 +26,8 @@ export const githubPrParser = async (octokit: Octokit, payload: WebhookEventDefi
2026
}
2127

2228
const diffs: sourcebot_diff[] = file.chunks.map((chunk) => {
23-
let oldSnippet = "";
24-
let newSnippet = "";
29+
let oldSnippet = `@@ -${chunk.oldStart},${chunk.oldLines} +${chunk.newStart},${chunk.newLines} @@\n`;
30+
let newSnippet = `@@ -${chunk.oldStart},${chunk.oldLines} +${chunk.newStart},${chunk.newLines} @@\n`;
2531

2632
for (const change of chunk.changes) {
2733
if (change.type === "normal") {

0 commit comments

Comments
 (0)