Skip to content
Open
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
59 changes: 57 additions & 2 deletions git-cliff-core/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<'a> Changelog<'a> {
/// Builds a changelog from releases and config.
fn build(releases: Vec<Release<'a>>, config: Config) -> Result<Self> {
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)?),
Expand All @@ -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.
Expand Down Expand Up @@ -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<Template> {
let template = Template::new("body", config.changelog.body.clone(), trim)?;
let deprecated_vars = [
Expand Down
Loading