From 1a47fdd8951b589203153791da657f556838c3ce Mon Sep 17 00:00:00 2001 From: Arun Murugan Date: Tue, 21 May 2024 13:54:46 -0400 Subject: [PATCH] Revert "Error handling for json response" --- src/main.ts | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/main.ts b/src/main.ts index 7df559e..0c622e4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -52,6 +52,7 @@ async function getDiff( pull_number, mediaType: { format: "diff" }, }); + // @ts-expect-error - response.data is a string return response.data; } @@ -78,17 +79,17 @@ async function analyzeCode( } function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string { - const newAndModifiedLines = chunk.changes.filter(change => change.add || (change.normal && change.content.trim() !== "")); - return `Your task is to review pull requests. Instructions: -- Provide the response in the following JSON format: {"reviews": [{"lineNumber": , "reviewComment": ""}]} +- Provide the response in following JSON format: {"reviews": [{"lineNumber": , "reviewComment": ""}]} - Do not give positive comments or compliments. - Provide comments and suggestions ONLY if there is something to improve, otherwise "reviews" should be an empty array. - Write the comment in GitHub Markdown format. - Use the given description only for the overall context and only comment the code. - IMPORTANT: NEVER suggest adding comments to the code. -Review the following code diff in the file "${file.to}" and take the pull request title and description into account when writing the response. +Review the following code diff in the file "${ + file.to + }" and take the pull request title and description into account when writing the response. Pull request title: ${prDetails.title} Pull request description: @@ -101,8 +102,9 @@ Git diff to review: \`\`\`diff ${chunk.content} -${newAndModifiedLines - .map((c) => `${c.add ? '+' : ''} ${c.ln ? c.ln : c.ln2} ${c.content}`) +${chunk.changes + // @ts-expect-error - ln and ln2 exists where needed + .map((c) => `${c.ln ? c.ln : c.ln2} ${c.content}`) .join("\n")} \`\`\` `; @@ -133,18 +135,10 @@ async function getAIResponse(prompt: string): Promise