Singular tag request
parent: tbd commit: d239950
1 | use Error; |
2 | use |
3 | , | Object
4 | |
5 | Commit, CommitSignature, Repository, RepositoryTag, RepositoryTagRequest, |
6 | RepositoryTagsRequest, |
7 | , |
8 | ; |
9 | use ; |
10 | |
11 | use ; |
12 | |
13 | |
14 | /// Converts a git2 tag into our own type, couldn't implement [`From`] or impl on [`RepositoryTag`] from here. |
15 | |
16 | id: String, |
17 | name: String, |
18 | tag: Tag, |
19 | |
20 | // Get the tag message and split it into a summary and body |
21 | let = if let Some = tag.message |
22 | parse_trim_git_message |
23 | else |
24 | |
25 | ; |
26 | |
27 | // Get the commit the tag is (possibly) pointing to |
28 | let commit = tag |
29 | .peel |
30 | .map |
31 | .ok |
32 | .flatten |
33 | .map; |
34 | // Get the author of the tag |
35 | let author: = tag.tagger .map; |
36 | // Get the time the tag or pointed commit was created |
37 | let time = if let Some = author |
38 | Some |
39 | else |
40 | // Get possible commit time if the tag has no author time |
41 | commit.as_ref .map |
42 | ; |
43 | |
44 | RepositoryTag |
45 | id: id.to_string, |
46 | name: name.to_string, |
47 | summary, |
48 | body, |
49 | author, |
50 | time, |
51 | commit, |
52 | |
53 | |
54 | |
55 | /// .0: List of tags in passed range |
56 | /// .1: Total amount of tags |
57 | pub async |
58 | &mut self, |
59 | requester: & , |
60 | repository_object: &mut , |
61 | OperationState | : ,
62 | request: &RepositoryTagsRequest, |
63 | |
64 | let repository = repository_object.object; |
65 | let git = self |
66 | .open_repository_and_check_permissions |
67 | .await?; |
68 | |
69 | let mut tags = vec!; |
70 | |
71 | // Iterate over each tag |
72 | let _ = git.tag_foreach |
73 | // Get the name in utf8 |
74 | let name = String from_utf8_lossy .replacen; |
75 | |
76 | // Find the tag so we can get the messages attached if any |
77 | if let Ok = git.find_tag |
78 | tags.push |
79 | id.to_string, |
80 | name, |
81 | tag, |
82 | ; |
83 | else |
84 | // Lightweight commit, we try and find the commit it's pointing to |
85 | let commit = git.find_commit .ok .map; |
86 | |
87 | tags.push |
88 | id: id.to_string, |
89 | name: name.to_string, |
90 | summary: None, |
91 | body: None, |
92 | author: None, |
93 | time: commit.as_ref .map, |
94 | commit, |
95 | ; |
96 | ; |
97 | |
98 | true |
99 | ; |
100 | |
101 | // Get the total amount of tags |
102 | let tag_count = tags.len; |
103 | |
104 | if let Some = &request.search |
105 | // TODO: Caching |
106 | // Search by sorting using a simple fuzzy search algorithm |
107 | tags.sort_by |
108 | damerau_levenshtein |
109 | .cmp |
110 | ; |
111 | else |
112 | // Sort the tags using their creation or pointer date |
113 | tags.sort_by; |
114 | |
115 | |
116 | // Get the requested range of tags |
117 | let tags = tags |
118 | .into_iter |
119 | .skip |
120 | .take |
121 | .; |
122 | |
123 | Ok |
124 | |
125 | |
126 | pub async |
127 | &mut self, |
128 | requester: & , |
129 | repository_object: &mut , |
130 | OperationState | : ,
131 | request: &RepositoryTagRequest, |
132 | |
133 | let repository = repository_object.object; |
134 | let git = self |
135 | .open_repository_and_check_permissions |
136 | .await?; |
137 | |
138 | // Get the tag id by parsing the ref |
139 | let full_ref_name = format!; |
140 | let tag_id = git |
141 | .refname_to_id |
142 | .map_err?; |
143 | |
144 | let tag = git.find_tag; |
145 | if let Ok = tag |
146 | // Convert the annotated tag into our own type |
147 | Ok |
148 | tag_id.to_string, |
149 | request.name.clone, |
150 | tag, |
151 | |
152 | else |
153 | // Lightweight tag, we try and find the commit it's pointing to |
154 | let commit = git.find_commit .ok .map; |
155 | |
156 | Ok |
157 | id: tag_id.to_string, |
158 | name: request.name.clone, |
159 | summary: None, |
160 | body: None, |
161 | author: None, |
162 | time: commit.as_ref .map, |
163 | commit, |
164 | |
165 | |
166 | |
167 | |
168 |