diff --git a/src/analyzer.rs b/src/analyzer.rs index 58d45ce..1c0cb0d 100644 --- a/src/analyzer.rs +++ b/src/analyzer.rs @@ -1,8 +1,3 @@ -use anyhow::{anyhow, Context, Result}; -use colored::Colorize; -use std::collections::HashMap; -use std::path::Path; - pub enum CommitType { Feat, Fix, @@ -41,8 +36,8 @@ pub struct AnalysisResult { pub reasons: Vec, } -pub fn analyze_changes(staged: &crate::git::StagedChanges) -> AnalysisResult { - let files: Vec<&crate::git::ChangedFile> = staged.files.iter().collect(); +pub fn analyze_changes(staged: &super::git::StagedChanges) -> AnalysisResult { + let files: Vec<&super::git::ChangedFile> = staged.files.iter().collect(); if files.is_empty() { return AnalysisResult { @@ -54,10 +49,10 @@ pub fn analyze_changes(staged: &crate::git::StagedChanges) -> AnalysisResult { }; } - let mut type_scores: HashMap)> = HashMap::new(); + let mut type_scores: std::collections::HashMap)> = std::collections::HashMap::new(); for file in &files { - let path = Path::new(&file.path); + let path = std::path::Path::new(&file.path); let ext = path.extension().and_then(|e| e.to_str()).unwrap_or(""); let file_name = path.file_name().and_then(|n| n.to_str()).unwrap_or(""); let parent = path.parent().and_then(|p| p.file_name()).and_then(|n| n.to_str()).unwrap_or(""); @@ -93,10 +88,10 @@ pub fn analyze_changes(staged: &crate::git::StagedChanges) -> AnalysisResult { fn classify_file( path: &str, - status: &crate::git::FileStatus, + status: &super::git::FileStatus, ext: &str, file_name: &str, - parent: &str, + _parent: &str, ) -> (CommitType, String) { if ext == "md" || path.to_lowercase().contains("readme") || path.to_lowercase().contains("changelog") { return (CommitType::Docs, format!("Documentation file: {}", path)); @@ -115,16 +110,16 @@ fn classify_file( } match status { - crate::git::FileStatus::Added if ext == "rs" => { + super::git::FileStatus::Added if ext == "rs" => { (CommitType::Feat, format!("New feature file: {}", path)) } - crate::git::FileStatus::Modified if ext == "rs" => { + super::git::FileStatus::Modified if ext == "rs" => { (CommitType::Fix, format!("Modified source file: {}", path)) } - crate::git::FileStatus::Deleted => { + super::git::FileStatus::Deleted => { (CommitType::Fix, format!("Deleted file: {}", path)) } - crate::git::FileStatus::Renamed => { + super::git::FileStatus::Renamed => { (CommitType::Refactor, format!("Renamed file: {}", path)) } _ => (CommitType::Chore, format!("Other change: {}", path)), @@ -132,7 +127,7 @@ fn classify_file( } pub fn extract_scope(path: &str) -> Option { - let path = Path::new(path); + let path = std::path::Path::new(path); let components: Vec = path .components() .filter_map(|c| c.as_os_str().to_str().map(|s| s.to_string())) @@ -150,7 +145,7 @@ pub fn extract_scope(path: &str) -> Option { } } -pub fn format_change_summary(changes: HashMap>) -> String { +pub fn format_change_summary(changes: std::collections::HashMap>) -> String { let mut summary = String::new(); let priority = vec!["added", "modified", "deleted", "renamed", "copied", "untacked"]; @@ -196,7 +191,7 @@ pub fn get_all_commit_types() -> Vec { ] } -fn generate_description(files: &[&crate::git::ChangedFile]) -> String { +fn generate_description(files: &[&super::git::ChangedFile]) -> String { if files.is_empty() { return String::from("empty commit"); } @@ -204,11 +199,11 @@ fn generate_description(files: &[&crate::git::ChangedFile]) -> String { if files.len() == 1 { let f = files[0]; let action = match f.status { - crate::git::FileStatus::Added => "add", - crate::git::FileStatus::Deleted => "remove", - crate::git::FileStatus::Modified => "update", - crate::git::FileStatus::Renamed => "rename", - crate::git::FileStatus::Unknown => "change", + super::git::FileStatus::Added => "add", + super::git::FileStatus::Deleted => "remove", + super::git::FileStatus::Modified => "update", + super::git::FileStatus::Renamed => "rename", + super::git::FileStatus::Unknown => "change", }; let file_name = std::path::Path::new(&f.path) .file_name() @@ -219,7 +214,7 @@ fn generate_description(files: &[&crate::git::ChangedFile]) -> String { let total = files.len(); let added: usize = files.iter().filter(|f| f.is_new).count(); - let modified: usize = files.iter().filter(|f| matches!(f.status, crate::git::FileStatus::Modified)).count(); + let modified: usize = files.iter().filter(|f| matches!(f.status, super::git::FileStatus::Modified)).count(); if added == total { format!("add {} new files", total) @@ -256,7 +251,7 @@ mod tests { #[test] fn test_format_change_summary() { - let mut changes = HashMap::new(); + let mut changes = std::collections::HashMap::new(); changes.insert("modified".to_string(), vec!["src/main.rs".to_string(), "Cargo.toml".to_string()]); changes.insert("added".to_string(), vec!["src/new_module.rs".to_string()]);