Skip to content

Commit

Permalink
fix(KAN-8): fixed commit message serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ShyamSundhar1411 committed Dec 2, 2023
1 parent 34257c3 commit 4eb29dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "git-automater"
version = "1.0.3"
version = "1.0.4"
edition = "2021"
repository = "https://github.com/ShyamSundhar1411/git-automater/"
keywords = ["git","command-line-utility","version-control","license-generator"]
Expand Down
19 changes: 16 additions & 3 deletions src/commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@ pub struct Commit{
commit_type: String,
body: Option<String>,
footer: Option<String>,
file_name: Option<String>
}
impl Commit{
pub fn new(commit_type: &str, description: &str,body: Option<&str>, footer: Option<&str>) -> Self{
pub fn new(commit_type: &str, description: &str,body: Option<&str>, footer: Option<&str>, file_name: Option<&str>) -> Self{
Commit{
commit_type: commit_type.to_string(),
description: description.to_string(),
body: body.map(String::from),
footer: footer.map(String::from),
file_name: file_name.map(String::from),
}
}
pub fn to_string(&self) -> String{
let mut commit_message = String::new();
commit_message.push_str(&format!("{}: {}", self.commit_type, self.description));

commit_message.push_str(&format!("{}",self.commit_type));
if let Some(ref file_name) = &self.file_name {
if !file_name.is_empty() {
commit_message.push_str("(");
commit_message.push_str(file_name);
commit_message.push_str(")");
}
};
commit_message.push_str(&format!(": {}",self.description));
if let Some(ref body) = self.body {
commit_message.push_str("\n\n");
commit_message.push_str(body);
Expand Down Expand Up @@ -81,6 +90,9 @@ pub fn commit_function(){
.items(&formatted_options)
.interact()
.expect("Failed to read selection");

// Prompt the user for a short description of the commit
let file_name: Option<String> = Some(Input::with_theme(&ColorfulTheme::default()).with_prompt("Enter file name or class name (default will be blank)").allow_empty(true).interact_text().unwrap());
let description: String = Input::with_theme(&ColorfulTheme::default()).with_prompt("Enter a short description").interact_text().unwrap();
let commit_type = conventional_commit_types[type_select];
let body: Option<String> = Some(Input::with_theme(&ColorfulTheme::default()).with_prompt("Enter brief description").allow_empty(true).interact_text().unwrap_or_default());
Expand All @@ -90,6 +102,7 @@ pub fn commit_function(){
&description,
body.as_deref(),
footer.as_deref(),
file_name.as_deref(),
);
let commit_message = commit.to_string();
let output = Command::new("git").arg("commit").arg("-m").arg(commit_message).output().expect("Failed to add commit message");
Expand Down

0 comments on commit 4eb29dd

Please sign in to comment.