Struct CalculatorConfig

Source
pub struct CalculatorConfig {
    pub force_first_version: bool,
    /* private fields */
}
Expand description

Captures the user configuration set for the bump and version number calculation

The configuration is set following the builder pattern and final build command creates a Calculator struct.

Fields§

§force_first_version: bool

Optional: Force the first version to be calculated as 1.0.0

Implementations§

Source§

impl CalculatorConfig

Source

pub fn new() -> CalculatorConfig

Initialise a new calculator config by providing the version prefix.

The version prefix identifies the start of the version string in the tag.

Source

pub fn set_prefix(self, version_prefix: &str) -> Self

Set the version prefix.

The version prefix identifies the start of the version string in the tag.

§Example

Where you have a version tag v0.7.9 the configuration should be set as follows:

    let calculator = CalculatorConfig::new()
        .set_prefix("v")
        .build()?;

    calculator.report();
Source

pub fn set_subdir(self, subdir: Option<&str>) -> Self

Set the optional subdir for commit analysis.

The subdir identifies a string by which the commits will be filtered. The objective of the filtering is to limit the calculation to commits related to one crate within a worlspace.

§Example

Where you have a crate called crate2 in a workspace and wish to calculate the version for that crate only.

Note:

A version prefix should be used to identify the relevent crate version tag.

    let calculator = CalculatorConfig::new()
        .set_prefix("crate2-v")
        .set_subdir(Some("crate2"))
        .build()?;

    calculator.report();
Source

pub fn set_package(self, subdir: Option<&str>) -> Self

Set the optional package for workspace subset.

The package identifies a subset of a workspace to consider when calculating the next version.

§Example

Where you have a crate called crate2 in a workspace and wish to calculate the version for that crate only.

Note:

A version prefix should be used to identify the relevent crate version tag.

    let calculator = CalculatorConfig::new()
        .set_prefix("crate2-v")
        .set_package(Some("crate2"))
        .build()?;

    calculator.report();
Source

pub fn set_bump_report(self, bump_report: bool) -> Self

Set the flag indicating if the bump should be reported by the Calculator::report method.

  • true indicates that the value should be reported
  • false inidcates that the value should not be reported
Source

pub fn set_version_report(self, report_number: bool) -> Self

Set the flag indicating if the calculated version number should be reported by the Calculator::report method.

  • true indicates that the value should be reported
  • false inidcates that the value should not be reported
Source

pub fn set_force_bump(self, force_level: ForceBump) -> Self

Force the bump result ignoring the bump that would be indicated by an analysis of conventional commits.

The forced bump result will be reported and the next vesion will be calculated based on the forced bump level.

§Example

Publish the first production release.

    let calculator = CalculatorConfig::new()
        .set_prefix("v")
        .set_force_bump(ForceBump::First)
        .build()?;

    calculator.report();

Produces the output:

v1.0.0
Source

pub fn add_required_files(self, files: Vec<OsString>) -> Self

Add a list of files that should be updated if the calculated level of the conventional commits analysed meets or exceeds the enforcement level set by CalculatorConfig::set_required_enforcement.

§Examples
§Using feature (default enforcement level)

Require that the README.md and CHANGELOG.md are updated for the calculation to report successfully if the calculated bump is feature or higher.

    let required_files = vec![
        OsString::from("README.md"),
        OsString::from("CHANGELOG.md"),
        ];

    let calculator = CalculatorConfig::new()
        .set_prefix("v")
        .add_required_files(required_files)
        .build()?;

    calculator.report();

The bump minor confirms that the checked files have been updated by the convential commits submitted as part of proposed release.

minor

In the event that one or more of the files was not found but the highest commit reached the feature threshold the response would be none.

none
§Setting breaking as the enforcement level

Require that the README.md and CHANGELOG.md are updated for the calculation to report successfully if the calculated bump is breaking or higher.

See

// Current version is 1.2.0
    let required_files = vec![
        OsString::from("README.md"),
        OsString::from("CHANGELOG.md"),
        ];

    let calculator = CalculatorConfig::new()
        .set_prefix("v")
        .add_required_files(required_files)
        .set_required_enforcement(Hierarchy::Breaking)
        .build()?;

    calculator.report();

The bump minor indicates that the highest conventional commit in the hierachy is a feat commit. The commits may or may not includes changes to the required files.

minor

The bump major confirms that the checked files have been updated by the convential commits submitted as part of proposed release.

major

In the event that one or more of the files was not found but the highest commit reached the breaking threshold the response would be none.

none

Files that may be listed would include README.md and CHANGELOG.md.

Source

pub fn set_required_enforcement(self, enforce: Hierarchy) -> Self

Sets the enforcement for the files submitted in CalculatorConfig::add_required_files according to the Hierarchy enum.

§Example

See the second example in CalculatorConfig::add_required_files for the use of set_required_enforcement

Source

pub fn set_reporting_threshold(self, threshold: Hierarchy) -> Self

Set a threshold that must be met before the calculated bump is reported.

The threshold is set based on the Hierarchy enumm.

§Example

Set a threshold of Hierarchy::Feature for reporting of the change bump.

    let calculator = CalculatorConfig::new()
        .set_prefix("v")
        .set_reporting_threshold(Hierarchy::Feature)
        .build()?;

    calculator.report();

The bump minor indicates that the highest conventional commit in the hierachy is a feat commit.

minor

If the threshold is not met bump is none

none
Source

pub fn set_first_version(self) -> Self

Set the flag to force the first version to be calculated as 1.0.0 to true. This is useful in combination with a pre-release to create a pre-release for the for the first production release.

Source

pub fn build(self) -> Result<Calculator, Error>

Executes the calculator with the CalculatorConfig returning a completed Calculator or an Error.

Trait Implementations§

Source§

impl Clone for CalculatorConfig

Source§

fn clone(&self) -> CalculatorConfig

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CalculatorConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CalculatorConfig

Source§

fn default() -> CalculatorConfig

Returns the “default value” for a type. Read more
Source§

impl PartialEq for CalculatorConfig

Source§

fn eq(&self, other: &CalculatorConfig) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for CalculatorConfig

Source§

impl StructuralPartialEq for CalculatorConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T