Parse a git commit message into subject and description.
(message: &str)
| 4140 | |
| 4141 | /// Parse a git commit message into subject and description. |
| 4142 | fn parse_commit_message(message: &str) -> (String, Option<String>) { |
| 4143 | let lines: Vec<&str> = message.lines().collect(); |
| 4144 | |
| 4145 | if lines.is_empty() { |
| 4146 | return ("(no message)".to_string(), None); |
| 4147 | } |
| 4148 | |
| 4149 | let subject = lines[0].trim().to_string(); |
| 4150 | |
| 4151 | let body_lines: Vec<&str> = lines |
| 4152 | .iter() |
| 4153 | .skip(1) |
| 4154 | .skip_while(|line| line.trim().is_empty()) |
| 4155 | .copied() |
| 4156 | .collect(); |
| 4157 | |
| 4158 | let description = if body_lines.is_empty() { |
| 4159 | None |
| 4160 | } else { |
| 4161 | Some(body_lines.join("\n").trim().to_string()) |
| 4162 | }; |
| 4163 | |
| 4164 | (subject, description) |
| 4165 | } |
| 4166 | |
| 4167 | // ═══════════════════════════════════════════════════════════════════════════ |
| 4168 | // Tests |