Parse a git commit message into subject and description.
(message: &str)
| 4539 | |
| 4540 | /// Parse a git commit message into subject and description. |
| 4541 | fn parse_commit_message(message: &str) -> (String, Option<String>) { |
| 4542 | let lines: Vec<&str> = message.lines().collect(); |
| 4543 | |
| 4544 | if lines.is_empty() { |
| 4545 | return ("(no message)".to_string(), None); |
| 4546 | } |
| 4547 | |
| 4548 | let subject = lines[0].trim().to_string(); |
| 4549 | |
| 4550 | let body_lines: Vec<&str> = lines |
| 4551 | .iter() |
| 4552 | .skip(1) |
| 4553 | .skip_while(|line| line.trim().is_empty()) |
| 4554 | .copied() |
| 4555 | .collect(); |
| 4556 | |
| 4557 | let description = if body_lines.is_empty() { |
| 4558 | None |
| 4559 | } else { |
| 4560 | Some(body_lines.join("\n").trim().to_string()) |
| 4561 | }; |
| 4562 | |
| 4563 | (subject, description) |
| 4564 | } |
| 4565 | |
| 4566 | // ═══════════════════════════════════════════════════════════════════════════ |
| 4567 | // Tests |