Move towards having GitBackend split into files
parent: tbd commit: e55da0e
1 | use Error; |
2 | use |
3 | , | Object
4 | , |
5 | ; |
6 | use ; |
7 | |
8 | use GitBackend; |
9 | |
10 | |
11 | /// .0: List of tags in passed range |
12 | /// .1: Total amount of tags |
13 | pub async |
14 | &mut self, |
15 | requester: & , |
16 | repository_object: &mut , |
17 | OperationState | : ,
18 | request: &RepositoryTagsRequest, |
19 | |
20 | let repository = repository_object.object; |
21 | let git = self |
22 | .open_repository_and_check_permissions |
23 | .await?; |
24 | |
25 | let mut tags = vec!; |
26 | |
27 | // Iterate over each tag |
28 | let _ = git.tag_foreach |
29 | // Get the name in utf8 |
30 | let name = String from_utf8_lossy .replacen; |
31 | |
32 | // Find the tag so we can get the messages attached if any |
33 | if let Ok = git.find_tag |
34 | // Get the tag message and split it into a summary and body |
35 | let = if let Some = tag.message |
36 | // Iterate over the lines |
37 | let mut lines = message |
38 | .lines |
39 | .map |
40 | // Trim the whitespace for every line |
41 | let mut whitespace_removed = String with_capacity; |
42 | |
43 | line.split_whitespace .for_each |
44 | if !whitespace_removed.is_empty |
45 | whitespace_removed.push; |
46 | |
47 | |
48 | whitespace_removed.push_str; |
49 | ; |
50 | |
51 | whitespace_removed |
52 | |
53 | .; |
54 | |
55 | let summary = Some; |
56 | let body = if lines.is_empty |
57 | None |
58 | else |
59 | Some |
60 | ; |
61 | |
62 | |
63 | else |
64 | |
65 | ; |
66 | |
67 | // Get the commit the tag is (possibly) pointing to |
68 | let commit = tag |
69 | .peel |
70 | .map |
71 | .ok |
72 | .flatten |
73 | .map; |
74 | // Get the author of the tag |
75 | let author: = tag.tagger .map; |
76 | // Get the time the tag or pointed commit was created |
77 | let time = if let Some = author |
78 | Some |
79 | else |
80 | // Get possible commit time if the tag has no author time |
81 | commit.as_ref .map |
82 | ; |
83 | |
84 | tags.push |
85 | id: id.to_string, |
86 | name: name.to_string, |
87 | summary, |
88 | body, |
89 | author, |
90 | time, |
91 | commit, |
92 | ; |
93 | else |
94 | // Lightweight commit, we try and find the commit it's pointing to |
95 | let commit = git.find_commit .ok .map; |
96 | |
97 | tags.push |
98 | id: id.to_string, |
99 | name: name.to_string, |
100 | summary: None, |
101 | body: None, |
102 | author: None, |
103 | time: commit.as_ref .map, |
104 | commit, |
105 | ; |
106 | ; |
107 | |
108 | true |
109 | ; |
110 | |
111 | // Get the total amount of tags |
112 | let tag_count = tags.len; |
113 | |
114 | if let Some = &request.search |
115 | // TODO: Caching |
116 | // Search by sorting using a simple fuzzy search algorithm |
117 | tags.sort_by |
118 | damerau_levenshtein |
119 | .cmp |
120 | ; |
121 | else |
122 | // Sort the tags using their creation or pointer date |
123 | tags.sort_by; |
124 | |
125 | |
126 | // Get the requested range of tags |
127 | let tags = tags |
128 | .into_iter |
129 | .skip |
130 | .take |
131 | .; |
132 | |
133 | Ok |
134 | |
135 | |
136 |