Skip to content
Clone

feat(export): add repo tag_protection export

zhenyi committed
parent cb51611 commit 04f956a Browse files

1 file changed

+69 −0

Added lib/export/repo/tag_protection.rs View lib/export/repo/tag_protection.rs
@@ -0,0 +1,69 @@
1use db::repo::repo_tag_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
12fn parse_user_ids_csv(s: &str) -> Vec<String> {
13 s.split(',')
14 .map(str::trim)
15 .filter(|p| !p.is_empty())
16 .map(str::to_string)
17 .collect()
18}
19
20#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
21pub struct TagProtectionView {
22 pub id: Uuid,
23 pub repo_id: Uuid,
24 pub name_pattern: String,
25 pub whitelist_usernames: Vec<String>,
26 pub whitelist_teams: Vec<String>,
27 pub created_at: String,
28 pub updated_at: String,
29}
30
31impl From<policy_entity::Model> for TagProtectionView {
32 fn from(m: policy_entity::Model) -> Self {
33 Self {
34 id: m.id,
35 repo_id: m.repo_id,
36 name_pattern: m.name_pattern,
37 whitelist_usernames: parse_user_ids_csv(&m.allowlist_user_ids),
38 whitelist_teams: Vec::new(),
39 created_at: fmt_ts(m.created_at),
40 updated_at: fmt_ts(m.updated_at),
41 }
42 }
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
46pub struct TagProtectionPage {
47 pub items: Vec<TagProtectionView>,
48 pub total: i64,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
52pub struct CreateTagProtectionOption {
53 pub name_pattern: String,
54 pub whitelist_usernames: Option<Vec<Uuid>>,
55 pub whitelist_teams: Option<Vec<String>>,
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
59pub struct EditTagProtectionOption {
60 pub name_pattern: Option<String>,
61 pub whitelist_usernames: Option<Vec<Uuid>>,
62 pub whitelist_teams: Option<Vec<String>>,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
66pub struct ListTagProtectionQuery {
67 pub page: Option<u64>,
68 pub limit: Option<u64>,
69}