commit_wizard/engine/models/policy/
release.rs1use crate::engine::models::runtime::ResolvedConfig;
2
3#[derive(Debug, Clone)]
4pub struct ReleaseValidationModel {
5 pub require_clean_worktree: bool,
6 pub fail_if_tag_exists: bool,
7 pub fail_if_release_branch_exists: bool,
8}
9
10#[derive(Debug, Clone)]
11pub struct ReleaseFinishModel {
12 pub tag: bool,
13 pub push: bool,
14 pub backmerge_branch: String,
15}
16
17#[derive(Debug, Clone)]
18pub struct ReleaseModel {
19 pub enabled: bool,
20 pub source_branch: String,
21 pub target_branch: String,
22 pub branch_format: String,
23 pub hotfix_pattern: String,
24 pub validation: ReleaseValidationModel,
25 pub finish: ReleaseFinishModel,
26}
27
28impl Default for ReleaseModel {
29 fn default() -> Self {
30 Self {
31 enabled: false,
32 source_branch: "main".to_string(),
33 target_branch: "main".to_string(),
34 branch_format: "release/{version}".to_string(),
35 hotfix_pattern: "hotfix/*".to_string(),
36 validation: ReleaseValidationModel {
37 require_clean_worktree: true,
38 fail_if_tag_exists: true,
39 fail_if_release_branch_exists: true,
40 },
41 finish: ReleaseFinishModel {
42 tag: true,
43 push: true,
44 backmerge_branch: "main".to_string(),
45 },
46 }
47 }
48}
49
50impl ReleaseModel {
51 pub fn from_config(config: &ResolvedConfig) -> Self {
52 let base = &config.base;
53
54 Self {
55 enabled: base.release_enabled(),
56 source_branch: base.release_source_branch(),
57 target_branch: base.release_target_branch(),
58 branch_format: base.release_branch_format(),
59 hotfix_pattern: base.release_hotfix_pattern(),
60 validation: ReleaseValidationModel {
61 require_clean_worktree: base.release_require_clean_worktree(),
62 fail_if_tag_exists: base.release_fail_if_tag_exists(),
63 fail_if_release_branch_exists: base.release_fail_if_release_branch_exists(),
64 },
65 finish: ReleaseFinishModel {
66 tag: base.release_finish_tag(),
67 push: base.release_finish_push(),
68 backmerge_branch: base.release_finish_backmerge_branch(),
69 },
70 }
71 }
72}