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
107 mut out: impl std::fmt::Write,107 mut out: impl std::fmt::Write,
108 link_mode: &Linkables,108 link_mode: &Linkables,
109 components: Components,109 components: Components,
110 capitalize_commit: bool,
110 ) -> std::fmt::Result {111 ) -> std::fmt::Result {
111 match self {112 match self {
112 Section::Verbatim { text, .. } => {113 Section::Verbatim { text, .. } => {
@@ -149,7 +150,7 @@ impl Section { · 36 unmodified lines
149 150
150 let section_level = *heading_level + 1;151 let section_level = *heading_level + 1;
151 for segment in segments {152 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)?;
153 }154 }
154 if !unknown.is_empty() && components.contains(Components::HTML_TAGS) {155 if !unknown.is_empty() && components.contains(Components::HTML_TAGS) {
155 writeln!(out, "{}", Section::UNKNOWN_TAG_START)?;156 writeln!(out, "{}", Section::UNKNOWN_TAG_START)?;
@@ -181,9 +182,10 @@ impl ChangeLog { · 25 unmodified lines
181 mut out: impl std::fmt::Write,182 mut out: impl std::fmt::Write,
182 link_mode: &Linkables,183 link_mode: &Linkables,
183 components: Components,184 components: Components,
185 capitalize_commit: bool,
184 ) -> std::fmt::Result {186 ) -> std::fmt::Result {
185 for section in &self.sections {187 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)?;
187 }189 }
188 Ok(())190 Ok(())
189 }191 }
@@ -195,6 +197,7 @@ impl section::Segment { · 5 unmodified lines
195 section_level: usize,197 section_level: usize,
196 link_mode: &Linkables,198 link_mode: &Linkables,
197 components: Components,199 components: Components,
200 capitalize_commit: bool,
198 mut out: impl std::fmt::Write,201 mut out: impl std::fmt::Write,
199 ) -> std::fmt::Result {202 ) -> std::fmt::Result {
200 let write_html = components.contains(Components::HTML_TAGS);203 let write_html = components.contains(Components::HTML_TAGS);
@@ -233,6 +236,11 @@ impl section::Segment { · 32 unmodified lines
233 for message in messages {236 for message in messages {
234 match message {237 match message {
235 Message::Generated { title, id, body } => {238 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 };
236 if write_html {244 if write_html {
237 writeln!(245 writeln!(
238 out,246 out,
cargo-smart-release/src/cli/main.rs+4−0
@@ -21,6 +21,7 @@ fn main() -> anyhow::Result<()> { · 20 unmodified lines
21 no_links,21 no_links,
22 without,22 without,
23 allow_dirty,23 allow_dirty,
24 capitalize_commit,
24 } => {25 } => {
25 init_logging(false);26 init_logging(false);
26 command::changelog(27 command::changelog(
@@ -31,6 +32,7 @@ fn main() -> anyhow::Result<()> { · 4 unmodified lines
31 preview: !no_preview,32 preview: !no_preview,
32 dependencies: !no_dependencies,33 dependencies: !no_dependencies,
33 generator_segments: names_to_segment_selection(&without)?,34 generator_segments: names_to_segment_selection(&without)?,
35 capitalize_commit,
34 },36 },
35 crates,37 crates,
36 )?38 )?
@@ -60,6 +62,7 @@ fn main() -> anyhow::Result<()> { · 23 unmodified lines
60 allow_fully_generated_changelogs,62 allow_fully_generated_changelogs,
61 no_dependencies,63 no_dependencies,
62 no_isolate_dependencies_from_breaking_changes,64 no_isolate_dependencies_from_breaking_changes,
65 capitalize_commit
63 } => {66 } => {
64 let verbose = execute || verbose;67 let verbose = execute || verbose;
65 init_logging(verbose);68 init_logging(verbose);
@@ -86,6 +89,7 @@ fn main() -> anyhow::Result<()> { · 20 unmodified lines
86 allow_fully_generated_changelogs,89 allow_fully_generated_changelogs,
87 changelog_links: !no_changelog_links,90 changelog_links: !no_changelog_links,
88 allow_changelog_github_release: !no_changelog_github_release,91 allow_changelog_github_release: !no_changelog_github_release,
92 capitalize_commit,
89 },93 },
90 crates,94 crates,
91 to_bump_spec(bump.as_deref().unwrap_or(DEFAULT_BUMP_SPEC))?,95 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
157 /// depend on an unpublished version with "--no-validate".157 /// depend on an unpublished version with "--no-validate".
158 #[clap(long, help_heading = Some("EXPERT"))]158 #[clap(long, help_heading = Some("EXPERT"))]
159 ignore_instability: bool,159 ignore_instability: bool,
160
161 /// Automatically capitalize commit message
162 #[clap(long, help_heading = Some("CHANGELOG"))]
163 capitalize_commit: bool,
160 },164 },
161 #[clap(name = "changelog", version = clap::crate_version!())]165 #[clap(name = "changelog", version = clap::crate_version!())]
162 /// Generate changelogs from commit histories, non-destructively.166 /// Generate changelogs from commit histories, non-destructively.
@@ -201,5 +205,9 @@ pub enum SubCommands { · 38 unmodified lines
201 /// Do not generate links to commits and issues when writing the changelogs. This currently only works for GitHub.205 /// Do not generate links to commits and issues when writing the changelogs. This currently only works for GitHub.
202 #[clap(long, help_heading = Some("CUSTOMIZATION"))]206 #[clap(long, help_heading = Some("CUSTOMIZATION"))]
203 no_links: bool,207 no_links: bool,
208
209 /// Automatically capitalize commit message
210 #[clap(long, help_heading = Some("CUSTOMIZATION"))]
211 capitalize_commit: bool,
204 },212 },
205}213}
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
18 dry_run,18 dry_run,
19 preview,19 preview,
20 no_links,20 no_links,
21 capitalize_commit,
21 ..22 ..
22 } = opts;23 } = opts;
23 let bump_spec = if dependencies { BumpSpec::Auto } else { BumpSpec::Keep };24 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
97 } else {98 } else {
98 Components::all()99 Components::all()
99 },100 },
101 capitalize_commit,
100 )102 )
101 .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?;103 .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?;
102 file.write_all(buf.as_bytes())104 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
25 pub allow_fully_generated_changelogs: bool,25 pub allow_fully_generated_changelogs: bool,
26 pub changelog_links: bool,26 pub changelog_links: bool,
27 pub allow_changelog_github_release: bool,27 pub allow_changelog_github_release: bool,
28 pub capitalize_commit: bool,
28 }29 }
29}30}
30#[path = "release/mod.rs"]31#[path = "release/mod.rs"]
@@ -43,6 +44,7 @@ pub mod changelog { · 12 unmodified lines
43 // All the segments to generate44 // All the segments to generate
44 pub generator_segments: segment::Selection,45 pub generator_segments: segment::Selection,
45 pub no_links: bool,46 pub no_links: bool,
47 pub capitalize_commit: bool,
46 }48 }
47}49}
48#[path = "changelog.rs"]50#[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
377 Options {377 Options {
378 dry_run,378 dry_run,
379 generator_segments,379 generator_segments,
380 capitalize_commit,
380 ..381 ..
381 }: Options,382 }: Options,
382) -> anyhow::Result<GatherOutcome<'meta>> {383) -> anyhow::Result<GatherOutcome<'meta>> {
@@ -484,6 +485,7 @@ fn gather_changelog_data<'meta>( · 101 unmodified lines
484 } else {485 } else {
485 changelog::write::Components::all()486 changelog::write::Components::all()
486 },487 },
488 capitalize_commit
487 )?;489 )?;
488 lock.with_mut(|file| file.write_all(write_buf.as_bytes()))?;490 lock.with_mut(|file| file.write_all(write_buf.as_bytes()))?;
489 *made_change |= previous_content.map(|previous| write_buf != previous).unwrap_or(true);491 *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
437 commit_id,437 commit_id,
438 release_section_by_publishee438 release_section_by_publishee
439 .get(&publishee.name.as_str())439 .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)),
441 &ctx.base,441 &ctx.base,
442 options,442 options,
443 )? {443 )? {
@@ -449,7 +449,7 @@ fn perform_release(ctx: &Context, options: Options, crates: &[Dependency<'_>]) - · 5 unmodified lines
449 for (publishee, new_version) in successful_publishees_and_version {449 for (publishee, new_version) in successful_publishees_and_version {
450 release_section_by_publishee450 release_section_by_publishee
451 .get(&publishee.name.as_str())451 .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))
453 .map(|release_notes| github::create_release(publishee, new_version, &release_notes, options, &ctx.base))453 .map(|release_notes| github::create_release(publishee, new_version, &release_notes, options, &ctx.base))
454 .transpose()?;454 .transpose()?;
455 }455 }
@@ -512,7 +512,7 @@ enum WriteMode { · 56 unmodified lines
512 GitHubRelease,512 GitHubRelease,
513}513}
514 514
515fn section_to_string(section: &Section, mode: WriteMode) -> Option<String> {515fn section_to_string(section: &Section, mode: WriteMode, capitalize_commit: bool) -> Option<String> {
516 let mut b = String::new();516 let mut b = String::new();
517 section517 section
518 .write_to(518 .write_to(
@@ -522,6 +522,7 @@ fn section_to_string(section: &Section, mode: WriteMode) -> Option<String> { · 3 unmodified lines
522 WriteMode::Tag => changelog::write::Components::empty(),522 WriteMode::Tag => changelog::write::Components::empty(),
523 WriteMode::GitHubRelease => changelog::write::Components::DETAIL_TAGS,523 WriteMode::GitHubRelease => changelog::write::Components::DETAIL_TAGS,
524 },524 },
525 capitalize_commit,
525 )526 )
526 .ok()527 .ok()
527 .map(|_| b)528 .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
59 let log = log.clone();59 let log = log.clone();
60 for _round in 1..=2 {60 for _round in 1..=2 {
61 let mut md = String::new();61 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)?;
63 insta::assert_snapshot!(md);63 insta::assert_snapshot!(md);
64 64
65 let parsed_log = ChangeLog::from_markdown(&md);65 let parsed_log = ChangeLog::from_markdown(&md);
@@ -72,7 +72,7 @@ fn conventional_write_empty_messages() -> Result { · 6 unmodified lines
72 ] {72 ] {
73 for section in &log.sections {73 for section in &log.sections {
74 let mut buf = String::new();74 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)?;
76 insta::assert_snapshot!(buf);76 insta::assert_snapshot!(buf);
77 }77 }
78 }78 }
@@ -164,7 +164,7 @@ fn all_section_types_round_trips_lossy() -> Result { · 85 unmodified lines
164 ] {164 ] {
165 // NOTE: we can't run this a second time as the statistical information will be gone (it was never parsed back)165 // NOTE: we can't run this a second time as the statistical information will be gone (it was never parsed back)
166 let mut md = String::new();166 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)?;
168 insta::assert_snapshot!(md);168 insta::assert_snapshot!(md);
169 169
170 let parsed_log = ChangeLog::from_markdown(&md);170 let parsed_log = ChangeLog::from_markdown(&md);
@@ -178,7 +178,7 @@ fn all_section_types_round_trips_lossy() -> Result { · 7 unmodified lines
178 ] {178 ] {
179 for section in &log.sections {179 for section in &log.sections {
180 let mut buf = String::new();180 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)?;
182 insta::assert_snapshot!(buf);182 insta::assert_snapshot!(buf);
183 }183 }
184 }184 }