(line: string)
| 267 | * or null if the line could not be parsed as a Git progress line. |
| 268 | */ |
| 269 | export function parse(line: string): IGitProgressInfo | null { |
| 270 | const titleLength = line.lastIndexOf(': ') |
| 271 | |
| 272 | if (titleLength === 0) { |
| 273 | return null |
| 274 | } |
| 275 | |
| 276 | if (titleLength - 2 >= line.length) { |
| 277 | return null |
| 278 | } |
| 279 | |
| 280 | const title = line.substring(0, titleLength) |
| 281 | const progressText = line.substring(title.length + 2).trim() |
| 282 | |
| 283 | if (!progressText.length) { |
| 284 | return null |
| 285 | } |
| 286 | |
| 287 | const progressParts = progressText.split(', ') |
| 288 | |
| 289 | if (!progressParts.length) { |
| 290 | return null |
| 291 | } |
| 292 | |
| 293 | let value: number |
| 294 | let total: number | undefined = undefined |
| 295 | let percent: number | undefined = undefined |
| 296 | |
| 297 | if (valueOnlyRe.test(progressParts[0])) { |
| 298 | value = parseInt(progressParts[0], 10) |
| 299 | |
| 300 | if (isNaN(value)) { |
| 301 | return null |
| 302 | } |
| 303 | } else { |
| 304 | const percentMatch = percentRe.exec(progressParts[0]) |
| 305 | |
| 306 | if (!percentMatch || percentMatch.length !== 4) { |
| 307 | return null |
| 308 | } |
| 309 | |
| 310 | percent = parseInt(percentMatch[1], 10) |
| 311 | value = parseInt(percentMatch[2], 10) |
| 312 | total = parseInt(percentMatch[3], 10) |
| 313 | |
| 314 | if (isNaN(percent) || isNaN(value) || isNaN(total)) { |
| 315 | return null |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | let done = false |
| 320 | |
| 321 | // We don't parse throughput at the moment so let's just loop |
| 322 | // through the remaining |
| 323 | for (let i = 1; i < progressParts.length; i++) { |
| 324 | if (progressParts[i] === 'done.') { |
| 325 | done = true |
| 326 | break |
no outgoing calls
no test coverage detected