fix: Update analyzer.rs, generator.rs, and prompt.rs with proper imports
This commit is contained in:
@@ -55,9 +55,8 @@ pub fn analyze_changes(staged: &super::git::StagedChanges) -> AnalysisResult {
|
||||
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("");
|
||||
|
||||
let (type_, reason) = classify_file(&file.path, &file.status, ext, file_name, parent);
|
||||
let (type_, reason) = classify_file(&file.path, &file.status, ext, file_name);
|
||||
type_scores
|
||||
.entry(type_)
|
||||
.or_insert((0.0, Vec::new()))
|
||||
@@ -91,7 +90,6 @@ fn classify_file(
|
||||
status: &super::git::FileStatus,
|
||||
ext: &str,
|
||||
file_name: &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));
|
||||
@@ -145,37 +143,6 @@ pub fn extract_scope(path: &str) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn format_change_summary(changes: std::collections::HashMap<String, Vec<String>>) -> String {
|
||||
let mut summary = String::new();
|
||||
|
||||
let priority = vec!["added", "modified", "deleted", "renamed", "copied", "untacked"];
|
||||
|
||||
for change_type in priority {
|
||||
if let Some(files) = changes.get(change_type) {
|
||||
if files.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let prefix = match change_type {
|
||||
"added" => "➕ Files",
|
||||
"modified" => "✏️ Files",
|
||||
"deleted" => "🗑️ Files",
|
||||
"renamed" => "📝 Files",
|
||||
"copied" => "📋 Files",
|
||||
"untacked" => "🔍 Files",
|
||||
_ => "📄 Files",
|
||||
};
|
||||
|
||||
summary.push_str(&format!("{} {}:\n", prefix, change_type));
|
||||
for file in files {
|
||||
summary.push_str(&format!(" - {}\n", file));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
summary
|
||||
}
|
||||
|
||||
pub fn get_all_commit_types() -> Vec<CommitType> {
|
||||
vec![
|
||||
CommitType::Feat,
|
||||
@@ -243,22 +210,4 @@ mod tests {
|
||||
fn test_extract_scope_root() {
|
||||
assert_eq!(extract_scope("main.rs"), Some(String::from("main.rs")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_scope_docs() {
|
||||
assert_eq!(extract_scope("README.md"), Some(String::from("README.md")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_change_summary() {
|
||||
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()]);
|
||||
|
||||
let summary = format_change_summary(changes);
|
||||
assert!(summary.contains("➕ Files added:"));
|
||||
assert!(summary.contains("✏️ Files modified:"));
|
||||
assert!(summary.contains("src/main.rs"));
|
||||
assert!(summary.contains("src/new_module.rs"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user