44
examples/custom_config.rs
Normal file
44
examples/custom_config.rs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
use git_commit_prefix_gen::{Config, CommitConvention};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("Git Commit Prefix Generator - Custom Configuration Example");
|
||||||
|
println!("=========================================================\n");
|
||||||
|
|
||||||
|
let custom_config = r#"
|
||||||
|
type_mapping:
|
||||||
|
- pattern: "src/**/*.rs" type: "feat"
|
||||||
|
- pattern: "tests/**/*.rs" type: "test"
|
||||||
|
- pattern: "docs/**/*.md" type: "docs"
|
||||||
|
scope_patterns:
|
||||||
|
- pattern: "^src/([^/]+)/" base: "src"
|
||||||
|
- pattern: "^lib/([^/]+)/" base: "lib"
|
||||||
|
ignored_patterns:
|
||||||
|
- "^target/"
|
||||||
|
- "^node_modules/"
|
||||||
|
"#;
|
||||||
|
|
||||||
|
println!("Custom config:\n{}", custom_config);
|
||||||
|
|
||||||
|
let config: Config = serde_yaml::from_str(custom_config).expect("Failed to parse config");
|
||||||
|
let convention = config.to_convention();
|
||||||
|
|
||||||
|
println!("\nTesting type detection with custom rules:");
|
||||||
|
|
||||||
|
let test_files = vec!["src/auth/login.rs", "tests/main.rs", "docs/README.md"];
|
||||||
|
|
||||||
|
for file in test_files {
|
||||||
|
if let Some((commit_type, confidence)) = convention.detect_type(file) {
|
||||||
|
println!(" {} -> {} (confidence: {:.0}%)", file, commit_type, confidence * 100.0);
|
||||||
|
} else {
|
||||||
|
println!(" {} -> No type detected", file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("\nTesting scope detection:");
|
||||||
|
let test_scope_files = vec!["src/auth/login.rs", "lib/database/connection.rs"];
|
||||||
|
|
||||||
|
for file in test_scope_files {
|
||||||
|
let scope = convention.detect_scope(file);
|
||||||
|
println!(" {} -> scope: {:?}", file, scope.map(|s| s.name));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user