Skip to content

Review Agent #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feedback
  • Loading branch information
msukkari committed May 9, 2025
commit ef978fdd87f6e67478601ca6f5bbfed3e3c04dbf
2 changes: 1 addition & 1 deletion packages/web/src/app/api/(server)/source/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const POST = async (request: NextRequest) => {
}


const postSource = (request: FileSourceRequest, domain: string) => sew(() =>
export const postSource = (request: FileSourceRequest, domain: string) => sew(() =>
withAuth(async (session) =>
withOrgMembership(session, domain, async ({ orgId }) => {
const response = await getFileSource(request, orgId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { sourcebot_context, sourcebot_pr_payload } from "@/features/agents/review-agent/types";
import { fileSourceResponseSchema } from "@/features/search/schemas";
import { base64Decode } from "@/lib/utils";
import { postSource } from "@/app/api/(server)/source/route";
import { isServiceError } from "@/lib/utils";

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

const response = await fetch('http://localhost:3000/api/source', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Org-Domain': '~'
},
body: JSON.stringify(fileSourceRequest)
});

if (!response.ok) {
throw new Error(`Failed to fetch file content for ${filename} from ${repoPath}: ${response.statusText}`);
const response = await postSource(fileSourceRequest, "~");
if (isServiceError(response)) {
throw new Error(`Failed to fetch file content for ${filename} from ${repoPath}: ${response.message}`);
}

const responseData = await response.json();
const fileSourceResponse = fileSourceResponseSchema.parse(responseData);
const fileSourceResponse = fileSourceResponseSchema.parse(response);
const fileContent = base64Decode(fileSourceResponse.source);

const fileContentContext: sourcebot_context = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ export const githubPrParser = async (octokit: Octokit, payload: WebhookEventDefi
throw new Error("Installation not found in github payload");
}

const diff = await octokit.request(payload.pull_request.patch_url);
const parsedDiff: parse.File[] = parse(diff.data);
let parsedDiff: parse.File[] = [];
try {
const diff = await octokit.request(payload.pull_request.patch_url);
parsedDiff = parse(diff.data);
} catch (error) {
console.error("Error fetching diff: ", error);
throw error;
}

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

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

for (const change of chunk.changes) {
if (change.type === "normal") {
Expand Down