From e74080cec4283a45f0f81b1b656af466ae4bd693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Thu, 22 Aug 2024 09:11:39 +0300 Subject: [PATCH] fix(changelog): allow using `--bumped-version` without conventional commits (#806) --- git-cliff-core/src/config.rs | 27 +++++++++++++++++++++++++++ git-cliff-core/src/release.rs | 14 +------------- git-cliff/src/lib.rs | 2 ++ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/git-cliff-core/src/config.rs b/git-cliff-core/src/config.rs index 4c9d423..5949d33 100644 --- a/git-cliff-core/src/config.rs +++ b/git-cliff-core/src/config.rs @@ -14,6 +14,9 @@ use std::fs; use std::path::Path; use std::path::PathBuf; +/// Default initial tag. +const DEFAULT_INITIAL_TAG: &str = "0.1.0"; + /// Manifest file information and regex for matching contents. #[derive(Debug)] struct ManifestInfo { @@ -246,6 +249,30 @@ pub struct Bump { pub bump_type: Option, } +impl Bump { + /// Returns the initial tag. + /// + /// This function also logs the returned value. + pub fn get_initial_tag(&self) -> String { + match self.initial_tag.clone() { + Some(tag) => { + warn!( + "No releases found, using initial tag '{tag}' as the next \ + version." + ); + tag + } + None => { + warn!( + "No releases found, using {DEFAULT_INITIAL_TAG} as the next \ + version." + ); + DEFAULT_INITIAL_TAG.into() + } + } + } +} + /// Parser for grouping commits. #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct CommitParser { diff --git a/git-cliff-core/src/release.rs b/git-cliff-core/src/release.rs index 2e681bf..204cdf4 100644 --- a/git-cliff-core/src/release.rs +++ b/git-cliff-core/src/release.rs @@ -154,19 +154,7 @@ impl<'a> Release<'a> { Ok(next_version) } } - None => match config.initial_tag.clone() { - Some(tag) => { - warn!( - "No releases found, using initial tag '{tag}' as the next \ - version." - ); - Ok(tag) - } - None => { - warn!("No releases found, using 0.1.0 as the next version."); - Ok(String::from("0.1.0")) - } - }, + None => Ok(config.get_initial_tag()), } } } diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index ed88cce..878a278 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -583,6 +583,8 @@ pub fn run(mut args: Opt) -> Result<()> { { warn!("There is nothing to bump."); last_version + } else if changelog.releases.is_empty() { + config.bump.get_initial_tag() } else { return Ok(()); };