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
22#[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}