Skip to content

Commit

Permalink
fix(commit): fix regex pattern for capturing commit message
Browse files Browse the repository at this point in the history
The regex pattern used to capture the commit message was not correctly capturing the scope when it contained non-word characters. This fix updates the pattern to capture the scope using the `\S` character class, which matches any non-whitespace character.
  • Loading branch information
liblaf committed Nov 18, 2023
1 parent cd04380 commit 69659ae
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/cmd/commit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ impl Run for Cmd {
.top_p(self.top_p)
.build()
.log()?;
tracing::debug!("{:#?}", request);
let response = client.chat().create(request).await.log()?;
tracing::debug!("{:#?}", response);
if let Some(usage) = response.usage {
println!(
"Tokens: {} (prompt) + {} (completion) = {} (total)",
Expand Down Expand Up @@ -132,7 +134,7 @@ where
let mut lines: Vec<_> = message.trim().split('\n').collect();
let subject = lines[0].trim();
let pattern: Regex =
Regex::new(r"(?P<type>\w+)(?:\((?P<scope>\w+)\))?(?P<breaking>!)?: (?P<description>.+)")
Regex::new(r"(?P<type>\w+)(?:\((?P<scope>\S+)\))?(?P<breaking>!)?: (?P<description>.+)")
.log()
.unwrap();
let matches = pattern.captures(subject)?;
Expand Down

0 comments on commit 69659ae

Please sign in to comment.