commit_wizard/engine/models/policy/
branch.rs1use crate::engine::models::runtime::ResolvedConfig;
2
3#[derive(Debug, Clone)]
4pub struct BranchModel {
5 pub remote: String,
6 pub protected_patterns: Vec<String>,
7 pub naming_pattern: String,
8 pub enforce_naming: bool,
9 pub allowed_targets: Option<Vec<String>>,
10}
11
12impl Default for BranchModel {
13 fn default() -> Self {
14 Self {
15 remote: "origin".to_string(),
16 protected_patterns: vec![
17 "main".to_string(),
18 "master".to_string(),
19 "release/*".to_string(),
20 ],
21 naming_pattern: "feature/{issue}".to_string(),
22 enforce_naming: false,
23 allowed_targets: None,
24 }
25 }
26}
27
28impl BranchModel {
29 pub fn from_config(config: &ResolvedConfig) -> Self {
30 let base = &config.base;
31
32 Self {
33 remote: base.branch_remote(),
34 protected_patterns: base.branch_protected_patterns(),
35 naming_pattern: base.branch_naming_pattern(),
36 enforce_naming: base.branch_naming_enforce(),
37 allowed_targets: if base.branch_allowed_targets().is_empty() {
38 None
39 } else {
40 Some(base.branch_allowed_targets())
41 },
42 }
43 }
44
45 pub fn is_protected_pattern_configured(&self) -> bool {
46 !self.protected_patterns.is_empty()
47 }
48}