use derive_builder::Builder;
use regex::Regex;
use url::Url;
use crate::{
config::prerelease::PrereleaseConfig, orchestrator::config::CommitModifiers,
};
pub const DEFAULT_BODY: &str = r#"# [{{ version }}]{% if tag_compare_link %}({{ tag_compare_link }}){% else %}({{ link }}){% endif %} - {{ timestamp | date(format="%Y-%m-%d") }}
{% for group, commits in commits | filter(attribute="merge_commit", value=false) | sort(attribute="group") | group_by(attribute="group") %}
### {{ group | striptags | trim }}
{% for commit in commits %}
{% if commit.breaking -%}
{% if commit.scope %}_({{ commit.scope }})_ {% endif -%}[**breaking**]: {{ commit.title }} [_({{ commit.short_id }})_]({{ commit.link }}){% if include_author %} ({{ commit.author_name }}){% endif %}
{% if commit.body -%}
> {{ commit.body }}
{% endif -%}
{% if commit.breaking_description -%}
> {{ commit.breaking_description }}
{% endif -%}
{% else -%}
- {% if commit.scope %}_({{ commit.scope }})_ {% endif %}{{ commit.title }} [_({{ commit.short_id }})_]({{ commit.link }}){% if include_author %} ({{ commit.author_name }}){% endif %}
{% endif -%}
{% endfor %}
{% endfor %}
"#;
#[derive(Debug, Clone, Builder)]
#[builder(setter(into, strip_option), default)]
pub struct AnalyzerConfig {
pub body: String,
pub skip_ci: bool,
pub skip_chore: bool,
pub skip_doc: bool,
pub skip_test: bool,
pub skip_style: bool,
pub skip_refactor: bool,
pub skip_perf: bool,
pub skip_revert: bool,
pub skip_miscellaneous: bool,
pub skip_merge_commits: bool,
pub skip_release_commits: bool,
pub include_author: bool,
pub tag_prefix: Option<String>,
pub release_link_base_url: Option<Url>,
pub compare_link_base_url: Option<Url>,
pub prerelease: Option<PrereleaseConfig>,
pub release_commit_matcher: Option<Regex>,
pub breaking_always_increment_major: bool,
pub features_always_increment_minor: bool,
pub custom_major_increment_regex: Option<String>,
pub custom_minor_increment_regex: Option<String>,
pub commit_modifiers: CommitModifiers,
}
impl Default for AnalyzerConfig {
fn default() -> Self {
Self {
body: DEFAULT_BODY.into(),
skip_ci: false,
skip_chore: false,
skip_doc: false,
skip_test: false,
skip_style: false,
skip_refactor: false,
skip_perf: false,
skip_revert: false,
skip_miscellaneous: false,
skip_merge_commits: true,
skip_release_commits: true,
include_author: false,
tag_prefix: None,
release_link_base_url: None,
compare_link_base_url: None,
prerelease: None,
release_commit_matcher: None,
breaking_always_increment_major: true,
features_always_increment_minor: true,
custom_major_increment_regex: None,
custom_minor_increment_regex: None,
commit_modifiers: CommitModifiers::default(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn loads_defaults() {
let config = AnalyzerConfig::default();
assert!(!config.body.is_empty())
}
}