1 |
use serde::{Deserialize, Serialize};
|
2 |
|
3 |
use super::instance::Instance;
|
4 |
|
5 |
#[derive(Hash, Clone, Serialize, Deserialize)]
|
6 |
pub struct Repository {
|
7 |
|
8 |
pub owner_username: String,
|
9 |
|
10 |
pub visibility: RepositoryVisibility,
|
11 |
|
12 |
pub name: String,
|
13 |
|
14 |
pub instance: Instance,
|
15 |
}
|
16 |
|
17 |
|
18 |
#[derive(Debug, Hash, Serialize, Deserialize, Clone, sqlx::Type)]
|
19 |
#[sqlx(type_name = "visibility", rename_all = "lowercase")]
|
20 |
pub enum RepositoryVisibility {
|
21 |
Public,
|
22 |
Unlisted,
|
23 |
Private,
|
24 |
}
|
25 |
|
26 |
#[derive(Clone, Debug, Serialize, Deserialize)]
|
27 |
pub struct RepositoryView {
|
28 |
|
29 |
pub name: String,
|
30 |
|
31 |
pub description: Option<String>,
|
32 |
|
33 |
pub visibility: RepositoryVisibility,
|
34 |
|
35 |
pub default_branch: String,
|
36 |
|
37 |
pub latest_commit: Option<Commit>,
|
38 |
|
39 |
pub tree_rev: Option<String>,
|
40 |
|
41 |
pub tree: Vec<RepositoryTreeEntry>,
|
42 |
}
|
43 |
|
44 |
#[derive(Debug, Clone, Serialize, Deserialize)]
|
45 |
pub enum RepositoryObjectType {
|
46 |
Tree,
|
47 |
Blob,
|
48 |
}
|
49 |
|
50 |
|
51 |
#[derive(Debug, Clone, Serialize, Deserialize)]
|
52 |
pub struct RepositoryTreeEntry {
|
53 |
|
54 |
pub name: String,
|
55 |
|
56 |
pub object_type: RepositoryObjectType,
|
57 |
|
58 |
pub mode: i32,
|
59 |
|
60 |
pub size: Option<usize>,
|
61 |
|
62 |
pub last_commit: Option<Commit>,
|
63 |
}
|
64 |
|
65 |
impl RepositoryTreeEntry {
|
66 |
|
67 |
pub fn new(name: &str, object_type: RepositoryObjectType, mode: i32) -> Self {
|
68 |
Self {
|
69 |
name: name.to_string(),
|
70 |
object_type,
|
71 |
mode,
|
72 |
size: None,
|
73 |
last_commit: None,
|
74 |
}
|
75 |
}
|
76 |
}
|
77 |
|
78 |
#[derive(Debug, Clone, Serialize, Deserialize)]
|
79 |
pub struct RepositoryTreeEntryWithCommit {
|
80 |
pub tree_entry: RepositoryTreeEntry,
|
81 |
pub commit: Commit,
|
82 |
}
|
83 |
|
84 |
|
85 |
#[derive(Debug, Clone, Serialize, Deserialize)]
|
86 |
pub struct Commit {
|
87 |
|
88 |
pub oid: String,
|
89 |
|
90 |
pub message: Option<String>,
|
91 |
|
92 |
pub author: CommitSignature,
|
93 |
|
94 |
pub committer: CommitSignature,
|
95 |
|
96 |
pub time: chrono::NaiveDateTime,
|
97 |
}
|
98 |
|
99 |
|
100 |
impl From<git2::Commit<'_>> for Commit {
|
101 |
fn from(commit: git2::Commit<'_>) -> Self {
|
102 |
Self {
|
103 |
oid: commit.id().to_string(),
|
104 |
message: commit
|
105 |
.message()
|
106 |
.map_or(None, |message| Some(message.to_string())),
|
107 |
author: commit.author().into(),
|
108 |
committer: commit.committer().into(),
|
109 |
time: chrono::NaiveDateTime::from_timestamp_opt(commit.time().seconds(), 0).unwrap(),
|
110 |
}
|
111 |
}
|
112 |
}
|
113 |
|
114 |
|
115 |
#[derive(Debug, Clone, Serialize, Deserialize)]
|
116 |
pub struct CommitSignature {
|
117 |
pub name: Option<String>,
|
118 |
pub email: Option<String>,
|
119 |
pub time: chrono::NaiveDateTime,
|
120 |
}
|
121 |
|
122 |
|
123 |
impl From<git2::Signature<'_>> for CommitSignature {
|
124 |
fn from(signature: git2::Signature<'_>) -> Self {
|
125 |
Self {
|
126 |
name: signature.name().map_or(None, |name| Some(name.to_string())),
|
127 |
email: signature
|
128 |
.email()
|
129 |
.map_or(None, |email| Some(email.to_string())),
|
130 |
time: chrono::NaiveDateTime::from_timestamp_opt(signature.when().seconds(), 0).unwrap(),
|
131 |
}
|
132 |
}
|
133 |
}
|
134 |
|