Skip to content

Commit

Permalink
🚑️ Fix panic when commit message does not match regex
Browse files Browse the repository at this point in the history
semver: patch
  • Loading branch information
Somfic committed Jun 22, 2024
1 parent 40b460e commit 4052c0a
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/git/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,28 @@ impl Commit {
let commit_regex =
regex::Regex::new(r"^([^\w\s:()]+)?\s*(?:\(?([^\)]+)\)?\s*:)?\s*([\s\w]*)$").unwrap();

let captures = commit_regex.captures(&message).unwrap();

let emoji = captures.get(1).map(|m| m.as_str().trim().to_string());
let scope = captures.get(2).map(|m| m.as_str().trim().to_string());
let message = captures
.get(3)
.map(|m| m.as_str().trim().to_string())
.unwrap();

Self {
emoji,
scope,
message,
let captures = commit_regex.captures(&message);

match captures {
Some(captures) => {
let emoji = captures.get(1).map(|m| m.as_str().trim().to_string());
let scope = captures.get(2).map(|m| m.as_str().trim().to_string());
let message = captures
.get(3)
.map(|m| m.as_str().trim().to_string())
.unwrap_or_default();

Self {
emoji,
scope,
message,
}
}
None => Self {
emoji: None,
scope: None,
message,
},
}
}
}
Expand Down

0 comments on commit 4052c0a

Please sign in to comment.