Parse a git commit message into subject and description.
(message: &str)
| 4170 | |
| 4171 | /// Parse a git commit message into subject and description. |
| 4172 | fn parse_commit_message(message: &str) -> (String, Option<String>) { |
| 4173 | let lines: Vec<&str> = message.lines().collect(); |
| 4174 | |
| 4175 | if lines.is_empty() { |
| 4176 | return ("(no message)".to_string(), None); |
| 4177 | } |
| 4178 | |
| 4179 | let subject = lines[0].trim().to_string(); |
| 4180 | |
| 4181 | let body_lines: Vec<&str> = lines |
| 4182 | .iter() |
| 4183 | .skip(1) |
| 4184 | .skip_while(|line| line.trim().is_empty()) |
| 4185 | .copied() |
| 4186 | .collect(); |
| 4187 | |
| 4188 | let description = if body_lines.is_empty() { |
| 4189 | None |
| 4190 | } else { |
| 4191 | Some(body_lines.join("\n").trim().to_string()) |
| 4192 | }; |
| 4193 | |
| 4194 | (subject, description) |
| 4195 | } |
| 4196 | |
| 4197 | // ═══════════════════════════════════════════════════════════════════════════ |
| 4198 | // Tests |