From a33f49a11bcb42327ef66b13eb8046f967046492 Mon Sep 17 00:00:00 2001 From: Manon Faour Date: Mon, 14 Aug 2023 17:05:54 +0100 Subject: [PATCH] fix: do not add file to prompt if only removed lines (#174) --- .../batchFiles/utils/createPromptFiles.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/review/prompt/constructPrompt/batchFiles/utils/createPromptFiles.ts b/src/review/prompt/constructPrompt/batchFiles/utils/createPromptFiles.ts index bb538513..9aafbb2e 100644 --- a/src/review/prompt/constructPrompt/batchFiles/utils/createPromptFiles.ts +++ b/src/review/prompt/constructPrompt/batchFiles/utils/createPromptFiles.ts @@ -118,7 +118,7 @@ export const createPromptFiles = ( maxPromptPayloadLength: number, maxSurroundingLines?: number ): PromptFile[] => { - return files.map((file) => { + return files.reduce((result: PromptFile[], file) => { const contentLines = file.fileContent.split("\n"); const changedLinesArray = file.changedLines.split("\n"); @@ -126,6 +126,10 @@ export const createPromptFiles = ( const { changedIndices, totalChangedLinesLength, minIndex, maxIndex } = getChangedIndicesAndLength(contentLines, changedLinesArray); + if (totalChangedLinesLength == 0) { + return result; + } + // Calculate remaining space and start/end positions let remainingSpace = maxPromptPayloadLength - totalChangedLinesLength - file.fileName.length; @@ -145,9 +149,10 @@ export const createPromptFiles = ( contentLines ); - return { + result.push({ fileName: file.fileName, promptContent: promptContent, - }; - }); + }); + return result; + }, []); };