From 95f64a2c8f55dfb8ee9c503c946858b3f36326f1 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sat, 31 Jan 2026 11:41:59 +0000 Subject: [PATCH] Add example files --- examples/custom_config.rs | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 examples/custom_config.rs diff --git a/examples/custom_config.rs b/examples/custom_config.rs new file mode 100644 index 0000000..7e884b0 --- /dev/null +++ b/examples/custom_config.rs @@ -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)); + } +}