pub fn default_target(
report: &VersionReport,
current: Version,
) -> Result<Version, String>Expand description
The version release bump raises to when no target is named: the report’s next, the
declared version when nothing would be released — and a refusal, with the report’s
reason, when the contract could not be measured and so no one decided.
use majordomus_cli::release::model::{DecidedBy, VersionReport};
use majordomus_cli::release::version::{default_target, Version};
let report = |next: Option<&str>, decided_by, why: Option<&str>| VersionReport {
declared: "0.11.0".into(), tool: "0.11.0".into(), agree: true,
last_release: Some("0.11.0".into()), bump: "patch".into(),
commits_imply: Some("0.11.1".into()), next: next.map(Into::into), decided_by,
contract_unreadable: why.map(Into::into), changes: Vec::new() };
let current = Version::parse("0.11.0").unwrap();
let fix = report(Some("0.11.1"), DecidedBy::ContractAndCommits, None);
assert_eq!(default_target(&fix, current).unwrap().to_string(), "0.11.1");
let nothing = report(None, DecidedBy::Contract, None);
assert_eq!(default_target(¬hing, current), Ok(current));
let unread = report(None, DecidedBy::Undecided, Some("no release"));
assert_eq!(default_target(&unread, current), Err("no release".into()));