Skip to content

Commit 450212e

Browse files
committed
Merge branch 'capitalize-commit'
2 parents b8db207 + df0c982 commit 450212e

File tree

9 files changed

+36
-10
lines changed

9 files changed

+36
-10
lines changed

cargo-smart-release/src/changelog/write.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ impl Section {
107107
mut out: impl std::fmt::Write,
108108
link_mode: &Linkables,
109109
components: Components,
110+
capitalize_commit: bool,
110111
) -> std::fmt::Result {
111112
match self {
112113
Section::Verbatim { text, .. } => {
@@ -149,7 +150,7 @@ impl Section {
149150

150151
let section_level = *heading_level + 1;
151152
for segment in segments {
152-
segment.write_to(section_level, link_mode, components, &mut out)?;
153+
segment.write_to(section_level, link_mode, components, capitalize_commit, &mut out)?;
153154
}
154155
if !unknown.is_empty() && components.contains(Components::HTML_TAGS) {
155156
writeln!(out, "{}", Section::UNKNOWN_TAG_START)?;
@@ -181,9 +182,10 @@ impl ChangeLog {
181182
mut out: impl std::fmt::Write,
182183
link_mode: &Linkables,
183184
components: Components,
185+
capitalize_commit: bool,
184186
) -> std::fmt::Result {
185187
for section in &self.sections {
186-
section.write_to(&mut out, link_mode, components)?;
188+
section.write_to(&mut out, link_mode, components, capitalize_commit)?;
187189
}
188190
Ok(())
189191
}
@@ -195,6 +197,7 @@ impl section::Segment {
195197
section_level: usize,
196198
link_mode: &Linkables,
197199
components: Components,
200+
capitalize_commit: bool,
198201
mut out: impl std::fmt::Write,
199202
) -> std::fmt::Result {
200203
let write_html = components.contains(Components::HTML_TAGS);
@@ -233,6 +236,11 @@ impl section::Segment {
233236
for message in messages {
234237
match message {
235238
Message::Generated { title, id, body } => {
239+
let title = if capitalize_commit {
240+
capitalize_message_title(title)
241+
} else {
242+
Cow::Borrowed(title.as_str())
243+
};
236244
if write_html {
237245
writeln!(
238246
out,

cargo-smart-release/src/cli/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ fn main() -> anyhow::Result<()> {
2121
no_links,
2222
without,
2323
allow_dirty,
24+
capitalize_commit,
2425
} => {
2526
init_logging(false);
2627
command::changelog(
@@ -31,6 +32,7 @@ fn main() -> anyhow::Result<()> {
3132
preview: !no_preview,
3233
dependencies: !no_dependencies,
3334
generator_segments: names_to_segment_selection(&without)?,
35+
capitalize_commit,
3436
},
3537
crates,
3638
)?
@@ -60,6 +62,7 @@ fn main() -> anyhow::Result<()> {
6062
allow_fully_generated_changelogs,
6163
no_dependencies,
6264
no_isolate_dependencies_from_breaking_changes,
65+
capitalize_commit
6366
} => {
6467
let verbose = execute || verbose;
6568
init_logging(verbose);
@@ -86,6 +89,7 @@ fn main() -> anyhow::Result<()> {
8689
allow_fully_generated_changelogs,
8790
changelog_links: !no_changelog_links,
8891
allow_changelog_github_release: !no_changelog_github_release,
92+
capitalize_commit,
8993
},
9094
crates,
9195
to_bump_spec(bump.as_deref().unwrap_or(DEFAULT_BUMP_SPEC))?,

cargo-smart-release/src/cli/options.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ pub enum SubCommands {
157157
/// depend on an unpublished version with "--no-validate".
158158
#[clap(long, help_heading = Some("EXPERT"))]
159159
ignore_instability: bool,
160+
161+
/// Capitalize commit messages.
162+
#[clap(long, help_heading = Some("CHANGELOG"))]
163+
capitalize_commit: bool,
160164
},
161165
#[clap(name = "changelog", version = clap::crate_version!())]
162166
/// Generate changelogs from commit histories, non-destructively.
@@ -201,5 +205,9 @@ pub enum SubCommands {
201205
/// Do not generate links to commits and issues when writing the changelogs. This currently only works for GitHub.
202206
#[clap(long, help_heading = Some("CUSTOMIZATION"))]
203207
no_links: bool,
208+
209+
/// Capitalize commit messages.
210+
#[clap(long, help_heading = Some("CUSTOMIZATION"))]
211+
capitalize_commit: bool,
204212
},
205213
}

cargo-smart-release/src/command/changelog.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub fn changelog(opts: Options, crates: Vec<String>) -> anyhow::Result<()> {
1818
dry_run,
1919
preview,
2020
no_links,
21+
capitalize_commit,
2122
..
2223
} = opts;
2324
let bump_spec = if dependencies { BumpSpec::Auto } else { BumpSpec::Keep };
@@ -97,6 +98,7 @@ pub fn changelog(opts: Options, crates: Vec<String>) -> anyhow::Result<()> {
9798
} else {
9899
Components::all()
99100
},
101+
capitalize_commit,
100102
)
101103
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?;
102104
file.write_all(buf.as_bytes())

cargo-smart-release/src/command/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub mod release {
2525
pub allow_fully_generated_changelogs: bool,
2626
pub changelog_links: bool,
2727
pub allow_changelog_github_release: bool,
28+
pub capitalize_commit: bool,
2829
}
2930
}
3031
#[path = "release/mod.rs"]
@@ -43,6 +44,7 @@ pub mod changelog {
4344
// All the segments to generate
4445
pub generator_segments: segment::Selection,
4546
pub no_links: bool,
47+
pub capitalize_commit: bool,
4648
}
4749
}
4850
#[path = "changelog.rs"]

cargo-smart-release/src/command/release/manifest.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ fn gather_changelog_data<'meta>(
377377
Options {
378378
dry_run,
379379
generator_segments,
380+
capitalize_commit,
380381
..
381382
}: Options,
382383
) -> anyhow::Result<GatherOutcome<'meta>> {
@@ -484,6 +485,7 @@ fn gather_changelog_data<'meta>(
484485
} else {
485486
changelog::write::Components::all()
486487
},
488+
capitalize_commit,
487489
)?;
488490
lock.with_mut(|file| file.write_all(write_buf.as_bytes()))?;
489491
*made_change |= previous_content.map(|previous| write_buf != previous).unwrap_or(true);

cargo-smart-release/src/command/release/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ fn perform_release(ctx: &Context, options: Options, crates: &[Dependency<'_>]) -
437437
commit_id,
438438
release_section_by_publishee
439439
.get(&publishee.name.as_str())
440-
.and_then(|s| section_to_string(s, WriteMode::Tag)),
440+
.and_then(|s| section_to_string(s, WriteMode::Tag, options.capitalize_commit)),
441441
&ctx.base,
442442
options,
443443
)? {
@@ -449,7 +449,7 @@ fn perform_release(ctx: &Context, options: Options, crates: &[Dependency<'_>]) -
449449
for (publishee, new_version) in successful_publishees_and_version {
450450
release_section_by_publishee
451451
.get(&publishee.name.as_str())
452-
.and_then(|s| section_to_string(s, WriteMode::GitHubRelease))
452+
.and_then(|s| section_to_string(s, WriteMode::GitHubRelease, options.capitalize_commit))
453453
.map(|release_notes| github::create_release(publishee, new_version, &release_notes, options, &ctx.base))
454454
.transpose()?;
455455
}
@@ -512,7 +512,7 @@ enum WriteMode {
512512
GitHubRelease,
513513
}
514514

515-
fn section_to_string(section: &Section, mode: WriteMode) -> Option<String> {
515+
fn section_to_string(section: &Section, mode: WriteMode, capitalize_commit: bool) -> Option<String> {
516516
let mut b = String::new();
517517
section
518518
.write_to(
@@ -522,6 +522,7 @@ fn section_to_string(section: &Section, mode: WriteMode) -> Option<String> {
522522
WriteMode::Tag => changelog::write::Components::empty(),
523523
WriteMode::GitHubRelease => changelog::write::Components::DETAIL_TAGS,
524524
},
525+
capitalize_commit,
525526
)
526527
.ok()
527528
.map(|_| b)

cargo-smart-release/tests/changelog/write_and_parse/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn conventional_write_empty_messages() -> Result {
5959
let log = log.clone();
6060
for _round in 1..=2 {
6161
let mut md = String::new();
62-
log.write_to(&mut md, link_mode, changelog::write::Components::all())?;
62+
log.write_to(&mut md, link_mode, changelog::write::Components::all(), false)?;
6363
insta::assert_snapshot!(md);
6464

6565
let parsed_log = ChangeLog::from_markdown(&md);
@@ -72,7 +72,7 @@ fn conventional_write_empty_messages() -> Result {
7272
] {
7373
for section in &log.sections {
7474
let mut buf = String::new();
75-
section.write_to(&mut buf, &changelog::write::Linkables::AsText, *components)?;
75+
section.write_to(&mut buf, &changelog::write::Linkables::AsText, *components, false)?;
7676
insta::assert_snapshot!(buf);
7777
}
7878
}
@@ -164,7 +164,7 @@ fn all_section_types_round_trips_lossy() -> Result {
164164
] {
165165
// NOTE: we can't run this a second time as the statistical information will be gone (it was never parsed back)
166166
let mut md = String::new();
167-
log.write_to(&mut md, link_mode, changelog::write::Components::all())?;
167+
log.write_to(&mut md, link_mode, changelog::write::Components::all(), false)?;
168168
insta::assert_snapshot!(md);
169169

170170
let parsed_log = ChangeLog::from_markdown(&md);
@@ -178,7 +178,7 @@ fn all_section_types_round_trips_lossy() -> Result {
178178
] {
179179
for section in &log.sections {
180180
let mut buf = String::new();
181-
section.write_to(&mut buf, &changelog::write::Linkables::AsText, *components)?;
181+
section.write_to(&mut buf, &changelog::write::Linkables::AsText, *components, false)?;
182182
insta::assert_snapshot!(buf);
183183
}
184184
}

cargo-smart-release/tests/changelog/write_and_parse/snapshots/integration__changelog__write_and_parse__conventional_write_empty_messages.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: cargo-smart-release/tests/changelog/write_and_parse/mod.rs
33
expression: md
4-
54
---
65
#### v1.0.2-beta.2 (1970-01-01)
76

0 commit comments

Comments
 (0)