Parse a git commit message into subject and description.
(message: &str)
| 9679 | |
| 9680 | /// Parse a git commit message into subject and description. |
| 9681 | fn parse_commit_message(message: &str) -> (String, Option<String>) { |
| 9682 | let lines: Vec<&str> = message.lines().collect(); |
| 9683 | |
| 9684 | if lines.is_empty() { |
| 9685 | return ("(no message)".to_string(), None); |
| 9686 | } |
| 9687 | |
| 9688 | let subject = lines[0].trim().to_string(); |
| 9689 | |
| 9690 | let body_lines: Vec<&str> = lines |
| 9691 | .iter() |
| 9692 | .skip(1) |
| 9693 | .skip_while(|line| line.trim().is_empty()) |
| 9694 | .copied() |
| 9695 | .collect(); |
| 9696 | |
| 9697 | let description = if body_lines.is_empty() { |
| 9698 | None |
| 9699 | } else { |
| 9700 | Some(body_lines.join("\n").trim().to_string()) |
| 9701 | }; |
| 9702 | |
| 9703 | (subject, description) |
| 9704 | } |
| 9705 | |
| 9706 | // ═══════════════════════════════════════════════════════════════════════════ |
| 9707 | // Tests |