refactor(repo): remove branch_protection types (inlined)
zhenyi committed
Deleted lib/repo/features/branch_protection/types.rs lib/repo/features/branch_protection/types.rs +0 −188
@@ -1,188 +0,0 @@
1use db::repo::repo_branch_protection_policy as policy_entity;
2use serde::{Deserialize, Serialize};
3use time::OffsetDateTime;
4use time::format_description::well_known::Rfc3339;
5use utoipa::{IntoParams, ToSchema};
6use uuid::Uuid;
7
8fn fmt_ts(ts: OffsetDateTime) -> String {
9 ts.format(&Rfc3339).unwrap_or_default()
10}
11
12#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
13pub struct BranchProtectionView {
14 pub id: Uuid,
15 pub repo_id: Uuid,
16 pub branch_name: String,
17 pub rule_name: String,
18 pub priority: i64,
19
20 pub enable_push: bool,
21 pub enable_push_whitelist: bool,
22 pub push_whitelist_usernames: Vec<String>,
23 pub push_whitelist_teams: Vec<String>,
24 pub push_whitelist_deploy_keys: bool,
25
26 pub enable_force_push: bool,
27 pub enable_force_push_allowlist: bool,
28 pub force_push_allowlist_usernames: Vec<String>,
29 pub force_push_allowlist_teams: Vec<String>,
30 pub force_push_allowlist_deploy_keys: bool,
31
32 pub enable_merge_whitelist: bool,
33 pub merge_whitelist_usernames: Vec<String>,
34 pub merge_whitelist_teams: Vec<String>,
35
36 pub enable_bypass_allowlist: bool,
37 pub bypass_allowlist_usernames: Vec<String>,
38 pub bypass_allowlist_teams: Vec<String>,
39
40 pub enable_approvals_whitelist: bool,
41 pub approvals_whitelist_usernames: Vec<String>,
42 pub approvals_whitelist_teams: Vec<String>,
43 pub required_approvals: i32,
44
45 pub block_on_rejected_reviews: bool,
46 pub block_on_change_requested_reviews: bool,
47 pub block_on_outdated_branch: bool,
48 pub dismiss_stale_approvals: bool,
49 pub ignore_stale_approvals: bool,
50 pub require_signed_commits: bool,
51 pub block_admin_merge_override: bool,
52
53 pub protected_file_patterns: String,
54 pub unprotected_file_patterns: String,
55
56 pub created_at: String,
57 pub updated_at: String,
58}
59
60impl From<policy_entity::Model> for BranchProtectionView {
61 fn from(m: policy_entity::Model) -> Self {
62 Self {
63 id: m.id,
64 repo_id: m.repo_id,
65 branch_name: m.branch_name.clone(),
66 rule_name: m.branch_name,
67 priority: 0,
68 enable_push: m.enable_push,
69 enable_push_whitelist: m.enable_push_whitelist,
70 push_whitelist_usernames: Vec::new(),
71 push_whitelist_teams: Vec::new(),
72 push_whitelist_deploy_keys: m.push_whitelist_deploy_keys,
73 enable_force_push: false,
74 enable_force_push_allowlist: false,
75 force_push_allowlist_usernames: Vec::new(),
76 force_push_allowlist_teams: Vec::new(),
77 force_push_allowlist_deploy_keys: false,
78 enable_merge_whitelist: m.enable_merge_whitelist,
79 merge_whitelist_usernames: Vec::new(),
80 merge_whitelist_teams: Vec::new(),
81 enable_bypass_allowlist: false,
82 bypass_allowlist_usernames: Vec::new(),
83 bypass_allowlist_teams: Vec::new(),
84 enable_approvals_whitelist: m.enable_approvals_whitelist,
85 approvals_whitelist_usernames: Vec::new(),
86 approvals_whitelist_teams: Vec::new(),
87 required_approvals: m.required_approvals,
88 block_on_rejected_reviews: m.block_on_rejected_reviews,
89 block_on_change_requested_reviews: m.block_on_change_requested_reviews,
90 block_on_outdated_branch: m.block_on_outdated_branch,
91 dismiss_stale_approvals: m.dismiss_stale_approvals,
92 ignore_stale_approvals: false,
93 require_signed_commits: m.require_signed_commits,
94 block_admin_merge_override: false,
95 protected_file_patterns: m.protected_file_patterns,
96 unprotected_file_patterns: m.unprotected_file_patterns,
97 created_at: fmt_ts(m.created_at),
98 updated_at: fmt_ts(m.updated_at),
99 }
100 }
101}
102
103#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
104pub struct BranchProtectionPage {
105 pub items: Vec<BranchProtectionView>,
106 pub total: i64,
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
110pub struct CreateBranchProtectionOption {
111 pub branch_name: String,
112 pub rule_name: Option<String>,
113 pub priority: Option<i64>,
114 pub enable_push: Option<bool>,
115 pub enable_push_whitelist: Option<bool>,
116 pub push_whitelist_usernames: Option<Vec<String>>,
117 pub push_whitelist_teams: Option<Vec<String>>,
118 pub push_whitelist_deploy_keys: Option<bool>,
119 pub enable_force_push: Option<bool>,
120 pub enable_force_push_allowlist: Option<bool>,
121 pub force_push_allowlist_usernames: Option<Vec<String>>,
122 pub force_push_allowlist_teams: Option<Vec<String>>,
123 pub force_push_allowlist_deploy_keys: Option<bool>,
124 pub enable_merge_whitelist: Option<bool>,
125 pub merge_whitelist_usernames: Option<Vec<String>>,
126 pub merge_whitelist_teams: Option<Vec<String>>,
127 pub enable_bypass_allowlist: Option<bool>,
128 pub bypass_allowlist_usernames: Option<Vec<String>>,
129 pub bypass_allowlist_teams: Option<Vec<String>>,
130 pub enable_approvals_whitelist: Option<bool>,
131 pub approvals_whitelist_usernames: Option<Vec<String>>,
132 pub approvals_whitelist_teams: Option<Vec<String>>,
133 pub required_approvals: Option<i32>,
134 pub block_on_rejected_reviews: Option<bool>,
135 pub block_on_change_requested_reviews: Option<bool>,
136 pub block_on_outdated_branch: Option<bool>,
137 pub dismiss_stale_approvals: Option<bool>,
138 pub ignore_stale_approvals: Option<bool>,
139 pub require_signed_commits: Option<bool>,
140 pub block_admin_merge_override: Option<bool>,
141 pub protected_file_patterns: Option<String>,
142 pub unprotected_file_patterns: Option<String>,
143}
144
145#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
146pub struct EditBranchProtectionOption {
147 pub priority: Option<i64>,
148 pub enable_push: Option<bool>,
149 pub enable_push_whitelist: Option<bool>,
150 pub push_whitelist_usernames: Option<Vec<String>>,
151 pub push_whitelist_teams: Option<Vec<String>>,
152 pub push_whitelist_deploy_keys: Option<bool>,
153 pub enable_force_push: Option<bool>,
154 pub enable_force_push_allowlist: Option<bool>,
155 pub force_push_allowlist_usernames: Option<Vec<String>>,
156 pub force_push_allowlist_teams: Option<Vec<String>>,
157 pub force_push_allowlist_deploy_keys: Option<bool>,
158 pub enable_merge_whitelist: Option<bool>,
159 pub merge_whitelist_usernames: Option<Vec<String>>,
160 pub merge_whitelist_teams: Option<Vec<String>>,
161 pub enable_bypass_allowlist: Option<bool>,
162 pub bypass_allowlist_usernames: Option<Vec<String>>,
163 pub bypass_allowlist_teams: Option<Vec<String>>,
164 pub enable_approvals_whitelist: Option<bool>,
165 pub approvals_whitelist_usernames: Option<Vec<String>>,
166 pub approvals_whitelist_teams: Option<Vec<String>>,
167 pub required_approvals: Option<i32>,
168 pub block_on_rejected_reviews: Option<bool>,
169 pub block_on_change_requested_reviews: Option<bool>,
170 pub block_on_outdated_branch: Option<bool>,
171 pub dismiss_stale_approvals: Option<bool>,
172 pub ignore_stale_approvals: Option<bool>,
173 pub require_signed_commits: Option<bool>,
174 pub block_admin_merge_override: Option<bool>,
175 pub protected_file_patterns: Option<String>,
176 pub unprotected_file_patterns: Option<String>,
177}
178
179#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
180pub struct UpdateBranchProtectionPriorities {
181 pub ids: Vec<Uuid>,
182}
183
184#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
185pub struct ListBranchProtectionQuery {
186 pub page: Option<u64>,
187 pub limit: Option<u64>,
188}