Base protocol refactor complete
parent: tbd commit: 079d544
1 | use ; |
2 | use FromStr; |
3 | |
4 | use ; |
5 | |
6 | use crate GiteratedObject; |
7 | |
8 | use ; |
9 | |
10 | /// A repository, defined by the instance it exists on along with |
11 | /// its owner and name. |
12 | /// |
13 | /// # Textual Format |
14 | /// A repository's textual reference is defined as: |
15 | /// |
16 | /// `{owner: User}/{name: String}@{instance: Instance}` |
17 | /// |
18 | /// # Examples |
19 | /// For the repository named `foo` owned by `barson:giterated.dev` on the instance |
20 | /// `giterated.dev`, the following [`Repository`] initialization would |
21 | /// be valid: |
22 | /// |
23 | /// ``` |
24 | //# use giterated_models::model::repository::Repository; |
25 | //# use giterated_models::model::instance::Instance; |
26 | //# use giterated_models::model::user::User; |
27 | /// let repository = Repository { |
28 | /// owner: User::from_str("barson:giterated.dev").unwrap(), |
29 | /// name: String::from("foo"), |
30 | /// instance: Instance::from_str("giterated.dev").unwrap() |
31 | /// }; |
32 | /// |
33 | /// // This is correct |
34 | /// assert_eq!(Repository::from_str("barson:giterated.dev/[email protected]").unwrap(), repository); |
35 | /// ``` |
36 | |
37 | |
38 | pub owner: User, |
39 | pub name: String, |
40 | /// Instance the repository is on |
41 | pub instance: Instance, |
42 | |
43 | |
44 | |
45 | |
46 | f.write_str |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | "repository" |
53 | |
54 | |
55 | |
56 | Ok |
57 | |
58 | |
59 | |
60 | |
61 | type Error = RepositoryParseError; |
62 | |
63 | |
64 | Self from_str |
65 | |
66 | |
67 | |
68 | |
69 | type Err = RepositoryParseError; |
70 | |
71 | |
72 | let mut by_ampersand = s.split; |
73 | let mut path_split = by_ampersand.next .unwrap .split; |
74 | |
75 | let instance = from_str .unwrap; |
76 | let owner = from_str .unwrap; |
77 | let name = path_split.next .unwrap .to_string; |
78 | |
79 | Ok |
80 | instance, |
81 | owner, |
82 | name, |
83 | |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | |
90 | /// Visibility of the repository to the general eye |
91 | |
92 | |
93 | |
94 | Public, |
95 | Unlisted, |
96 | Private, |
97 | |
98 | |
99 | /// Implements [`Display`] for [`RepositoryVisiblity`] using [`Debug`] |
100 | |
101 | |
102 | write! |
103 | |
104 | |
105 | |
106 | |
107 | |
108 | /// Name of the repository |
109 | /// |
110 | /// This is different than the [`Repository`] name, |
111 | /// which may be a path. |
112 | pub name: String, |
113 | /// Owner of the Repository |
114 | pub owner: User, |
115 | /// Repository description |
116 | pub description: , |
117 | /// Repository visibility |
118 | pub visibility: RepositoryVisibility, |
119 | /// Default branch of the repository |
120 | pub default_branch: String, |
121 | /// Last commit made to the repository |
122 | pub latest_commit: , |
123 | /// Revision of the displayed tree |
124 | pub tree_rev: , |
125 | /// Repository tree |
126 | pub tree: , |
127 | |
128 | |
129 | |
130 | |
131 | Tree, |
132 | Blob, |
133 | |
134 | |
135 | /// Stored info for our tree entries |
136 | |
137 | |
138 | /// Name of the tree/blob |
139 | pub name: String, |
140 | /// Type of the tree entry |
141 | pub object_type: RepositoryObjectType, |
142 | /// Git supplies us with the mode at all times, and people like it displayed. |
143 | pub mode: i32, |
144 | /// File size |
145 | pub size: , |
146 | /// Last commit made to the tree/blob |
147 | pub last_commit: , |
148 | |
149 | |
150 | |
151 | // I love you Emilia <3 |
152 | |
153 | Self |
154 | name: name.to_string, |
155 | object_type, |
156 | mode, |
157 | size: None, |
158 | last_commit: None, |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | |
165 | pub tree_entry: RepositoryTreeEntry, |
166 | pub commit: Commit, |
167 | |
168 | |
169 | /// Info about a git commit |
170 | |
171 | |
172 | /// Unique commit ID |
173 | pub oid: String, |
174 | /// Shortened abbreviated OID |
175 | /// This starts at the git config's "core.abbrev" length (default 7 characters) and |
176 | /// iteratively extends to a longer string if that length is ambiguous. The |
177 | /// result will be unambiguous (at least until new objects are added to the repository). |
178 | pub short_oid: String, |
179 | /// Full commit message |
180 | pub message: , |
181 | /// Who created the commit |
182 | pub author: CommitSignature, |
183 | /// Who committed the commit |
184 | pub committer: CommitSignature, |
185 | /// Time when the commit happened |
186 | pub time: NaiveDateTime, |
187 | |
188 | |
189 | /// Gets all info from [`git2::Commit`] for easy use |
190 | |
191 | |
192 | Self |
193 | oid: commit.id .to_string, |
194 | // This shouldn't ever fail, as we already know the object has an oid. |
195 | short_oid: commit |
196 | .as_object |
197 | .short_id |
198 | .unwrap |
199 | .as_str |
200 | .unwrap |
201 | .to_string, |
202 | message: commit.message .map, |
203 | author: commit.author .into, |
204 | committer: commit.committer .into, |
205 | time: from_timestamp_opt .unwrap, |
206 | |
207 | |
208 | |
209 | |
210 | /// Git commit signature |
211 | |
212 | |
213 | pub name: , |
214 | pub email: , |
215 | pub time: NaiveDateTime, |
216 | |
217 | |
218 | /// Converts the signature from git2 into something usable without explicit lifetimes. |
219 | |
220 | |
221 | Self |
222 | name: signature.name .map, |
223 | email: signature.email .map, |
224 | time: from_timestamp_opt .unwrap, |
225 | |
226 | |
227 | |
228 | |
229 | |
230 | |
231 | pub repository: Repository, |
232 | pub owner: User, |
233 | pub visibility: RepositoryVisibility, |
234 | pub description: , |
235 | pub last_commit: , |
236 | |
237 | |
238 | |
239 | |
240 | pub name: String, |
241 | pub color: String, |
242 | |
243 | |
244 | |
245 | |
246 | pub author: User, |
247 | pub id: u64, |
248 | pub title: String, |
249 | pub contents: String, |
250 | pub labels: , |
251 | |
252 |