use crate::domain::{CommitMessage, CommitType, DomainError};
#[derive(Debug, Clone)]
pub struct StructuredInput {
pub commit_type: CommitType,
pub scope: Option<String>,
pub description: String,
pub body: Option<String>,
pub breaking_change: Option<String>,
pub refs: Option<String>,
}
impl TryFrom<StructuredInput> for CommitMessage {
type Error = DomainError;
fn try_from(s: StructuredInput) -> Result<Self, DomainError> {
let footers = match s.refs {
Some(refs) => vec![("Refs".to_string(), refs)],
None => vec![],
};
CommitMessage::new(
s.commit_type,
s.scope,
s.description,
s.body,
s.breaking_change,
footers,
)
}
}
pub trait InputSource {
type Output;
type Error: std::fmt::Display;
fn collect(&self) -> Result<Self::Output, Self::Error>;
}
pub trait CommitMessageSource {
type Error: std::fmt::Display;
fn resolve(&self) -> Result<CommitMessage, Self::Error>;
}