git_iris/types/
commit.rs

1//! Commit message types and formatting
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5use std::fmt::Write;
6use textwrap;
7
8/// Model for commit message generation results
9#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)]
10pub struct GeneratedMessage {
11    /// Optional emoji for the commit message
12    pub emoji: Option<String>,
13    /// Commit message title/subject line
14    pub title: String,
15    /// Detailed commit message body
16    pub message: String,
17    /// Brief completion status message for the UI (e.g., "Auth refactor ready.")
18    #[serde(default)]
19    pub completion_message: Option<String>,
20}
21
22/// Formats a commit message from a `GeneratedMessage`
23pub fn format_commit_message(response: &GeneratedMessage) -> String {
24    let mut message = String::new();
25
26    if let Some(emoji) = &response.emoji {
27        write!(&mut message, "{emoji} ").expect("write to string should not fail");
28    }
29
30    message.push_str(&response.title);
31    message.push_str("\n\n");
32
33    let wrapped_message = textwrap::wrap(&response.message, 78);
34    for line in wrapped_message {
35        message.push_str(&line);
36        message.push('\n');
37    }
38
39    message
40}