Skip to content
Clone

feat(export): add repo tag export

zhenyi committed
parent b79b838 commit cb51611 Browse files

1 file changed

+81 −0

Added lib/export/repo/tag.rs View lib/export/repo/tag.rs
@@ -0,0 +1,81 @@
1use db::git::git_tags as tag_entity;
2use db::git::git_tags::TagType;
3use serde::{Deserialize, Serialize};
4use time::OffsetDateTime;
5use time::format_description::well_known::Rfc3339;
6use utoipa::{IntoParams, ToSchema};
7use uuid::Uuid;
8
9use super::branch::CommitMeta;
10
11fn fmt_ts(ts: OffsetDateTime) -> String {
12 ts.format(&Rfc3339).unwrap_or_default()
13}
14
15fn fmt_ts_opt(ts: Option<OffsetDateTime>) -> Option<String> {
16 ts.map(fmt_ts)
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
20pub struct TagView {
21 pub id: Uuid,
22 pub repo_id: Uuid,
23 pub name: String,
24 pub tag_type: String,
25
26 pub commit_sha: String,
27 pub commit: CommitMeta,
28 pub message: String,
29 pub zipball_url: String,
30 pub tarball_url: String,
31 pub created_at: String,
32}
33
34impl From<tag_entity::Model> for TagView {
35 fn from(m: tag_entity::Model) -> Self {
36 Self {
37 id: m.id,
38 repo_id: m.repo_id,
39 name: m.name,
40 tag_type: match m.tag_type {
41 TagType::Lightweight => "lightweight".to_string(),
42 TagType::Annotated => "annotated".to_string(),
43 },
44 commit_sha: m.commit_sha.clone(),
45 commit: CommitMeta {
46 sha: m.commit_sha,
47 message: m.message.clone().unwrap_or_default(),
48 author_name: m.tagger_name.clone(),
49 author_email: m.tagger_email.clone(),
50 committer_name: m.tagger_name,
51 committer_email: m.tagger_email,
52 authored_at: None,
53 committed_at: None,
54 tree_sha: None,
55 },
56 message: m.message.unwrap_or_default(),
57 zipball_url: String::new(),
58 tarball_url: String::new(),
59 created_at: fmt_ts(m.created_at),
60 }
61 }
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
65pub struct TagPage {
66 pub items: Vec<TagView>,
67 pub total: i64,
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
71pub struct CreateTagOption {
72 pub tag_name: String,
73 pub target: Option<String>,
74 pub message: Option<String>,
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
78pub struct ListTagQuery {
79 pub page: Option<u64>,
80 pub limit: Option<u64>,
81}