diff --git a/changelog.d/20230716_174100_GitHub_Actions_337-2.ron b/changelog.d/20230716_174100_GitHub_Actions_337-2.ron new file mode 100644 index 00000000..dce4916d --- /dev/null +++ b/changelog.d/20230716_174100_GitHub_Actions_337-2.ron @@ -0,0 +1,11 @@ +( + references: {}, + changes: { + "Added": [ + "comment-changes: ``--force`` mode", + ], + "Changed": [ + "comment-changes: work on entire commit message instead of certain part", + ], + }, +) diff --git a/src/changelog/comment_changes.rs b/src/changelog/comment_changes.rs index 80b52ebf..38300829 100644 --- a/src/changelog/comment_changes.rs +++ b/src/changelog/comment_changes.rs @@ -50,6 +50,10 @@ pub struct CommentChanges { #[arg(long, short = 'C')] fallback_category: Option, + /// Whether to enforce the fragment creation. + #[arg(long, short = 'F')] + force: bool, + /// The heading's level in the resulting fragment. #[arg( default_value = "3", @@ -109,6 +113,7 @@ impl CommentChanges { depth: None, extension: FragmentExportFormat::Rst, fallback_category: None, + force: false, heading: 3, keep_a_changelog: false, link: Vec::new(), @@ -190,7 +195,9 @@ impl Logic { } fn harvest_message(&self, message: &str) -> Option<(String, String)> { - if let Some((category, change)) = + if message.is_empty() { + None + } else if let Some((category, change)) = message.trim().split_once(&self.cli.delimiter) { let category = category.trim().to_string(); @@ -296,15 +303,28 @@ impl Logic { } if let Ok(commit) = repository.find_commit(oid) { - if let Some(message) = if self.cli.body { - commit.body() - } else { - commit.summary() - } { + if let Some(message) = commit.message() { + let (summary, body) = + message.split_once('\n').unwrap_or((message, "")); + if let Some((category, change)) = - self.harvest_message(message) + self.harvest_message(if self.cli.body { + body.trim() + } else { + summary.trim() + }) { Self::insert(&mut result, category, change); + } else if self.cli.force { + if let Some((category, change)) = + self.harvest_message(if self.cli.body { + summary.trim() + } else { + body.trim() + }) + { + Self::insert(&mut result, category, change); + } } } } else {