conventional_commits_next_semver/
lib.rs1use crate::utils::{increment_major, increment_minor, increment_patch};
2use conventional_commits_parser::Commit;
3
4use semver::Version;
5
6pub mod error;
7mod git;
8pub mod types;
9pub mod utils;
10
11pub use error::Error;
13pub use git::{git_commits_in_range, latest_semver_compatible_git_tag};
14pub use types::SemverCompatibleGitTag;
15
16pub fn next_version<'a>(
28 current_version: Version,
29 commits: &'a [&'a Commit<'a>],
30) -> Result<Version, Error<'a>> {
31 let is_breaking_change = commits.iter().any(|c| c.is_breaking_change);
33 if is_breaking_change {
34 return Ok(increment_major(current_version));
35 }
36
37 let is_new_feature_available = commits.iter().any(|c| c.ty == "feat");
39 if is_new_feature_available {
40 return Ok(increment_minor(current_version));
41 }
42
43 let is_new_fix_available = commits.iter().any(|c| c.ty == "fix");
45 if is_new_fix_available {
46 return Ok(increment_patch(current_version));
47 }
48
49 Err(Error::SameVersion(current_version))
50}