parseDiffResult parses unified diff output and categorizes files by their status change. New files (--- /dev/null) with +status: pending are "Added"; all others are categorized by their +status: line.
(diff string)
| 346 | // status change. New files (--- /dev/null) with +status: pending are "Added"; |
| 347 | // all others are categorized by their +status: line. |
| 348 | func parseDiffResult(diff string) DiffResult { |
| 349 | var result DiffResult |
| 350 | var currentFile string |
| 351 | var isNewFile bool |
| 352 | |
| 353 | s := bufio.NewScanner(strings.NewReader(diff)) |
| 354 | for s.Scan() { |
| 355 | line := s.Text() |
| 356 | if strings.HasPrefix(line, "--- ") { |
| 357 | isNewFile = line == "--- /dev/null" |
| 358 | } else if strings.HasPrefix(line, "+++ b/") { |
| 359 | currentFile = strings.TrimPrefix(line, "+++ b/") |
| 360 | } else if currentFile != "" && strings.HasPrefix(line, "+status: ") { |
| 361 | status := strings.TrimPrefix(line, "+status: ") |
| 362 | status = strings.TrimSpace(status) |
| 363 | switch status { |
| 364 | case "completed": |
| 365 | result.Completed = append(result.Completed, currentFile) |
| 366 | case "pending": |
| 367 | if isNewFile { |
| 368 | result.Added = append(result.Added, currentFile) |
| 369 | } |
| 370 | case "in-progress": |
| 371 | result.Started = append(result.Started, currentFile) |
| 372 | case "blocked": |
| 373 | result.Blocked = append(result.Blocked, currentFile) |
| 374 | case "cancelled": |
| 375 | result.Cancelled = append(result.Cancelled, currentFile) |
| 376 | } |
| 377 | currentFile = "" // avoid duplicates from same file |
| 378 | } |
| 379 | } |
| 380 | return result |
| 381 | } |
| 382 | |
| 383 | // TaskChanges holds tasks categorized by their change type. |
| 384 | type TaskChanges struct { |