diff --git a/src/parser/conventional.rs b/src/parser/conventional.rs new file mode 100644 index 0000000..526c626 --- /dev/null +++ b/src/parser/conventional.rs @@ -0,0 +1,36 @@ +use serde::Serialize; + +#[derive(Debug, Clone, Default)] +pub struct ConventionalMessage { + pub r#type: String, + pub scope: Option, + pub description: String, + pub body: Option, + pub breaking: bool, + pub breaking_description: Option, + pub footer: Option, +} + +impl ConventionalMessage { + pub fn header(&self) -> String { + let scope_part = self.scope.as_ref() + .map(|s| format!("({})", s)) + .unwrap_or_default(); + + let breaking_marker = if self.breaking { "!" } else { "" }; + + let description = if self.description.trim().is_empty() { + "no description".to_string() + } else { + self.description.clone() + }; + + format!( + "{}{}{}: {}", + self.r#type, + scope_part, + breaking_marker, + description + ) + } +}