(diff: string, maxChangeLength: number)
| 260 | } |
| 261 | |
| 262 | function splitDiff(diff: string, maxChangeLength: number) { |
| 263 | const lines = diff.split('\n'); |
| 264 | const splitDiffs = [] as string[]; |
| 265 | let currentDiff = ''; |
| 266 | |
| 267 | if (maxChangeLength <= 0) { |
| 268 | throw new Error(GenerateCommitMessageErrorEnum.outputTokensTooHigh); |
| 269 | } |
| 270 | |
| 271 | for (let line of lines) { |
| 272 | // If a single line exceeds maxChangeLength, split it into multiple lines |
| 273 | while (tokenCount(line) > maxChangeLength) { |
| 274 | const subLine = line.substring(0, maxChangeLength); |
| 275 | line = line.substring(maxChangeLength); |
| 276 | splitDiffs.push(subLine); |
| 277 | } |
| 278 | |
| 279 | // Check the tokenCount of the currentDiff and the line separately |
| 280 | if (tokenCount(currentDiff) + tokenCount('\n' + line) > maxChangeLength) { |
| 281 | // If adding the next line would exceed the maxChangeLength, start a new diff |
| 282 | splitDiffs.push(currentDiff); |
| 283 | currentDiff = line; |
| 284 | } else { |
| 285 | // Otherwise, add the line to the current diff |
| 286 | currentDiff += '\n' + line; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | // Add the last diff |
| 291 | if (currentDiff) { |
| 292 | splitDiffs.push(currentDiff); |
| 293 | } |
| 294 | |
| 295 | return splitDiffs; |
| 296 | } |
| 297 | |
| 298 | export const getCommitMsgsPromisesFromFileDiffs = async ( |
| 299 | diff: string, |
no test coverage detected
searching dependent graphs…