use serde::{Deserialize, Serialize};
use sublime_standard_tools::config::{ConfigResult, Configurable};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(default)]
pub struct GitConfig {
pub merge_commit_template: String,
pub monorepo_merge_commit_template: String,
pub include_breaking_warning: bool,
pub breaking_warning_template: String,
}
impl Default for GitConfig {
fn default() -> Self {
Self {
merge_commit_template: "chore(release): {version}\n\nRelease version {version}\n\n{changelog_summary}".to_string(),
monorepo_merge_commit_template: "chore(release): {package_name}@{version}\n\nRelease {package_name} version {version}\n\n{changelog_summary}".to_string(),
include_breaking_warning: true,
breaking_warning_template: "\n⚠️ BREAKING CHANGES: {breaking_changes_count}\n".to_string(),
}
}
}
impl Configurable for GitConfig {
fn validate(&self) -> ConfigResult<()> {
if self.merge_commit_template.is_empty() {
return Err(sublime_standard_tools::config::ConfigError::ValidationError {
message: "git.merge_commit_template: Merge commit template cannot be empty"
.to_string(),
});
}
if self.monorepo_merge_commit_template.is_empty() {
return Err(sublime_standard_tools::config::ConfigError::ValidationError {
message: "git.monorepo_merge_commit_template: Monorepo merge commit template cannot be empty".to_string(),
});
}
if self.include_breaking_warning && self.breaking_warning_template.is_empty() {
return Err(sublime_standard_tools::config::ConfigError::ValidationError {
message: "git.breaking_warning_template: Breaking warning template cannot be empty when warnings are enabled"
.to_string(),
});
}
Ok(())
}
fn merge_with(&mut self, other: Self) -> ConfigResult<()> {
self.merge_commit_template = other.merge_commit_template;
self.monorepo_merge_commit_template = other.monorepo_merge_commit_template;
self.include_breaking_warning = other.include_breaking_warning;
self.breaking_warning_template = other.breaking_warning_template;
Ok(())
}
}