A changelog parser, written in Rust.
To use this crate as a command line tool, run the following command:
sh
cargo install parse-changelog
To use this crate as a library, add this to your Cargo.toml
:
toml
[dependencies]
parse-changelog = { version = "0.1", default-features = false }
When using this crate as a library, we recommend disabling the default feature due to the default feature enables CLI-related dependencies.
Compiler support: requires rustc 1.45+
Usage:
```console $ parse-changelog --help parse-changelog Parses changelog and returns a release note for the specified version
USAGE:
parse-changelog
OPTIONS:
--version-format
ARGS:
Gets release note for Rust 1.46.0:
console
$ curl -sSf https://raw.githubusercontent.com/rust-lang/rust/master/RELEASES.md > rust-releases.md
$ parse-changelog rust-releases.md 1.46.0
```rust let changelog = "\
Foo
.Bar
.Initial release ";
// Parse changelog. let releases = parse_changelog::parse(changelog).unwrap();
// Get the latest release. asserteq!(releases[0].version, "0.1.2"); asserteq!(releases[0].title, "0.1.2 - 2020-03-01"); assert_eq!(releases[0].notes, "- Bug fixes.");
// Get the specified release.
asserteq!(releases["0.1.0"].title, "0.1.0 - 2020-01-01");
asserteq!(releases["0.1.0"].notes, "Initial release");
asserteq!(releases["0.1.1"].title, "0.1.1 - 2020-02-01");
asserteq!(
releases["0.1.1"].notes,
"- Added Foo
.\n\
- Added Bar
."
);
```
By default, this crate is intended to support most markdown-based changelogs that have the title of each release starts with the version.
The heading for each release must be Atx-style (1-6 #
) or
Setext-style (=
or -
in a line under text), and the heading levels
must match with other releases.
Atx-style headings:
```markdown
```
```markdown
```
Setext-style headings:
```markdown
```
```markdown
```
The title of each release must start with a text or a link text (text with [
and ]
)
that starts with a valid version format. For example:
```markdown
description...
description... ```
You can also include characters before the version as prefix. For example:
```markdown
```
By default only "v", "Version " and "Release " are allowed as prefix and
can be customized using the [Parser::prefix_format
] method.
You can freely include characters after the version (this crate does not parse it). For example:
```markdown
```
The default version format is
MAJOR.MINOR.PATCH(-PRE_RELEASE)?(+BUILD_METADATA)?
, and is
based on Semantic Versioning. (Pre-release version and build
metadata are optional.)
This is parsed using the following regular expression:
text
^\d+\.\d+\.\d+(-[\w\.-]+)?(\+[\w\.-]+)?
To customize the version format, use the [Parser::version_format
] method (library), or use --version-format
option ().
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.