Skip to main content

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`
23#[must_use]
24pub fn format_commit_message(response: &GeneratedMessage) -> String {
25    let mut message = String::new();
26
27    if let Some(emoji) = &response.emoji {
28        write!(&mut message, "{emoji} ").expect("write to string should not fail");
29    }
30
31    message.push_str(&response.title);
32    message.push_str("\n\n");
33
34    let wrapped_message = textwrap::wrap(&response.message, 78);
35    for line in wrapped_message {
36        message.push_str(&line);
37        message.push('\n');
38    }
39
40    message
41}