Skip to content
Open
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
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
3 changes: 3 additions & 0 deletions git-cliff-core/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ Refs: #123
username: None,
pr_title: Some("feat: do something".to_string()),
pr_number: None,
pr_numbers: vec![],
pr_labels: vec![String::from("feature"), String::from("deprecation")],
is_first_time: true,
});
Expand Down Expand Up @@ -845,6 +846,7 @@ Refs: #123
username: None,
pr_title: Some("feat: do something".to_string()),
pr_number: None,
pr_numbers: vec![],
pr_labels: vec![String::from("feature"), String::from("deprecation")],
is_first_time: true,
});
Expand Down Expand Up @@ -1020,6 +1022,7 @@ Refs: #123
username: None,
pr_title: Some("feat: do something".to_string()),
pr_number: None,
pr_numbers: vec![],
pr_labels: Vec::new(),
is_first_time: true,
});
Expand Down
4 changes: 4 additions & 0 deletions git-cliff-core/src/contributor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ pub struct RemoteContributor {
pub pr_title: Option<String>,
/// The pull request that the user created.
pub pr_number: Option<i64>,
/// All pull requests that the user created in this release, sorted in
/// ascending order (lowest PR number first).
#[serde(default)]
pub pr_numbers: Vec<i64>,
/// Labels of the pull request.
pub pr_labels: Vec<String>,
/// Whether if the user contributed for the first time.
Expand Down
2 changes: 2 additions & 0 deletions git-cliff-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub const CONFIG_FILES: &[&str] = &["cliff.toml", ".cliff.toml", ".config/cliff.
pub const DEFAULT_OUTPUT: &str = "CHANGELOG.md";
/// Default ignore file.
pub const IGNORE_FILE: &str = ".cliffignore";
/// Git blame ignore revs file.
pub const BLAME_IGNORE_REVS_FILE: &str = ".git-blame-ignore-revs";

/// Sets a human-readable message on the current progress bar span.
/// This macro only has effect if the `tracing-indicatif` feature is enabled.
Expand Down
Loading
Loading