| 107 | } |
| 108 | |
| 109 | function parseDiff(diff: string): LineChange[] { |
| 110 | const changeSummaries = diff.match(/@@ [ \d,+-]+ @@/g); |
| 111 | if (changeSummaries == null) { |
| 112 | return []; |
| 113 | } |
| 114 | return changeSummaries |
| 115 | .map(summary => summary.match(/^@@ -(\d+|\d+,\d+) \+(\d+|\d+,\d+) @@$/)) |
| 116 | .filter((matches): matches is RegExpMatchArray => matches != null) |
| 117 | .map((matches): LineChange => { |
| 118 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 119 | const [prevLine = '', prevAdded = '1'] = matches[1]!.split(','); |
| 120 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 121 | const [currLine = '', currAdded = '1'] = matches[2]!.split(','); |
| 122 | return { |
| 123 | prev: { |
| 124 | line: Number.parseInt(prevLine, 10), |
| 125 | count: Number.parseInt(prevAdded, 10), |
| 126 | }, |
| 127 | curr: { |
| 128 | line: Number.parseInt(currLine, 10), |
| 129 | count: Number.parseInt(currAdded, 10), |
| 130 | }, |
| 131 | }; |
| 132 | }); |
| 133 | } |
| 134 | |
| 135 | export function isFileChanged( |
| 136 | changedFiles: ChangedFiles, |