Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d44369a

Browse files
committed
Only write headlines that we can parse back… (#198)
…or else there will be duplication each time the changelog is regenerated.
1 parent e0d437c commit d44369a

5 files changed

Lines changed: 72 additions & 63 deletions

File tree

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ impl Section {
151151
State::SkipGenerated
152152
}
153153
Some((Event::Text(title), _range))
154-
if title.starts_with(as_headline("feat").as_ref())
155-
|| title.starts_with(as_headline("add").as_ref())
156-
|| title.starts_with(as_headline("revert").as_ref())
157-
|| title.starts_with(as_headline("remove").as_ref())
158-
|| title.starts_with(as_headline("change").as_ref())
159-
|| title.starts_with(as_headline("docs").as_ref())
160-
|| title.starts_with(as_headline("perf").as_ref())
161-
|| title.starts_with(as_headline("fix").as_ref()) =>
154+
if title.starts_with(as_headline("feat").expect("valid"))
155+
|| title.starts_with(as_headline("add").expect("valid"))
156+
|| title.starts_with(as_headline("revert").expect("valid"))
157+
|| title.starts_with(as_headline("remove").expect("valid"))
158+
|| title.starts_with(as_headline("change").expect("valid"))
159+
|| title.starts_with(as_headline("docs").expect("valid"))
160+
|| title.starts_with(as_headline("perf").expect("valid"))
161+
|| title.starts_with(as_headline("fix").expect("valid")) =>
162162
{
163163
State::ParseConventional {
164164
title: title.into_string(),
@@ -225,7 +225,7 @@ fn parse_conventional_to_next_section_title(
225225
let is_breaking = title.ends_with(section::segment::Conventional::BREAKING_TITLE);
226226
let kind = ["fix", "add", "feat", "revert", "remove", "change", "docs", "perf"]
227227
.iter()
228-
.find(|kind| title.starts_with(section::segment::conventional::as_headline(*kind).as_ref()))
228+
.find(|kind| title.starts_with(section::segment::conventional::as_headline(*kind).expect("valid")))
229229
.expect("BUG: this list needs an update too if new kinds of conventional messages are added");
230230

231231
let mut conventional = section::segment::Conventional {

cargo-smart-release/src/changelog/section/segment.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use bitflags::bitflags;
44
use git_repository as git;
55

66
pub mod conventional {
7-
use std::borrow::Cow;
8-
97
use git_repository as git;
108

119
/// A message that is associated with a Segment for a particular git-conventional segment
@@ -23,9 +21,9 @@ pub mod conventional {
2321
}
2422

2523
/// Note that this depends on `crate::commit::message::to_static()`,
26-
pub fn as_headline(kind: &str) -> Cow<'static, str> {
24+
pub fn as_headline(kind: &str) -> Option<&'static str> {
2725
// NOTE: adding one here needs additions to parse.rs
28-
match kind {
26+
Some(match kind {
2927
"fix" => "Fixed",
3028
"add" => "Added",
3129
"feat" => "New Features",
@@ -34,9 +32,8 @@ pub mod conventional {
3432
"change" => "Changed",
3533
"docs" => "Documentation",
3634
"perf" => "Performance",
37-
unknown => return Cow::Owned(unknown.into()),
38-
}
39-
.into()
35+
_unknown => return None,
36+
})
4037
}
4138
}
4239

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

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -88,46 +88,53 @@ impl section::Segment {
8888
is_breaking,
8989
removed,
9090
messages,
91-
}) => {
92-
writeln!(
93-
out,
94-
"{} {}{}\n",
95-
heading(section_level),
96-
segment::conventional::as_headline(kind),
97-
if *is_breaking {
98-
format!(" {}", segment::Conventional::BREAKING_TITLE)
99-
} else {
100-
"".into()
101-
},
102-
)?;
91+
}) => match segment::conventional::as_headline(kind) {
92+
Some(headline) => {
93+
writeln!(
94+
out,
95+
"{} {}{}\n",
96+
heading(section_level),
97+
headline,
98+
if *is_breaking {
99+
format!(" {}", segment::Conventional::BREAKING_TITLE)
100+
} else {
101+
"".into()
102+
},
103+
)?;
103104

104-
if !removed.is_empty() {
105-
for id in removed {
106-
writeln!(out, "{}{}/>", segment::Conventional::REMOVED_HTML_PREFIX, id)?;
105+
if !removed.is_empty() {
106+
for id in removed {
107+
writeln!(out, "{}{}/>", segment::Conventional::REMOVED_HTML_PREFIX, id)?;
108+
}
109+
writeln!(out)?;
107110
}
108-
writeln!(out)?;
109-
}
110111

111-
use segment::conventional::Message;
112-
for message in messages {
113-
match message {
114-
Message::Generated { title, id } => writeln!(
115-
out,
116-
" - {}{}/> {}",
117-
segment::Conventional::REMOVED_HTML_PREFIX,
118-
id,
119-
title
120-
)?,
121-
Message::User { markdown } => {
122-
out.write_all(markdown.as_bytes())?;
123-
if !markdown.ends_with('\n') {
124-
writeln!(out)?;
112+
use segment::conventional::Message;
113+
for message in messages {
114+
match message {
115+
Message::Generated { title, id } => writeln!(
116+
out,
117+
" - {}{}/> {}",
118+
segment::Conventional::REMOVED_HTML_PREFIX,
119+
id,
120+
title
121+
)?,
122+
Message::User { markdown } => {
123+
out.write_all(markdown.as_bytes())?;
124+
if !markdown.ends_with('\n') {
125+
writeln!(out)?;
126+
}
125127
}
126128
}
127129
}
130+
writeln!(out)?;
128131
}
129-
writeln!(out)?;
130-
}
132+
None => log::trace!(
133+
"Skipping unknown git-conventional kind {:?} and all {} message(s) in it.",
134+
kind,
135+
messages.len()
136+
),
137+
},
131138
Segment::Details(section::Data::Generated(segment::Details { commits_by_category }))
132139
if !commits_by_category.is_empty() =>
133140
{

git-url/CHANGELOG.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
<csr-read-only-do-not-edit/>
1313

14-
- 4 commits contributed to the release.
14+
- 6 commits contributed to the release over the course of 6 calendar days.
1515
- 0 commits where understood as [conventional](https://www.conventionalcommits.org).
16-
- 1 unique issue was worked on
16+
- 2 unique issues were worked on
1717

1818
### Commit Details
1919

@@ -22,10 +22,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
<details><summary>view details</summary>
2323

2424
* **#198**
25-
- Rebuild all changelogs to assure properly ordered headlines (cfcaa66)
26-
- Sort all commits by time, descending… (7c37a3d)
27-
- greatly reduce changelog size now that the traversal fix is applied (3924c03)
28-
- Fixup remaining changelogs… (0ac488a)
25+
- Rebuild all changelogs to assure properly ordered headlines (4a9a05f)
26+
- Sort all commits by time, descending… (f536bad)
27+
- greatly reduce changelog size now that the traversal fix is applied (a0bc98c)
28+
- Fixup remaining changelogs… (2f75db2)
29+
* **Uncategorized**
30+
- make fmt, but now it picked up some parts that usually don't get altered… (01f7b72)
31+
- Update changelogs just for fun (21541b3)
2932
</details>
3033

3134
## v0.3.3 (2021-08-17)

git-validate/CHANGELOG.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
<csr-read-only-do-not-edit/>
1313

14-
- 10 commits contributed to the release over the course of 6 calendar days.
14+
- 11 commits contributed to the release over the course of 18 calendar days.
1515
- 0 commits where understood as [conventional](https://www.conventionalcommits.org).
16-
- 2 unique issues were worked on
16+
- 3 unique issues were worked on
1717

1818
### Commit Details
1919

@@ -22,17 +22,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
<details><summary>view details</summary>
2323

2424
* **#198**
25-
- Rebuild all changelogs to assure properly ordered headlines (cfcaa66)
26-
- Sort all commits by time, descending… (7c37a3d)
27-
- greatly reduce changelog size now that the traversal fix is applied (3924c03)
28-
- Generate changelogs with details (fd0f3bd)
29-
- Update all changelogs with details (0732699)
30-
- Update changelogs (b30db3b)
25+
- Rebuild all changelogs to assure properly ordered headlines (4a9a05f)
26+
- Sort all commits by time, descending… (f536bad)
27+
- greatly reduce changelog size now that the traversal fix is applied (a0bc98c)
28+
- Generate changelogs with details (e1861ca)
29+
- Update all changelogs with details (58ab2ae)
30+
- Update changelogs (c857d61)
3131
- Avoid adding newlines which make writing unstable (6b5c394)
3232
- Fix section headline level (9d6f263)
3333
- Write first version of changlogs thus far… (719b6bd)
3434
* **#205**
3535
- validate assumption about '(null)' as ref-name (2576168)
36+
* **Uncategorized**
37+
- Update changelogs just for fun (21541b3)
3638
</details>
3739

3840
## v0.5.2 (2021-08-17)

0 commit comments

Comments
 (0)