Skip to content

Commit

Permalink
✨ Implement line wrapping for commit messages
Browse files Browse the repository at this point in the history
Add textwrap dependency and use it to wrap commit message body

Modify format_commit_message function to wrap the message body at 78
characters, improving readability and adhering to Git best practices.
This change ensures that long commit messages are properly formatted
without manual intervention.
  • Loading branch information
hyperb1iss committed Aug 11, 2024
1 parent 54c2951 commit dc3738b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::token_optimizer::TokenOptimizer;
use serde::{Deserialize, Serialize};
use std::fmt;

use crate::token_optimizer::TokenOptimizer;
use textwrap::wrap;

#[derive(Serialize, Debug, Clone)]
pub struct CommitContext {
Expand Down Expand Up @@ -112,11 +112,19 @@ impl CommitContext {

pub fn format_commit_message(response: &GeneratedMessage) -> String {
let mut message = String::new();

if let Some(emoji) = &response.emoji {
message.push_str(&format!("{} ", emoji));
}

message.push_str(&response.title);
message.push_str("\n\n");
message.push_str(&response.message);

let wrapped_message = wrap(&response.message, 78);
for line in wrapped_message {
message.push_str(&line);
message.push_str("\n");
}

message
}

0 comments on commit dc3738b

Please sign in to comment.