diff --git a/git-cliff-core/src/changelog.rs b/git-cliff-core/src/changelog.rs index 016243a23f..0632f53bfa 100644 --- a/git-cliff-core/src/changelog.rs +++ b/git-cliff-core/src/changelog.rs @@ -52,7 +52,7 @@ impl<'a> Changelog<'a> { /// Builds a changelog from releases and config. fn build(releases: Vec>, config: Config) -> Result { let trim = config.changelog.trim; - Ok(Self { + let changelog = Self { releases, header_template: match &config.changelog.header { Some(header) => Some(Template::new("header", header.clone(), trim)?), @@ -65,7 +65,9 @@ impl<'a> Changelog<'a> { }, config, additional_context: HashMap::new(), - }) + }; + warn_if_remote_template_variables_without_feature(&changelog); + Ok(changelog) } /// Constructs an instance from a serialized context object. @@ -658,6 +660,59 @@ impl<'a> Changelog<'a> { } } +/// Emits a warning when a template references remote-specific variables for a +/// provider whose Cargo feature is not compiled in. +fn warn_if_remote_template_variables_without_feature(changelog: &Changelog<'_>) { + // `changelog` is only referenced inside #[cfg(not(feature = "..."))] blocks; + // when all remote features are enabled every block is compiled out. + let _ = changelog; + macro_rules! warn_missing_feature { + ($feature:literal, $vars:expr, $example:literal) => { + #[cfg(not(feature = $feature))] + if [ + Some(&changelog.body_template), + changelog.header_template.as_ref(), + changelog.footer_template.as_ref(), + ] + .into_iter() + .flatten() + .any(|t| t.contains_variable($vars)) + { + tracing::warn!( + "Template uses `{}` variables (e.g. `{}`) but the `{}` feature is not \ + enabled. Rebuild with `--features {}`.", + $feature, + $example, + $feature, + $feature, + ); + } + }; + } + + warn_missing_feature!( + "github", + &["github", "commit.github"], + "github.contributors" + ); + warn_missing_feature!( + "gitlab", + &["gitlab", "commit.gitlab"], + "gitlab.contributors" + ); + warn_missing_feature!("gitea", &["gitea", "commit.gitea"], "gitea.contributors"); + warn_missing_feature!( + "bitbucket", + &["bitbucket", "commit.bitbucket"], + "bitbucket.contributors" + ); + warn_missing_feature!( + "azure_devops", + &["azure_devops", "commit.azure_devops"], + "azure_devops.contributors" + ); +} + fn get_body_template(config: &Config, trim: bool) -> Result