Skip to content

Commit 2f43a54

Browse files
committed
Parse more user generated section content, adapt existing changelogs to work correctly (#198)
Which means we can already deal with what's there and now work on amending information parsed from the commit history, neat.
1 parent 2a57b75 commit 2f43a54

File tree

7 files changed

+39
-23
lines changed

7 files changed

+39
-23
lines changed

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

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@ impl ChangeLog {
6969

7070
impl Section {
7171
fn from_headline_and_body(Headline { level, version, date }: Headline, body: String) -> Self {
72-
let mut events = pulldown_cmark::Parser::new(&body).into_offset_iter();
72+
let mut events = pulldown_cmark::Parser::new_ext(&body, pulldown_cmark::Options::all()).into_offset_iter();
7373
let mut unknown = String::new();
7474
let mut thanks_clippy_count = 0;
7575
let mut segments = Vec::new();
7676

7777
// let mut user_authored = String::new();
7878
let mut unknown_range = None;
7979
while let Some((e, range)) = events.next() {
80+
// dbg!(&e, &range);
8081
match e {
8182
Event::Html(text) if text.starts_with(Section::UNKNOWN_TAG_START) => {
8283
consume_unknown_range(&mut segments, unknown_range.take(), &body);
@@ -96,11 +97,22 @@ impl Section {
9697
Some((Event::Text(title), _range)) if title.starts_with(Section::THANKS_CLIPPY_TITLE) => {
9798
State::ParseClippy
9899
}
99-
_ => State::ConsiderUserAuthored,
100+
Some((_event, next_range)) => {
101+
update_unknown_range(&mut unknown_range, range);
102+
update_unknown_range(&mut unknown_range, next_range);
103+
State::ConsiderUserAuthored
104+
}
105+
None => State::ConsiderUserAuthored,
100106
};
107+
101108
events
102109
.by_ref()
103-
.take_while(|(e, _range)| !matches!(e, Event::End(Tag::Heading(_))))
110+
.take_while(|(e, range)| {
111+
if matches!(state, State::ConsiderUserAuthored) {
112+
update_unknown_range(&mut unknown_range, range.clone());
113+
}
114+
!matches!(e, Event::End(Tag::Heading(_)))
115+
})
104116
.count();
105117
match state {
106118
State::ParseClippy => {
@@ -115,14 +127,7 @@ impl Section {
115127
State::ConsiderUserAuthored => {}
116128
}
117129
}
118-
_unknown_event => match &mut unknown_range {
119-
Some(range_thus_far) => {
120-
if range.end > range_thus_far.end {
121-
range_thus_far.end = range.end;
122-
}
123-
}
124-
None => unknown_range = range.into(),
125-
},
130+
_unknown_event => update_unknown_range(&mut unknown_range, range),
126131
};
127132
}
128133
consume_unknown_range(&mut segments, unknown_range.take(), &body);
@@ -140,6 +145,17 @@ impl Section {
140145
}
141146
}
142147

148+
fn update_unknown_range(target: &mut Option<Range<usize>>, source: Range<usize>) {
149+
match target {
150+
Some(range_thus_far) => {
151+
if source.end > range_thus_far.end {
152+
range_thus_far.end = source.end;
153+
}
154+
}
155+
None => *target = source.into(),
156+
}
157+
}
158+
143159
fn consume_unknown_range(out: &mut Vec<section::Segment>, range: Option<Range<usize>>, markdown: &str) {
144160
if let Some(range) = range {
145161
out.push(section::Segment::Unknown {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn unknown_link_and_headling() {
4444
heading_level: 4,
4545
thanks_clippy_count: 0,
4646
segments: vec![section::Segment::Unknown {
47-
text: "Hello [there][194] period.\n".into()
47+
text: "##### Special\n\nHello [there][194] period.\n".into()
4848
}],
4949
unknown: String::new(),
5050
},]

git-odb/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
### 0.21.1 (2021-09-08)
1+
### v0.21.1 (2021-09-08)
22

33
* added `linked::Store::refresh()`
44

5-
### 0.21.0 (2021-08-27)
5+
### v0.21.0 (2021-08-27)
66

77
- **renames**
88
- `compound::Store::find()` -> `compound::Store::try_find()`

git-pack/CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
### 0.11.0 (2021-09-08)
1+
### v0.11.0 (2021-09-08)
22

33
- manual bump for safety as its dependencies have breaking changes
44

5-
### 0.10.0 (2021-09-07)
5+
### v0.10.0 (2021-09-07)
66

77
- **renames**
88
- `data::Object::into_commit_iter()` -> `data::Object::try_into_commit_iter()`
99
- `data::Object::into_tree_iter()` -> `data::Object::try_into_tree_iter()`
1010
- `data::Object::into_tag_iter()` -> `data::Object::try_into_tag_iter()`
1111

12-
### 0.9.0 (2021-08-27)
12+
### v0.9.0 (2021-08-27)
1313

1414
- **renames / moves / visibility**
1515
- `find::Find` and `find::FindExt` only in `Find` and `FindExt` (not in `find` anymore)

git-packetline/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### 0.10.0 (2021-08-27)
1+
### v0.10.0 (2021-08-27)
22

33
#### Breaking
44

git-protocol/CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
### 0.10.1 (2021-08-29)
1+
### v0.10.1 (2021-08-29)
22

33
- instruct docs.rs which features to use for more useful documentation
44

5-
### 0.10.0 (2021-08-27)
5+
### v0.10.0 (2021-08-27)
66

77
- Various minor updates of pre-release dependencies
88

9-
### 0.9.0 (2021-08-17)
9+
### v0.9.0 (2021-08-17)
1010

1111
#### BREAKING
1212

git-transport/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
### 0.11.1 (2021-08-29)
1+
### v0.11.1 (2021-08-29)
22

33
- instruct docs.rs which features to use for more useful documentation
44

5-
### 0.11.0 (2021-08-27)
5+
### v0.11.0 (2021-08-27)
66

77
- upgrade to the latest git-packetline release

0 commit comments

Comments
 (0)