History

feat: add --capitalize-commit option to capitalize commit message in cargo-smart-release

eatradish committed 3 years ago

Commit 4a244a21 parent b8db2078 files · +36 −9Browse files

Unified · Split

8 files
  1. cargo-smart-release/src/changelog/write.rs +10 −2
  2. cargo-smart-release/src/cli/main.rs +4 −0
  3. cargo-smart-release/src/cli/options.rs +8 −0
  4. cargo-smart-release/src/command/changelog.rs +2 −0
  5. cargo-smart-release/src/command/mod.rs +2 −0
  6. cargo-smart-release/src/command/release/manifest.rs +2 −0
  7. cargo-smart-release/src/command/release/mod.rs +4 −3
  8. cargo-smart-release/tests/changelog/write_and_parse/mod.rs +4 −4
cargo-smart-release/src/changelog/write.rs+10−2
@@ -107,6 +107,7 @@ impl Section { · 106 unmodified lines
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 { · 36 unmodified lines
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 { · 25 unmodified lines
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 { · 5 unmodified lines
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 { · 32 unmodified lines
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+4−0
@@ -21,6 +21,7 @@ fn main() -> anyhow::Result<()> { · 20 unmodified lines
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<()> { · 4 unmodified lines
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<()> { · 23 unmodified lines
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<()> { · 20 unmodified lines
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+8−0
@@ -157,6 +157,10 @@ pub enum SubCommands { · 156 unmodified lines
157157 /// depend on an unpublished version with "--no-validate".
158158 #[clap(long, help_heading = Some("EXPERT"))]
159159 ignore_instability: bool,
160+
161+ /// Automatically capitalize commit message
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 { · 38 unmodified lines
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+ /// Automatically capitalize commit message
210+ #[clap(long, help_heading = Some("CUSTOMIZATION"))]
211+ capitalize_commit: bool,
204212 },
205213 }
cargo-smart-release/src/command/changelog.rs+2−0
@@ -18,6 +18,7 @@ pub fn changelog(opts: Options, crates: Vec<String>) -> anyhow::Result<()> { · 17 unmodified lines
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<()> { · 73 unmodified lines
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+2−0
@@ -25,6 +25,7 @@ pub mod release { · 24 unmodified lines
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 { · 12 unmodified lines
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+2−0
@@ -377,6 +377,7 @@ fn gather_changelog_data<'meta>( · 376 unmodified lines
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>( · 101 unmodified lines
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+4−3
@@ -437,7 +437,7 @@ fn perform_release(ctx: &Context, options: Options, crates: &[Dependency<'_>]) - · 436 unmodified lines
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<'_>]) - · 5 unmodified lines
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 { · 56 unmodified lines
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> { · 3 unmodified lines
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+4−4
@@ -59,7 +59,7 @@ fn conventional_write_empty_messages() -> Result { · 58 unmodified lines
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 { · 6 unmodified lines
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 { · 85 unmodified lines
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 { · 7 unmodified lines
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 }