Initial commit: git-issue-commit CLI tool
This commit is contained in:
82
src/generator/type_detector.rs
Normal file
82
src/generator/type_detector.rs
Normal file
@@ -0,0 +1,82 @@
|
||||
pub fn detect_type_from_text(text: &str) -> String {
|
||||
let text_lower = text.to_lowercase();
|
||||
|
||||
if text_lower.contains("fix") || text_lower.contains("bug") || text_lower.contains("error") {
|
||||
return "fix".to_string();
|
||||
}
|
||||
if text_lower.contains("feature") || text_lower.contains("add") || text_lower.contains("new") {
|
||||
return "feat".to_string();
|
||||
}
|
||||
if text_lower.contains("document") || text_lower.contains("doc") {
|
||||
return "docs".to_string();
|
||||
}
|
||||
if text_lower.contains("test") {
|
||||
return "test".to_string();
|
||||
}
|
||||
if text_lower.contains("refactor") {
|
||||
return "refactor".to_string();
|
||||
}
|
||||
if text_lower.contains("performance") || text_lower.contains("optimize") {
|
||||
return "perf".to_string();
|
||||
}
|
||||
if text_lower.contains("style") || text_lower.contains("format") {
|
||||
return "style".to_string();
|
||||
}
|
||||
if text_lower.contains("ci") || text_lower.contains("workflow") {
|
||||
return "ci".to_string();
|
||||
}
|
||||
if text_lower.contains("build") || text_lower.contains("dependenc") {
|
||||
return "build".to_string();
|
||||
}
|
||||
if text_lower.contains("revert") || text_lower.contains("undo") {
|
||||
return "revert".to_string();
|
||||
}
|
||||
|
||||
"chore".to_string()
|
||||
}
|
||||
|
||||
pub fn extract_scope_from_labels(labels: &[String]) -> Option<String> {
|
||||
for label in labels {
|
||||
let label_lower = label.to_lowercase();
|
||||
if label_lower.contains("backend") || label_lower.contains("server") {
|
||||
return Some("backend".to_string());
|
||||
}
|
||||
if label_lower.contains("frontend") || label_lower.contains("ui") || label_lower.contains("web") {
|
||||
return Some("frontend".to_string());
|
||||
}
|
||||
if label_lower.contains("api") {
|
||||
return Some("api".to_string());
|
||||
}
|
||||
if label_lower.contains("database") || label_lower.contains("db") {
|
||||
return Some("db".to_string());
|
||||
}
|
||||
if label_lower.contains("auth") {
|
||||
return Some("auth".to_string());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn extract_scope_from_path(path: &str) -> Option<String> {
|
||||
let parts: Vec<&str> = path.split('/').collect();
|
||||
|
||||
for &part in &parts {
|
||||
match part {
|
||||
"src" | "lib" => continue,
|
||||
"tests" | "test" => return Some("test".to_string()),
|
||||
"docs" | "documentation" => return Some("docs".to_string()),
|
||||
"api" => return Some("api".to_string()),
|
||||
"cli" => return Some("cli".to_string()),
|
||||
_ => {
|
||||
if part.ends_with(".rs") {
|
||||
let module_name = part.trim_end_matches(".rs");
|
||||
return Some(module_name.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parts.last()
|
||||
.map(|s| s.trim_end_matches(".rs").to_string())
|
||||
.filter(|s| !s.is_empty())
|
||||
}
|
||||
Reference in New Issue
Block a user