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; + }, []); };