Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Search Entire Commit Message on Demand; fixes #337 #498

Merged
merged 4 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions changelog.d/20230716_174100_GitHub_Actions_337-2.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(
references: {},
changes: {
"Added": [
"comment-changes: ``--force`` mode",
],
"Changed": [
"comment-changes: work on entire commit message instead of certain part",
],
},
)
34 changes: 27 additions & 7 deletions src/changelog/comment_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ pub struct CommentChanges {
#[arg(long, short = 'C')]
fallback_category: Option<String>,

/// Whether to enforce the fragment creation.
#[arg(long, short = 'F')]
force: bool,
kevinmatthes marked this conversation as resolved.
Show resolved Hide resolved

/// The heading's level in the resulting fragment.
#[arg(
default_value = "3",
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
kevinmatthes marked this conversation as resolved.
Show resolved Hide resolved
}
}
} else {
Expand Down