( patch: StructuredPatchHunk[], newFileContent?: string, )
| 49 | * @param newFileContent Optional content string for new files |
| 50 | */ |
| 51 | export function countLinesChanged( |
| 52 | patch: StructuredPatchHunk[], |
| 53 | newFileContent?: string, |
| 54 | ): void { |
| 55 | let numAdditions = 0 |
| 56 | let numRemovals = 0 |
| 57 | |
| 58 | if (patch.length === 0 && newFileContent) { |
| 59 | // For new files, count all lines as additions |
| 60 | numAdditions = newFileContent.split(/\r?\n/).length |
| 61 | } else { |
| 62 | numAdditions = patch.reduce( |
| 63 | (acc, hunk) => acc + count(hunk.lines, _ => _.startsWith('+')), |
| 64 | 0, |
| 65 | ) |
| 66 | numRemovals = patch.reduce( |
| 67 | (acc, hunk) => acc + count(hunk.lines, _ => _.startsWith('-')), |
| 68 | 0, |
| 69 | ) |
| 70 | } |
| 71 | |
| 72 | addToTotalLinesChanged(numAdditions, numRemovals) |
| 73 | |
| 74 | getLocCounter()?.add(numAdditions, { type: 'added' }) |
| 75 | getLocCounter()?.add(numRemovals, { type: 'removed' }) |
| 76 | |
| 77 | logEvent('tengu_file_changed', { |
| 78 | lines_added: numAdditions, |
| 79 | lines_removed: numRemovals, |
| 80 | }) |
| 81 | } |
| 82 | |
| 83 | export function getPatchFromContents({ |
| 84 | filePath, |
no test coverage detected