1use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5use std::fmt::Write;
6use textwrap;
7
8#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)]
10pub struct GeneratedMessage {
11 pub emoji: Option<String>,
13 pub title: String,
15 pub message: String,
17 #[serde(default)]
19 pub completion_message: Option<String>,
20}
21
22pub 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}