Parse a git commit message into subject and description.
(message: &str)
| 4022 | |
| 4023 | /// Parse a git commit message into subject and description. |
| 4024 | fn parse_commit_message(message: &str) -> (String, Option<String>) { |
| 4025 | let lines: Vec<&str> = message.lines().collect(); |
| 4026 | |
| 4027 | if lines.is_empty() { |
| 4028 | return ("(no message)".to_string(), None); |
| 4029 | } |
| 4030 | |
| 4031 | let subject = lines[0].trim().to_string(); |
| 4032 | |
| 4033 | let body_lines: Vec<&str> = lines |
| 4034 | .iter() |
| 4035 | .skip(1) |
| 4036 | .skip_while(|line| line.trim().is_empty()) |
| 4037 | .copied() |
| 4038 | .collect(); |
| 4039 | |
| 4040 | let description = if body_lines.is_empty() { |
| 4041 | None |
| 4042 | } else { |
| 4043 | Some(body_lines.join("\n").trim().to_string()) |
| 4044 | }; |
| 4045 | |
| 4046 | (subject, description) |
| 4047 | } |
| 4048 | |
| 4049 | // ═══════════════════════════════════════════════════════════════════════════ |
| 4050 | // Tests |