Struct next_version::VersionUpdater
source · pub struct VersionUpdater { /* private fields */ }Expand description
This struct allows to increment a version by specifying a configuration.
Useful if you don’t like the default increment rules of the crate.
use next_version::VersionUpdater;
use semver::Version;
let updated_version = VersionUpdater::new()
.with_features_always_increment_minor(false)
.with_breaking_always_increment_major(true)
.increment(&Version::new(1, 2, 3), ["feat: commit 1", "fix: commit 2"]);
assert_eq!(Version::new(1, 3, 0), updated_version);Implementations§
source§impl VersionUpdater
impl VersionUpdater
sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new instance with the default rules of the crate.
If you don’t customize the struct further, it is equivalent to
calling crate::NextVersion::next.
use next_version::{NextVersion, VersionUpdater};
use semver::Version;
let version = Version::new(1, 2, 3);
let commits = ["feat: commit 1", "fix: commit 2"];
let updated_version1 = VersionUpdater::new()
.increment(&version, &commits);
let updated_version2 = version.next(&commits);
assert_eq!(updated_version1, updated_version2);sourcepub fn with_features_always_increment_minor(
self,
features_always_increment_minor: bool,
) -> Self
pub fn with_features_always_increment_minor( self, features_always_increment_minor: bool, ) -> Self
Configures automatic minor version increments for feature changes.
- When
trueis passed, a feature will always trigger a minor version update. - When
falseis passed, a feature will trigger:- a patch version update if the major version is 0.
- a minor version update otherwise.
Default: false.
use semver::Version;
use next_version::VersionUpdater;
let commits = ["feat: make coffee"];
let version = Version::new(0, 2, 3);
assert_eq!(
VersionUpdater::new()
.with_features_always_increment_minor(true)
.increment(&version, &commits),
Version::new(0, 3, 0)
);
assert_eq!(
VersionUpdater::new()
.increment(&version, &commits),
Version::new(0, 2, 4)
);sourcepub fn with_breaking_always_increment_major(
self,
breaking_always_increment_major: bool,
) -> Self
pub fn with_breaking_always_increment_major( self, breaking_always_increment_major: bool, ) -> Self
Configures 0 -> 1 major version increments for breaking changes.
- When
trueis passed, a breaking change commit will always trigger a major version update (including the transition from version 0 to 1) - When
falseis passed, a breaking change commit will trigger:- a minor version update if the major version is 0.
- a major version update otherwise.
Default: false.
use semver::Version;
use next_version::VersionUpdater;
let commits = ["feat!: incompatible change"];
let version = Version::new(0, 2, 3);
assert_eq!(
VersionUpdater::new()
.with_breaking_always_increment_major(true)
.increment(&version, &commits),
Version::new(1, 0, 0)
);
assert_eq!(
VersionUpdater::new()
.increment(&version, &commits),
Version::new(0, 3, 0)
);sourcepub fn with_custom_major_increment_regex(
self,
custom_major_increment_regex: &str,
) -> Result<Self, Error>
pub fn with_custom_major_increment_regex( self, custom_major_increment_regex: &str, ) -> Result<Self, Error>
Configure a custom regex pattern for major version increments. This will check only the type of the commit against the given pattern.
Default: None.
§Note
commit type according to the spec is only [a-zA-Z]+
§Example
use semver::Version;
use next_version::VersionUpdater;
let commits = ["abc: incompatible change"];
let version = Version::new(1, 2, 3);
assert_eq!(
VersionUpdater::new()
.with_custom_major_increment_regex("abc")
.expect("invalid regex")
.increment(&version, &commits),
Version::new(2, 0, 0)
);
assert_eq!(
VersionUpdater::new()
.increment(&version, &commits),
Version::new(1, 2, 4)
);sourcepub fn with_custom_minor_increment_regex(
self,
custom_minor_increment_regex: &str,
) -> Result<Self, Error>
pub fn with_custom_minor_increment_regex( self, custom_minor_increment_regex: &str, ) -> Result<Self, Error>
Configures a custom regex pattern for minor version increments. This will check only the type of the commit against the given pattern.
Default: None.
§Note
commit type according to the spec is only [a-zA-Z]+
§Example
use semver::Version;
use next_version::VersionUpdater;
let commits = ["bbb: make coffee"];
let version = Version::new(0, 2, 3);
assert_eq!(
VersionUpdater::new()
.with_custom_minor_increment_regex("abc|bbb")
.expect("invalid regex")
.increment(&version, &commits),
Version::new(0, 3, 0)
);
assert_eq!(
VersionUpdater::new()
.increment(&version, &commits),
Version::new(0, 2, 4)
);