Skip to content

Commit c583e0a

Browse files
authored
Merge pull request GitoxideLabs#61 from GitoxideLabs/allow-generated
feat: add `--allow-empty-release-message` actually ignore empty changelogs
2 parents bd30507 + 2efb737 commit c583e0a

File tree

5 files changed

+66
-57
lines changed

5 files changed

+66
-57
lines changed

src/cli/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ fn main() -> anyhow::Result<()> {
5959
no_changelog_preview,
6060
no_changelog_github_release,
6161
allow_fully_generated_changelogs,
62+
allow_empty_release_message,
6263
no_dependencies,
6364
no_isolate_dependencies_from_breaking_changes,
6465
capitalize_commit,
@@ -88,6 +89,7 @@ fn main() -> anyhow::Result<()> {
8889
preview: !no_changelog_preview,
8990
generator_segments: names_to_segment_selection(&changelog_without)?,
9091
allow_fully_generated_changelogs,
92+
allow_empty_release_message,
9193
changelog_links: !no_changelog_links,
9294
allow_changelog_github_release: !no_changelog_github_release,
9395
capitalize_commit,

src/cli/options.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,15 @@ pub enum SubCommands {
8484
no_changelog_github_release: bool,
8585

8686
/// If changelogs are generated from git-conventional comments extracted from the commit history exclusively, publishes
87-
/// will fail as in order to give opportunity to author at least a portion of the upcoming release.
87+
/// will fail as to give an opportunity to author at least a portion of the upcoming release.
8888
///
8989
/// With this flag set, the release will not stop.
9090
/// Note that changelog entries purely composed of statistical information will always stop a release.
9191
#[clap(long, help_heading = Some("CHANGELOG-EXPERT"))]
9292
allow_fully_generated_changelogs: bool,
93+
/// If changelogs have no message or release information at all, continue anyway.
94+
#[clap(long, help_heading = Some("CHANGELOG-EXPERT"))]
95+
allow_empty_release_message: bool,
9396

9497
/// Do not generate links to commits and issues when writing the changelogs. This currently only works for GitHub.
9598
#[clap(long, help_heading = Some("CHANGELOG"))]

src/command/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub mod release {
2323
pub preview: bool,
2424
pub generator_segments: segment::Selection,
2525
pub allow_fully_generated_changelogs: bool,
26+
pub allow_empty_release_message: bool,
2627
pub changelog_links: bool,
2728
pub allow_changelog_github_release: bool,
2829
pub capitalize_commit: bool,

src/command/release/manifest.rs

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ use std::{
55
str::FromStr,
66
};
77

8-
use anyhow::{bail, Context as ContextTrait};
9-
use cargo_metadata::{camino::Utf8PathBuf, Package};
10-
use gix::{lock::File, Id};
11-
use semver::{Version, VersionReq};
12-
138
use super::{cargo, git, Context, Options};
149
use crate::{
1510
changelog,
@@ -18,6 +13,10 @@ use crate::{
1813
utils::{names_and_versions, try_to_published_crate_and_new_version, version_req_unset_or_default, will},
1914
version, ChangeLog,
2015
};
16+
use anyhow::{bail, Context as ContextTrait};
17+
use cargo_metadata::{camino::Utf8PathBuf, Package};
18+
use gix::{lock::File, Id};
19+
use semver::{Version, VersionReq};
2120

2221
pub struct Outcome<'repo, 'meta> {
2322
pub commit_id: Option<Id<'repo>>,
@@ -76,8 +75,9 @@ pub(in crate::command::release_impl) fn edit_version_and_fixup_dependent_crates_
7675
)?;
7776
}
7877

79-
let would_stop_release = !(changelog_ids_with_statistical_segments_only.is_empty()
80-
&& changelog_ids_probably_lacking_user_edits.is_empty());
78+
let would_stop_release = (!changelog_ids_with_statistical_segments_only.is_empty()
79+
&& !opts.allow_fully_generated_changelogs)
80+
|| (!changelog_ids_probably_lacking_user_edits.is_empty() && !opts.allow_empty_release_message);
8181
let safety_bumped_packages = crates
8282
.iter()
8383
.filter_map(|c| c.mode.safety_bump().map(|b| (c.package, &b.next_release)))
@@ -123,6 +123,7 @@ fn commit_locks_and_generate_bail_message(
123123
dry_run,
124124
skip_publish,
125125
allow_fully_generated_changelogs,
126+
allow_empty_release_message,
126127
..
127128
}: Options,
128129
) -> anyhow::Result<Option<String>> {
@@ -134,15 +135,15 @@ fn commit_locks_and_generate_bail_message(
134135
|| changelog_ids_with_statistical_segments_only.contains(&idx)
135136
{
136137
lock.commit()?;
137-
if !changelog_ids_with_statistical_segments_only.is_empty() {
138+
if !allow_fully_generated_changelogs && !changelog_ids_with_statistical_segments_only.is_empty() {
138139
packages_whose_changelogs_need_edits
139140
.get_or_insert_with(Vec::new)
140141
.push(package);
141142
}
142143
} else {
143144
drop(lock);
144145
}
145-
if changelog_ids_probably_lacking_user_edits.contains(&idx) {
146+
if allow_empty_release_message || changelog_ids_probably_lacking_user_edits.contains(&idx) {
146147
packages_which_might_be_fully_generated
147148
.get_or_insert_with(Vec::new)
148149
.push(package);
@@ -152,42 +153,40 @@ fn commit_locks_and_generate_bail_message(
152153
manifest_lock.commit()?;
153154
}
154155
// This is dangerous as incompatibilities can happen here, leaving the working tree dirty.
155-
// For now we leave it that way without auto-restoring originals to facilitate debugging.
156+
// For now, we leave it that way without auto-restoring originals to facilitate debugging.
156157
cargo::refresh_lock_file()?;
157158

158-
packages_whose_changelogs_need_edits
159-
.and_then(|logs| {
160-
let names_of_crates_in_need_of_changelog_entry =
161-
logs.iter().map(|p| p.name.as_str()).collect::<Vec<_>>().join(", ");
162-
if skip_publish {
163-
log::warn!(
164-
"Please consider creating changelog entries for crate{}: {}",
165-
if logs.len() == 1 { "" } else { "s" },
166-
names_of_crates_in_need_of_changelog_entry
167-
);
168-
None
169-
} else {
170-
Some(format!(
171-
"Write changelog entries for crate(s) {names_of_crates_in_need_of_changelog_entry} and try again"
172-
))
173-
}
174-
})
175-
.or_else(|| {
176-
packages_which_might_be_fully_generated.and_then(|packages| {
177-
let crate_names = packages.iter().map(|p| p.name.as_str()).collect::<Vec<_>>().join(", ");
178-
(!allow_fully_generated_changelogs).then(|| {
179-
format!(
180-
"{} edits by hand to avoid being entirely generated: {}",
181-
if crate_names.len() == 1 {
182-
"This changelog needs"
183-
} else {
184-
"These changelogs need"
185-
},
186-
crate_names
187-
)
188-
})
189-
})
159+
if let Some(logs) = packages_whose_changelogs_need_edits {
160+
let names_of_crates_in_need_of_changelog_entry =
161+
logs.iter().map(|p| p.name.as_str()).collect::<Vec<_>>().join(", ");
162+
if skip_publish {
163+
log::warn!(
164+
"Please consider creating changelog entries for crate{}: {}",
165+
if logs.len() == 1 { "" } else { "s" },
166+
names_of_crates_in_need_of_changelog_entry
167+
);
168+
None
169+
} else {
170+
Some(format!(
171+
"Write changelog entries for crate(s) {names_of_crates_in_need_of_changelog_entry} and try again"
172+
))
173+
}
174+
} else if let Some(packages) = packages_which_might_be_fully_generated {
175+
let crate_names = packages.iter().map(|p| p.name.as_str()).collect::<Vec<_>>().join(", ");
176+
(!allow_fully_generated_changelogs).then(|| {
177+
format!(
178+
"{} edits by hand to avoid being entirely generated: {}",
179+
if crate_names.len() == 1 {
180+
"This changelog needs"
181+
} else {
182+
"These changelogs need"
183+
},
184+
crate_names
185+
)
190186
})
187+
} else {
188+
None
189+
}
191190
} else {
192191
let crate_names = |ids: &[usize]| {
193192
ids.iter()
@@ -207,23 +206,27 @@ fn commit_locks_and_generate_bail_message(
207206
let crate_names = crate_names(&changelog_ids_with_statistical_segments_only);
208207
let names_of_crates_that_would_need_review = crate_names.join(", ");
209208
log::warn!(
210-
"WOULD {} as the changelog entry is empty for crate{}: {}",
211-
if skip_publish {
212-
"ask for review after commit"
213-
} else {
214-
"stop release after commit"
215-
},
216-
if changelog_ids_with_statistical_segments_only.len() == 1 {
209+
"WOULD {message}{plural_s}: {crates}",
210+
crates = names_of_crates_that_would_need_review,
211+
plural_s = if changelog_ids_with_statistical_segments_only.len() == 1 {
217212
""
218213
} else {
219214
"s"
220215
},
221-
names_of_crates_that_would_need_review
222-
);
223-
log::warn!(
224-
"To fix the changelog manually, run: cargo changelog --write {}",
225-
ctx.base.crate_names.join(" ")
216+
message = if allow_empty_release_message {
217+
"continue despite the changelog entry being empty for crate"
218+
} else if skip_publish {
219+
"ask for review after commit as the changelog entry is empty for crate"
220+
} else {
221+
"stop release after commit as the changelog entry is empty for crate"
222+
},
226223
);
224+
if !allow_empty_release_message {
225+
log::warn!(
226+
"To fix the changelog manually, run: cargo changelog --write {}",
227+
ctx.base.crate_names.join(" ")
228+
);
229+
}
227230
}
228231
if !changelog_ids_probably_lacking_user_edits.is_empty() {
229232
let crate_names = crate_names(&changelog_ids_probably_lacking_user_edits);

tests/snapshots/triple-depth-workspace/a-dry-run-success-multi-crate-auto-bump-breaking-change-dependant-publish

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
[TRACE] Pending 'b' manifest dependencies update: 'a = "^0.9.0"' (from "0.8.0" )
1212
[TRACE] Pending 'c' manifest version update: "9.0.0"
1313
[TRACE] Pending 'c' manifest dependencies update: 'b = "^0.9.0"' (from "0.8.0" )
14-
[TRACE] WOULD persist changes to 3 manifests and 3 changelogs (1 new) with: "Adjusting changelogs prior to release of a v0.9.0, b v0.9.0, c v9.0.0, safety bump 2 crates\n\nSAFETY BUMP: b v0.9.0, c v9.0.0"
14+
[TRACE] WOULD persist changes to 3 manifests and 3 changelogs (1 new) with: "Bump a v0.9.0, b v0.9.0, c v9.0.0, safety bump 2 crates\n\nSAFETY BUMP: b v0.9.0, c v9.0.0"
1515
[INFO ] Up to 3 changelogs would be previewed if the --execute is set and --no-changelog-preview is unset.
1616
[WARN ] WOULD ask for review after commit as the changelog entry is empty for crates: b, c
1717
[WARN ] To fix the changelog manually, run: cargo changelog --write c a
18-
[TRACE] WOULD run "git" "commit" "-am" "Adjusting changelogs prior to release of a v0.9.0, b v0.9.0, c v9.0.0, safety bump 2 crates\n\nSAFETY BUMP: b v0.9.0, c v9.0.0"
18+
[TRACE] WOULD run "git" "commit" "-am" "Bump a v0.9.0, b v0.9.0, c v9.0.0, safety bump 2 crates\n\nSAFETY BUMP: b v0.9.0, c v9.0.0"
1919
[TRACE] WOULD create tag object a-v0.9.0 with changelog message, first line is: '### Refactor (BREAKING)'
2020
[TRACE] WOULD create tag object b-v0.9.0 with changelog message, first line is: '### Commit Statistics'
2121
[TRACE] WOULD create tag object c-v9.0.0 with changelog message, first line is: '### Commit Statistics'

0 commit comments

Comments
 (0)