fix: Update analyzer.rs with proper pub modifiers and super::git imports
Some checks failed
CI / lint (push) Failing after 4s
CI / build (push) Has been skipped
CI / test (push) Has been skipped

This commit is contained in:
2026-02-01 12:33:34 +00:00
parent 28ce772dff
commit b0b9dfab9f

View File

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