Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(changelog): allow using --bumped-version without conventional commits #806

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions git-cliff-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -246,6 +249,30 @@ pub struct Bump {
pub bump_type: Option<BumpType>,
}

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 {
Expand Down
14 changes: 1 addition & 13 deletions git-cliff-core/src/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
};
Expand Down
Loading