Skip to content

Commit

Permalink
fix: 🐛 merge a non-exist version may delete the pre-release log
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Adoo committed Jan 8, 2024
1 parent 26130d3 commit 8c01cad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he
### Fixed

- Return error when the changelog content is empty. (#1 @M-Adoo)
- Fix merge a non-exist version may delete the pre-release version. (#1 @M-Adoo)

## 0.1.1-alpha.1 - 2024-01-04

Expand Down
22 changes: 22 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ pub fn merge_pre_release_changelogs(
}
}

if version_idx == -1 {
return Err("No version heading found".into());
}

let mut content = vec![];

for (idx, node) in nodes.iter().enumerate() {
Expand Down Expand Up @@ -241,3 +245,21 @@ fn merge() {
new_changelog,
)
}

#[test]
fn fix_merge_wrong_version() {
let changelog = "# Changelog
## Unreleased
The version not released yet.
## 0.1.1-alpha.1 - 2024-01-02
But a pre-release version is released.
";

let version = Version::parse("0.1.1").unwrap();
let new_changelog = merge_pre_release_changelogs(&version, changelog);
assert!(new_changelog.is_err())
}

0 comments on commit 8c01cad

Please sign in to comment.