Skip to content

Commit

Permalink
export legacy contents during export
Browse files Browse the repository at this point in the history
  • Loading branch information
MalteHerrmann committed Jun 22, 2024
1 parent 3adbc83 commit 1a18e99
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct Changelog {
pub path: PathBuf,
pub fixed: Vec<String>,
comments: Vec<String>,
legacy_contents: Vec<String>,
pub releases: Vec<release::Release>,
pub problems: Vec<String>,
}
Expand Down Expand Up @@ -47,6 +48,10 @@ impl Changelog {
}
}

self.legacy_contents
.iter()
.for_each(|l| exported_string.push_str(format!("{}\n", l).as_str()));

exported_string
}
}
Expand Down Expand Up @@ -76,6 +81,7 @@ pub fn parse_changelog(config: Config, file_path: &Path) -> Result<Changelog, Ch

let mut comments: Vec<String> = Vec::new();
let mut fixed: Vec<String> = Vec::new();
let mut legacy_contents: Vec<String> = Vec::new();
let mut releases: Vec<release::Release> = Vec::new();
let mut problems: Vec<String> = Vec::new();

Expand All @@ -92,9 +98,13 @@ pub fn parse_changelog(config: Config, file_path: &Path) -> Result<Changelog, Ch
let exit_comment_regex = Regex::new("-->")?;

for line in contents.lines() {
if is_legacy {
legacy_contents.push(line.to_string());
continue;
}

let trimmed_line = line.trim();

// TODO: improve this?
if enter_comment_regex.is_match(trimmed_line) && !exit_comment_regex.is_match(trimmed_line)
{
is_comment = true;
Expand Down Expand Up @@ -133,7 +143,6 @@ pub fn parse_changelog(config: Config, file_path: &Path) -> Result<Changelog, Ch
if current_release
.is_legacy(&config)
.expect("failed to check legacy")
&& !is_legacy
{
is_legacy = true;
}
Expand Down Expand Up @@ -234,6 +243,7 @@ pub fn parse_changelog(config: Config, file_path: &Path) -> Result<Changelog, Ch
releases,
comments,
problems,
legacy_contents,
})
}

Expand Down Expand Up @@ -263,6 +273,7 @@ mod changelog_tests {
fixed: Vec::new(),
releases: Vec::new(),
comments: Vec::new(),
legacy_contents: Vec::new(),
problems: Vec::new(),
};
let e = entry::parse(&cfg, example).expect("failed to parse entry");
Expand Down
4 changes: 4 additions & 0 deletions tests/testdata/changelog_fixed.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ Some comments at head of file...
- (vesting) [#1862](https://github.com/evmos/evmos/pull/1862) Add Authorization Grants to the Vesting extension.
- (app) [#555](https://github.com/evmos/evmos/pull/555) `v4.0.0` upgrade logic.

## [v2.0.0](https://github.com/evmos/evmos/releases/tag/v2.0.0) - 2021-10-31
### State Machine Breaking

- legacy entries do not have to be fully correct
4 changes: 4 additions & 0 deletions tests/testdata/changelog_to_be_fixed.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ Some comments at head of file...
- (vesting) [#1862](https://github.com/evmos/evmos/pull/1862) Add Authorization Grants to the Vesting extension.
- (app) [#555](https://github.com/evmos/evmos/pull/555) `v4.0.0` upgrade logic.

## [v2.0.0](https://github.com/evmos/evmos/releases/tag/v2.0.0) - 2021-10-31
### State Machine Breaking

- legacy entries do not have to be fully correct

0 comments on commit 1a18e99

Please sign in to comment.