Skip to content
Clone

feat(export): add repo lifecycle export

zhenyi committed
parent d5d3b70 commit 36ceb8e Browse files

1 file changed

+322 −0

Added lib/export/repo/lifecycle.rs View lib/export/repo/lifecycle.rs
@@ -0,0 +1,322 @@
1use db::repo::repos as repo_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
12fn fmt_ts_opt(ts: Option<OffsetDateTime>) -> Option<String> {
13 ts.map(fmt_ts)
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
17pub struct SpaceSummary {
18 pub id: Uuid,
19 pub name: String,
20 pub display_name: Option<String>,
21}
22
23impl SpaceSummary {
24 pub fn none() -> Option<Self> {
25 None
26 }
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
30pub struct ChannelSummary {
31 pub id: Uuid,
32 pub space_id: Uuid,
33 pub name: String,
34 pub display_name: Option<String>,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
38pub struct Permission {
39 pub admin: bool,
40 pub push: bool,
41 pub pull: bool,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
45pub struct InternalTracker {
46 pub enable_time_tracker: bool,
47 pub allow_only_contributors_to_track_time: bool,
48 pub enable_issue_dependencies: bool,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
52pub struct ExternalTracker {
53 pub external_tracker_url: String,
54 pub external_tracker_format: String,
55 pub external_tracker_style: String,
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
59pub struct ExternalWiki {
60 pub external_wiki_url: String,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
64pub struct RepoView {
65 pub id: Uuid,
66 pub channel_id: Uuid,
67 pub space_id: Uuid,
68
69 pub name: String,
70 pub lower_name: String,
71 pub full_name: String,
72
73 pub description: Option<String>,
74 pub website: Option<String>,
75 pub default_branch: String,
76 pub enable_lfs: bool,
77 pub is_private: bool,
78 pub is_archived: bool,
79 pub is_fork: bool,
80 pub is_template: bool,
81 pub is_mirror: bool,
82 pub empty: bool,
83 pub parent: Option<Box<RepoView>>,
84
85 pub size: i64,
86 pub git_size: i64,
87 pub lfs_size: i64,
88 pub storage_limit_size: Option<i64>,
89
90 pub nums_watch: i32,
91 pub nums_star: i32,
92 pub nums_pr: i32,
93 pub nums_commits: i32,
94 pub nums_branches: i32,
95 pub nums_tags: i32,
96
97 pub allow_rebase: bool,
98 pub allow_rebase_explicit: bool,
99 pub allow_squash_merge: bool,
100 pub allow_merge_commits: bool,
101 pub allow_fast_forward_only_merge: bool,
102 pub allow_rebase_update: bool,
103 pub allow_merge_update: bool,
104 pub allow_manual_merge: bool,
105 pub autodetect_manual_merge: bool,
106 pub default_delete_branch_after_merge: bool,
107 pub default_allow_maintainer_edit: bool,
108 pub ignore_whitespace_conflicts: bool,
109
110 pub object_format: String,
111
112 pub has_code: bool,
113 pub has_issues: bool,
114 pub has_wiki: bool,
115 pub has_pull_requests: bool,
116 pub has_projects: bool,
117 pub has_releases: bool,
118 pub has_packages: bool,
119 pub has_actions: bool,
120 pub projects_mode: String,
121
122 pub primary_language: Option<String>,
123 pub languages: Vec<String>,
124 pub license_name: Option<String>,
125 pub licenses: Vec<String>,
126 pub topics: Vec<String>,
127
128 pub html_url: String,
129 pub url: String,
130 pub link: String,
131 pub ssh_url: String,
132 pub clone_url: String,
133 pub avatar_url: Option<String>,
134
135 pub space: Option<SpaceSummary>,
136 pub channel: Option<ChannelSummary>,
137
138 pub created_at: String,
139 pub updated_at: String,
140 pub last_pushed_at: Option<String>,
141 pub archived_at: Option<String>,
142}
143
144impl From<repo_entity::Model> for RepoView {
145 fn from(m: repo_entity::Model) -> Self {
146 let full_name = format!("ch-{}/{}", m.channel_id, m.name);
147 Self {
148 id: m.id,
149 channel_id: m.channel_id,
150 space_id: m.channel_id,
151 name: m.name.clone(),
152 lower_name: m.lower_name,
153 full_name,
154 description: m.description,
155 website: m.website,
156 default_branch: m.default_branch,
157 enable_lfs: m.enable_lfs,
158 is_private: m.is_private,
159 is_archived: m.is_archived,
160 is_fork: false,
161 is_template: false,
162 is_mirror: false,
163 empty: false,
164 parent: None,
165 size: m.size,
166 git_size: m.git_size,
167 lfs_size: m.lfs_size,
168 storage_limit_size: m.storage_limit_size,
169 nums_watch: m.nums_watch,
170 nums_star: m.nums_star,
171 nums_pr: m.nums_pr,
172 nums_commits: m.nums_commits,
173 nums_branches: m.nums_branches,
174 nums_tags: m.nums_tags,
175 allow_rebase: m.allow_rebase,
176 allow_rebase_explicit: m.allow_rebase_explicit,
177 allow_squash_merge: m.allow_squash_merge,
178 allow_merge_commits: m.allow_merge_commits,
179 allow_fast_forward_only_merge: false,
180 allow_rebase_update: false,
181 allow_merge_update: false,
182 allow_manual_merge: false,
183 autodetect_manual_merge: false,
184 default_delete_branch_after_merge: false,
185 default_allow_maintainer_edit: false,
186 ignore_whitespace_conflicts: false,
187 object_format: m.object_format,
188 has_code: true,
189 has_issues: false,
190 has_wiki: false,
191 has_pull_requests: false,
192 has_projects: false,
193 has_releases: true,
194 has_packages: false,
195 has_actions: false,
196 projects_mode: "off".to_string(),
197 primary_language: m.primary_language.clone(),
198 languages: m.primary_language.into_iter().collect(),
199 license_name: m.license_name.clone(),
200 licenses: m.license_name.into_iter().collect(),
201 topics: Vec::new(),
202 html_url: String::new(),
203 url: String::new(),
204 link: String::new(),
205 ssh_url: String::new(),
206 clone_url: String::new(),
207 avatar_url: m.avatar_url,
208 space: None,
209 channel: None,
210 created_at: fmt_ts(m.created_at),
211 updated_at: fmt_ts_opt(m.last_pushed_at).unwrap_or_else(|| fmt_ts(m.created_at)),
212 last_pushed_at: fmt_ts_opt(m.last_pushed_at),
213 archived_at: fmt_ts_opt(m.archived_at),
214 }
215 }
216}
217
218#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
219pub struct RepoPage {
220 pub items: Vec<RepoView>,
221 pub total: i64,
222}
223
224#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
225pub struct CreateRepoOption {
226 pub channel_id: Uuid,
227 pub name: String,
228 pub description: Option<String>,
229 pub website: Option<String>,
230 pub default_branch: Option<String>,
231 pub is_private: Option<bool>,
232 pub enable_lfs: Option<bool>,
233 pub auto_init: Option<bool>,
234 pub template: Option<bool>,
235 pub license_name: Option<String>,
236 pub readme: Option<String>,
237 pub gitignores: Option<String>,
238 pub issue_labels: Option<String>,
239 pub object_format: Option<String>,
240}
241
242#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
243pub struct UpdateRepoOption {
244 pub description: Option<Option<String>>,
245 pub website: Option<Option<String>>,
246 pub default_branch: Option<String>,
247 pub is_private: Option<bool>,
248 pub enable_lfs: Option<bool>,
249 pub license_name: Option<Option<String>>,
250 pub allow_rebase: Option<bool>,
251 pub allow_rebase_explicit: Option<bool>,
252 pub allow_squash_merge: Option<bool>,
253 pub allow_merge_commits: Option<bool>,
254 pub allow_fast_forward_only_merge: Option<bool>,
255 pub allow_rebase_update: Option<bool>,
256 pub allow_merge_update: Option<bool>,
257 pub allow_manual_merge: Option<bool>,
258 pub autodetect_manual_merge: Option<bool>,
259 pub default_delete_branch_after_merge: Option<bool>,
260 pub default_allow_maintainer_edit: Option<bool>,
261 pub ignore_whitespace_conflicts: Option<bool>,
262 pub default_merge_style: Option<String>,
263 pub default_update_style: Option<String>,
264 pub archived: Option<bool>,
265
266 pub name: Option<String>,
267 pub template: Option<bool>,
268 pub has_code: Option<bool>,
269 pub has_issues: Option<bool>,
270 pub has_wiki: Option<bool>,
271 pub has_pull_requests: Option<bool>,
272 pub has_projects: Option<bool>,
273 pub has_releases: Option<bool>,
274 pub has_packages: Option<bool>,
275 pub has_actions: Option<bool>,
276 pub projects_mode: Option<String>,
277 pub internal_tracker: Option<InternalTracker>,
278 pub external_tracker: Option<ExternalTracker>,
279 pub external_wiki: Option<ExternalWiki>,
280}
281
282#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
283pub struct TransferRepoOption {
284 pub new_channel_id: Uuid,
285 pub new_name: Option<String>,
286}
287
288#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
289pub struct ArchiveRepoOption {
290 pub archived: bool,
291}
292
293#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
294pub struct RenameRepoOption {
295 pub new_name: String,
296}
297
298#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
299pub struct ForkRepoOption {
300 pub to_channel_id: Uuid,
301 pub name: Option<String>,
302 pub description: Option<String>,
303}
304
305#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
306pub struct GenerateRepoOption {
307 pub to_channel_id: Uuid,
308 pub name: String,
309 pub description: Option<String>,
310 pub is_private: Option<bool>,
311}
312
313#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
314pub struct ListRepoQuery {
315 pub channel_id: Option<Uuid>,
316 pub owner_user_id: Option<Uuid>,
317 pub is_private: Option<bool>,
318 pub is_archived: Option<bool>,
319 pub q: Option<String>,
320 pub limit: Option<u64>,
321 pub offset: Option<u64>,
322}