(output: string)
| 146 | } |
| 147 | |
| 148 | function parseNumstat(output: string): ReviewFile[] { |
| 149 | const fields = output.split("\0").filter((field) => field.length > 0); |
| 150 | const files: ReviewFile[] = []; |
| 151 | |
| 152 | for (let index = 0; index < fields.length;) { |
| 153 | const header = fields[index++] ?? ""; |
| 154 | const parts = header.split("\t"); |
| 155 | const additions = parseStatNumber(parts[0]); |
| 156 | const removals = parseStatNumber(parts[1]); |
| 157 | |
| 158 | if (parts.length >= 3) { |
| 159 | const path = parts[2] ?? ""; |
| 160 | if (path) files.push({ path, type: fileType(path, undefined, additions, removals), additions, removals }); |
| 161 | continue; |
| 162 | } |
| 163 | |
| 164 | const previousPath = fields[index++]; |
| 165 | const path = fields[index++]; |
| 166 | if (!path) continue; |
| 167 | |
| 168 | files.push({ |
| 169 | path, |
| 170 | previousPath, |
| 171 | type: fileType(path, previousPath, additions, removals), |
| 172 | additions, |
| 173 | removals, |
| 174 | }); |
| 175 | } |
| 176 | |
| 177 | return files; |
| 178 | } |
| 179 | |
| 180 | function parseStatNumber(value: string | undefined): number { |
| 181 | if (!value || value === "-") return 0; |
no test coverage detected