Huge refactor to prep for moving the daemon over to the plugin architecture
parent: tbd commit: 5df753c
1 | use ; |
2 | use FromStr; |
3 | |
4 | use ; |
5 | |
6 | use crate GiteratedObject; |
7 | |
8 | use ; |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | pub use *; |
15 | pub use *; |
16 | pub use *; |
17 | |
18 | /// A repository, defined by the instance it exists on along with |
19 | /// its owner and name. |
20 | /// |
21 | /// # Textual Format |
22 | /// A repository's textual reference is defined as: |
23 | /// |
24 | /// `{owner: User}/{name: String}@{instance: Instance}` |
25 | /// |
26 | /// # Examples |
27 | /// For the repository named `foo` owned by `barson:giterated.dev` on the instance |
28 | /// `giterated.dev`, the following [`Repository`] initialization would |
29 | /// be valid: |
30 | /// |
31 | /// ``` |
32 | //# use giterated_models::model::repository::Repository; |
33 | //# use giterated_models::model::instance::Instance; |
34 | //# use giterated_models::model::user::User; |
35 | /// let repository = Repository { |
36 | /// owner: User::from_str("barson:giterated.dev").unwrap(), |
37 | /// name: String::from("foo"), |
38 | /// instance: Instance::from_str("giterated.dev").unwrap() |
39 | /// }; |
40 | /// |
41 | /// // This is correct |
42 | /// assert_eq!(Repository::from_str("barson:giterated.dev/[email protected]").unwrap(), repository); |
43 | /// ``` |
44 | |
45 | |
46 | pub owner: User, |
47 | pub name: String, |
48 | /// Instance the repository is on |
49 | pub instance: Instance, |
50 | |
51 | |
52 | |
53 | |
54 | Self |
55 | owner, |
56 | name, |
57 | instance, |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | f.write_str |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | "repository" |
71 | |
72 | |
73 | |
74 | Ok |
75 | |
76 | |
77 | |
78 | self.instance.home_uri |
79 | |
80 | |
81 | |
82 | // impl TryFrom<String> for Repository { |
83 | // type Error = RepositoryParseError; |
84 | |
85 | // fn try_from(value: String) -> Result<Self, Self::Error> { |
86 | // Self::from_str(&value) |
87 | // } |
88 | // } |
89 | |
90 | |
91 | |
92 | unwrap | from_str .
93 | |
94 | |
95 | |
96 | |
97 | type Err = RepositoryParseError; |
98 | |
99 | |
100 | let mut by_ampersand = s.split; |
101 | let mut path_split = by_ampersand.next .ok_or?.split; |
102 | |
103 | let instance = from_str |
104 | .map_err?; |
105 | let owner = from_str |
106 | .map_err?; |
107 | let name = path_split.next .ok_or?.to_string; |
108 | |
109 | Ok |
110 | instance, |
111 | owner, |
112 | name, |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | ; |
120 | |
121 | /// Visibility of the repository to the general eye |
122 | |
123 | |
124 | |
125 | Public, |
126 | Unlisted, |
127 | Private, |
128 | |
129 | |
130 | /// Implements [`Display`] for [`RepositoryVisiblity`] using [`Debug`] |
131 | |
132 | |
133 | write! |
134 | |
135 | |
136 | |
137 | |
138 | |
139 | /// Name of the repository |
140 | /// |
141 | /// This is different than the [`Repository`] name, |
142 | /// which may be a path. |
143 | pub name: String, |
144 | /// Owner of the Repository |
145 | pub owner: User, |
146 | /// Repository description |
147 | pub description: , |
148 | /// Repository visibility |
149 | pub visibility: Visibility, |
150 | /// Default branch of the repository |
151 | pub default_branch: DefaultBranch, |
152 | /// Last commit made to the repository |
153 | pub latest_commit: , |
154 | /// Repository statistics |
155 | pub stats: RepositoryStatistics, |
156 | /// Revision of the displayed tree |
157 | pub tree_rev: , |
158 | /// Repository tree |
159 | pub tree: , |
160 | |
161 | |
162 | /// Generic repository statistics |
163 | |
164 | |
165 | /// Amount of commits made to this branch in the repository |
166 | pub commits: usize, |
167 | /// Amount of branches the repository has |
168 | pub branches: usize, |
169 | /// Amount of tags the repository has |
170 | pub tags: usize, |
171 | |
172 | |
173 | /// Repository branch |
174 | |
175 | |
176 | /// Full reference name |
177 | pub name: String, |
178 | /// Whether the repository is stale or not |
179 | pub stale: bool, |
180 | /// The last commit made to the branch |
181 | pub last_commit: , |
182 | |
183 | |
184 | |
185 | |
186 | /// ID of the file |
187 | pub id: String, |
188 | /// Content of the file |
189 | pub content: , |
190 | /// If the file is binary or not |
191 | pub binary: bool, |
192 | /// File size in bytes |
193 | pub size: usize, |
194 | |
195 | |
196 | |
197 | |
198 | /// "to" side of the diff commit |
199 | pub new_commit: Commit, |
200 | /// Total number of files changed |
201 | pub files_changed: usize, |
202 | /// Total number of insertions |
203 | pub insertions: usize, |
204 | /// Total number of deletions |
205 | pub deletions: usize, |
206 | /// List of changed files |
207 | pub files: , |
208 | |
209 | |
210 | /// Represents the type of change made to a [`RepositoryDiffFile`] |
211 | |
212 | |
213 | /// No changes |
214 | Unmodified, |
215 | Added, |
216 | Deleted, |
217 | /// Content changed between old and new |
218 | Modified, |
219 | /// Renamed between old and new |
220 | Renamed, |
221 | /// Copied from another old entry |
222 | Copied, |
223 | /// Ignored item in workdir |
224 | Ignored, |
225 | /// Untracked item in workdir |
226 | Untracked, |
227 | /// Type of file changed between old and new |
228 | Typechange, |
229 | /// File is unreadable |
230 | Unreadable, |
231 | /// File in the index is conflicted |
232 | Conflicted, |
233 | |
234 | |
235 | |
236 | |
237 | match status |
238 | => Self Unmodified, | Unmodified
239 | => Self Added, | Added
240 | => Self Deleted, | Deleted
241 | => Self Modified, | Modified
242 | => Self Renamed, | Renamed
243 | => Self Copied, | Copied
244 | => Self Ignored, | Ignored
245 | => Self Untracked, | Untracked
246 | => Self Typechange, | Typechange
247 | => Self Unreadable, | Unreadable
248 | => Self Conflicted, | Conflicted
249 | |
250 | |
251 | |
252 | |
253 | /// Represents a single file of a diff |
254 | |
255 | |
256 | /// The type of change made to this file |
257 | pub status: RepositoryDiffFileStatus, |
258 | /// "From" side of the diff, can be nonexistent if file for example got added for the first time |
259 | pub old_file_info: , |
260 | /// "To" side of the diff, can be nonexistent if file got removed |
261 | pub new_file_info: , |
262 | /// Individual chunks of changes in this file |
263 | pub chunks: , |
264 | |
265 | |
266 | /// Represents one side of a file diff [`RepositoryDiffFile`] |
267 | |
268 | |
269 | /// ID of the file |
270 | pub id: String, |
271 | /// Path of the entry relative to the working directory of the repository |
272 | pub path: String, |
273 | /// Size in bytes |
274 | pub size: u64, |
275 | /// If the file is binary or not |
276 | pub binary: bool, |
277 | |
278 | |
279 | /// Represents a single chunk of a file diff [`RepositoryDiffFile`] |
280 | |
281 | |
282 | /// Header of the chunk |
283 | pub header: , |
284 | /// Starting line number of the old file |
285 | pub old_start: u32, |
286 | /// Number of lines in "from" side of this chunk |
287 | pub old_lines: u32, |
288 | /// Starting line number of the new file |
289 | pub new_start: u32, |
290 | /// Number of lines in "to" side of this chunk |
291 | pub new_lines: u32, |
292 | /// Lines of the chunk |
293 | pub lines: , |
294 | |
295 | |
296 | /// Represents the change type of the [`RepositoryChunkLine`], incomplete of what git actually provides. |
297 | |
298 | |
299 | Context, |
300 | Addition, |
301 | Deletion, |
302 | |
303 | |
304 | |
305 | |
306 | match line_type |
307 | => Self Context, | Context
308 | => Self Addition, | Addition
309 | => Self Deletion, | Deletion
310 | _ => Self Context, |
311 | |
312 | |
313 | |
314 | |
315 | /// Represents a single line of a [`RepositoryDiffFileChunk`] |
316 | |
317 | |
318 | /// Type of change the line is |
319 | pub change_type: RepositoryChunkLineType, |
320 | /// Content of the line |
321 | pub content: String, |
322 | /// Line number in old file |
323 | pub old_line_num: , |
324 | /// Line number in new file |
325 | pub new_line_num: , |
326 | |
327 | |
328 | |
329 | |
330 | Tree, |
331 | Blob, |
332 | |
333 | |
334 | /// Stored info for our tree entries |
335 | |
336 | |
337 | /// ID of the tree/blob |
338 | pub id: String, |
339 | /// Name of the tree/blob |
340 | pub name: String, |
341 | /// Type of the tree entry |
342 | pub object_type: RepositoryObjectType, |
343 | /// Git supplies us with the mode at all times, and people like it displayed. |
344 | pub mode: i32, |
345 | /// File size |
346 | pub size: , |
347 | /// Last commit made to the tree/blob |
348 | pub last_commit: , |
349 | |
350 | |
351 | |
352 | // I love you Emilia <3 |
353 | |
354 | Self |
355 | id: id.to_string, |
356 | name: name.to_string, |
357 | object_type, |
358 | mode, |
359 | size: None, |
360 | last_commit: None, |
361 | |
362 | |
363 | |
364 | |
365 | |
366 | |
367 | pub tree_entry: RepositoryTreeEntry, |
368 | pub commit: Commit, |
369 | |
370 | |
371 | /// Info about a git commit |
372 | |
373 | |
374 | /// Unique commit ID |
375 | pub oid: String, |
376 | /// Shortened abbreviated OID |
377 | /// This starts at the git config's "core.abbrev" length (default 7 characters) and |
378 | /// iteratively extends to a longer string if that length is ambiguous. The |
379 | /// result will be unambiguous (at least until new objects are added to the repository). |
380 | pub short_oid: String, |
381 | /// First paragraph of the full message |
382 | pub summary: , |
383 | /// Everything in the full message apart from the first paragraph |
384 | pub body: , |
385 | /// All commit id's of the parents of this commit |
386 | pub parents: , |
387 | /// Who created the commit |
388 | pub author: CommitSignature, |
389 | /// Who committed the commit |
390 | pub committer: CommitSignature, |
391 | /// Time when the commit happened |
392 | pub time: NaiveDateTime, |
393 | |
394 | |
395 | /// Gets all info from [`git2::Commit`] for easy use |
396 | |
397 | |
398 | Self |
399 | oid: commit.id .to_string, |
400 | // This shouldn't ever fail, as we already know the object has an oid. |
401 | short_oid: commit |
402 | .as_object |
403 | .short_id |
404 | .unwrap |
405 | .as_str |
406 | .unwrap |
407 | .to_string, |
408 | summary: commit.summary .map, |
409 | body: commit.body .map, |
410 | parents: commit |
411 | .parents |
412 | .map |
413 | ., |
414 | author: commit.author .into, |
415 | committer: commit.committer .into, |
416 | time: from_timestamp_opt .unwrap, |
417 | |
418 | |
419 | |
420 | |
421 | /// Git commit signature |
422 | |
423 | |
424 | pub name: , |
425 | pub email: , |
426 | pub time: NaiveDateTime, |
427 | |
428 | |
429 | /// Converts the signature from git2 into something usable without explicit lifetimes. |
430 | |
431 | |
432 | Self |
433 | name: signature.name .map, |
434 | email: signature.email .map, |
435 | time: from_timestamp_opt .unwrap, |
436 | |
437 | |
438 | |
439 | |
440 | /// The document type of a [`Commit`]'s body |
441 | |
442 | |
443 | Plain, |
444 | Markdown, |
445 | |
446 | |
447 | |
448 | |
449 | Self Plain |
450 | |
451 | |
452 | |
453 | |
454 | |
455 | pub repository: Repository, |
456 | pub owner: User, |
457 | pub visibility: RepositoryVisibility, |
458 | pub description: , |
459 | pub last_commit: , |
460 | |
461 | |
462 | |
463 | |
464 | pub name: String, |
465 | pub color: String, |
466 | |
467 | |
468 | |
469 | |
470 | pub author: User, |
471 | pub id: u64, |
472 | pub title: String, |
473 | pub contents: String, |
474 | pub labels: , |
475 | |
476 |