Improve oid_from_reference tag id fetching and pass full Repository Object to every function
parent: tbd commit: 6d7e35e
1 | use |
2 | , | UserAuthenticationToken
3 | , |
4 | |
5 | AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest, |
6 | , |
7 | , | ObjectBackend
8 | |
9 | Commit, DefaultBranch, Description, LatestCommit, Repository, RepositoryBranch, |
10 | RepositoryBranchRequest, RepositoryBranchesRequest, RepositoryCommitBeforeRequest, |
11 | RepositoryCommitFromIdRequest, RepositoryDiff, RepositoryDiffPatchRequest, |
12 | RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, |
13 | RepositoryFileFromPathRequest, RepositoryFileInspectRequest, RepositoryInfoRequest, |
14 | RepositoryLastCommitOfFileRequest, RepositoryStatistics, RepositoryStatisticsRequest, |
15 | RepositorySummary, RepositoryTag, RepositoryTagsRequest, RepositoryView, Visibility, |
16 | , |
17 | , |
18 | ; |
19 | use ; |
20 | |
21 | use DatabaseBackend; |
22 | |
23 | pub async |
24 | object: User, |
25 | _operation: UserRepositoriesRequest, |
26 | state: DatabaseBackend, |
27 | OperationState | : ,
28 | requester: , |
29 | |
30 | let object = object.clone; |
31 | |
32 | let mut user_backend = state.user_backend.lock .await; |
33 | let repositories_response = user_backend |
34 | .repositories_for_user |
35 | .await |
36 | .as_internal_error?; |
37 | drop; |
38 | let mut repositories_backend = state.repository_backend.lock .await; |
39 | |
40 | let mut repositories = vec!; |
41 | |
42 | for repository in repositories_response |
43 | if repositories_backend |
44 | .exists |
45 | .await |
46 | .as_internal_error? |
47 | |
48 | repositories.push; |
49 | |
50 | |
51 | |
52 | Ok |
53 | |
54 | |
55 | pub async |
56 | object: Repository, |
57 | operation: RepositoryInfoRequest, |
58 | state: DatabaseBackend, |
59 | OperationState | : ,
60 | backend: GiteratedStack, |
61 | requester: , |
62 | |
63 | info!; |
64 | let mut object = backend |
65 | . |
66 | .await |
67 | .unwrap; |
68 | let mut repository_backend = state.repository_backend.lock .await; |
69 | let tree = repository_backend |
70 | .repository_file_inspect |
71 | &requester, |
72 | &mut object, |
73 | OperationState, |
74 | &RepositoryFileInspectRequest |
75 | extra_metadata: operation.extra_metadata, |
76 | path: operation.path.clone, |
77 | rev: operation.rev.clone, |
78 | , |
79 | |
80 | .await |
81 | .as_internal_error?; |
82 | |
83 | let statistics = repository_backend |
84 | .repository_get_statistics |
85 | &requester, |
86 | &mut object, |
87 | OperationState, |
88 | &RepositoryStatisticsRequest |
89 | rev: operation.rev.clone, |
90 | , |
91 | |
92 | .await |
93 | .as_internal_error?; |
94 | drop; |
95 | |
96 | let info = RepositoryView |
97 | name: object.object .name.clone, |
98 | owner: object.object .owner.clone, |
99 | description: object. .await.ok, |
100 | visibility: object |
101 | . |
102 | .await |
103 | .as_internal_error?, |
104 | default_branch: object |
105 | . |
106 | .await |
107 | .as_internal_error?, |
108 | // TODO: Can't be a simple get function, this needs to be returned alongside the tree as this differs depending on the rev and path. |
109 | latest_commit: object. .await.ok, |
110 | stats: statistics, |
111 | tree_rev: operation.rev.clone, |
112 | tree, |
113 | ; |
114 | |
115 | Ok |
116 | |
117 | |
118 | pub async |
119 | object: Repository, |
120 | operation: RepositoryStatisticsRequest, |
121 | state: DatabaseBackend, |
122 | OperationState | : ,
123 | backend: GiteratedStack, |
124 | requester: , |
125 | |
126 | let mut object = backend |
127 | . |
128 | .await |
129 | .unwrap; |
130 | |
131 | let mut repository_backend = state.repository_backend.lock .await; |
132 | let statistics = repository_backend |
133 | .repository_get_statistics |
134 | &requester, |
135 | &mut object, |
136 | OperationState, |
137 | &RepositoryStatisticsRequest |
138 | rev: operation.rev.clone, |
139 | , |
140 | |
141 | .await |
142 | .as_internal_error?; |
143 | drop; |
144 | |
145 | Ok |
146 | |
147 | |
148 | pub async |
149 | object: Repository, |
150 | operation: RepositoryBranchesRequest, |
151 | state: DatabaseBackend, |
152 | OperationState | : ,
153 | backend: GiteratedStack, |
154 | requester: , |
155 | |
156 | let mut object = backend |
157 | . |
158 | .await |
159 | .unwrap; |
160 | |
161 | let mut repository_backend = state.repository_backend.lock .await; |
162 | let branches = repository_backend |
163 | .repository_get_branches |
164 | &requester, |
165 | &mut object, |
166 | OperationState, |
167 | &operation, |
168 | |
169 | .await |
170 | .as_internal_error?; |
171 | drop; |
172 | |
173 | Ok |
174 | |
175 | |
176 | pub async |
177 | object: Repository, |
178 | operation: RepositoryBranchRequest, |
179 | state: DatabaseBackend, |
180 | OperationState | : ,
181 | backend: GiteratedStack, |
182 | requester: , |
183 | |
184 | let mut object = backend |
185 | . |
186 | .await |
187 | .unwrap; |
188 | |
189 | let mut repository_backend = state.repository_backend.lock .await; |
190 | let branch = repository_backend |
191 | .repository_get_branch |
192 | &requester, |
193 | &mut object, |
194 | OperationState, |
195 | &operation, |
196 | |
197 | .await |
198 | .as_internal_error?; |
199 | drop; |
200 | |
201 | Ok |
202 | |
203 | |
204 | pub async |
205 | object: Repository, |
206 | operation: RepositoryTagsRequest, |
207 | state: DatabaseBackend, |
208 | OperationState | : ,
209 | backend: GiteratedStack, |
210 | requester: , |
211 | |
212 | let mut object = backend |
213 | . |
214 | .await |
215 | .unwrap; |
216 | |
217 | let mut repository_backend = state.repository_backend.lock .await; |
218 | let branches = repository_backend |
219 | .repository_get_tags |
220 | &requester, |
221 | &mut object, |
222 | OperationState, |
223 | &operation, |
224 | |
225 | .await |
226 | .as_internal_error?; |
227 | drop; |
228 | |
229 | Ok |
230 | |
231 | |
232 | pub async |
233 | object: Repository, |
234 | operation: RepositoryFileFromIdRequest, |
235 | state: DatabaseBackend, |
236 | OperationState | : ,
237 | backend: GiteratedStack, |
238 | requester: , |
239 | |
240 | let mut object = backend |
241 | . |
242 | .await |
243 | .unwrap; |
244 | |
245 | let mut repository_backend = state.repository_backend.lock .await; |
246 | let file = repository_backend |
247 | .repository_file_from_id |
248 | &requester, |
249 | &mut object, |
250 | OperationState, |
251 | &RepositoryFileFromIdRequest, |
252 | |
253 | .await |
254 | .as_internal_error?; |
255 | drop; |
256 | |
257 | Ok |
258 | |
259 | |
260 | pub async |
261 | object: Repository, |
262 | operation: RepositoryFileFromPathRequest, |
263 | state: DatabaseBackend, |
264 | OperationState | : ,
265 | backend: GiteratedStack, |
266 | requester: , |
267 | |
268 | let mut object = backend |
269 | . |
270 | .await |
271 | .unwrap; |
272 | |
273 | let mut repository_backend = state.repository_backend.lock .await; |
274 | let file = repository_backend |
275 | .repository_file_from_path |
276 | &requester, |
277 | &mut object, |
278 | OperationState, |
279 | &RepositoryFileFromPathRequest |
280 | rev: operation.rev.clone, |
281 | path: operation.path.clone, |
282 | , |
283 | |
284 | .await |
285 | .as_internal_error?; |
286 | drop; |
287 | |
288 | Ok |
289 | |
290 | |
291 | pub async |
292 | object: Repository, |
293 | operation: RepositoryLastCommitOfFileRequest, |
294 | state: DatabaseBackend, |
295 | OperationState | : ,
296 | backend: GiteratedStack, |
297 | requester: , |
298 | |
299 | let mut object = backend |
300 | . |
301 | .await |
302 | .unwrap; |
303 | |
304 | let mut repository_backend = state.repository_backend.lock .await; |
305 | let commit = repository_backend |
306 | .repository_last_commit_of_file |
307 | &requester, |
308 | &mut object, |
309 | OperationState, |
310 | &RepositoryLastCommitOfFileRequest |
311 | start_commit: operation.start_commit.clone, |
312 | path: operation.path.clone, |
313 | , |
314 | |
315 | .await |
316 | .as_internal_error?; |
317 | drop; |
318 | |
319 | Ok |
320 | |
321 | |
322 | pub async |
323 | object: Repository, |
324 | operation: RepositoryCommitFromIdRequest, |
325 | state: DatabaseBackend, |
326 | OperationState | : ,
327 | backend: GiteratedStack, |
328 | requester: , |
329 | |
330 | let mut object = backend |
331 | . |
332 | .await |
333 | .unwrap; |
334 | |
335 | let mut repository_backend = state.repository_backend.lock .await; |
336 | let commit = repository_backend |
337 | .repository_commit_from_id |
338 | &requester, |
339 | &mut object, |
340 | OperationState, |
341 | &RepositoryCommitFromIdRequest, |
342 | |
343 | .await |
344 | .as_internal_error?; |
345 | drop; |
346 | |
347 | Ok |
348 | |
349 | |
350 | pub async |
351 | object: Repository, |
352 | operation: RepositoryDiffRequest, |
353 | state: DatabaseBackend, |
354 | OperationState | : ,
355 | backend: GiteratedStack, |
356 | requester: , |
357 | |
358 | let mut object = backend |
359 | . |
360 | .await |
361 | .unwrap; |
362 | |
363 | let mut repository_backend = state.repository_backend.lock .await; |
364 | let diff = repository_backend |
365 | .repository_diff |
366 | &requester, |
367 | &mut object, |
368 | OperationState, |
369 | &operation, |
370 | |
371 | .await |
372 | .as_internal_error?; |
373 | drop; |
374 | |
375 | Ok |
376 | |
377 | |
378 | pub async |
379 | object: Repository, |
380 | operation: RepositoryDiffPatchRequest, |
381 | state: DatabaseBackend, |
382 | OperationState | : ,
383 | backend: GiteratedStack, |
384 | requester: , |
385 | |
386 | let mut object = backend |
387 | . |
388 | .await |
389 | .unwrap; |
390 | |
391 | let mut repository_backend = state.repository_backend.lock .await; |
392 | let patch = repository_backend |
393 | .repository_diff_patch |
394 | &requester, |
395 | &mut object, |
396 | OperationState, |
397 | &operation, |
398 | |
399 | .await |
400 | .as_internal_error?; |
401 | drop; |
402 | |
403 | Ok |
404 | |
405 | |
406 | pub async |
407 | object: Repository, |
408 | operation: RepositoryCommitBeforeRequest, |
409 | state: DatabaseBackend, |
410 | OperationState | : ,
411 | backend: GiteratedStack, |
412 | requester: , |
413 | |
414 | let mut object = backend |
415 | . |
416 | .await |
417 | .unwrap; |
418 | |
419 | let mut repository_backend = state.repository_backend.lock .await; |
420 | let file = repository_backend |
421 | .repository_commit_before |
422 | &requester, |
423 | &mut object, |
424 | OperationState, |
425 | &operation, |
426 | |
427 | .await |
428 | .as_internal_error?; |
429 | drop; |
430 | |
431 | Ok |
432 | |
433 | |
434 | pub async |
435 | object: Instance, |
436 | operation: AuthenticationTokenRequest, |
437 | state: DatabaseBackend, |
438 | OperationState | : ,
439 | // Authorizes the request for SAME-INSTANCE |
440 | // _authorized_instance: AuthorizedInstance, |
441 | |
442 | let mut backend = state.user_backend.lock .await; |
443 | |
444 | backend |
445 | .login |
446 | .await |
447 | .as_internal_error |
448 | |
449 | |
450 | pub async |
451 | _object: Instance, |
452 | operation: RegisterAccountRequest, |
453 | state: DatabaseBackend, |
454 | OperationState// Authorizes the request for SAME-INSTANCE | : ,
455 | // _authorized_instance: AuthorizedInstance, |
456 | |
457 | let mut backend = state.user_backend.lock .await; |
458 | |
459 | backend |
460 | .register |
461 | .await |
462 | .as_internal_error |
463 | |
464 | |
465 | pub async |
466 | _object: Instance, |
467 | operation: RepositoryCreateRequest, |
468 | state: DatabaseBackend, |
469 | OperationState | : ,
470 | requester: AuthenticatedUser, |
471 | // Authorizes the request for SAME-INSTANCE |
472 | // _authorized_instance: AuthorizedInstance, |
473 | |
474 | let mut backend = state.repository_backend.lock .await; |
475 | |
476 | backend |
477 | .create_repository |
478 | .await |
479 | .as_internal_error |
480 | |
481 | |
482 | pub async |
483 | _repository: Repository, |
484 | _state: DatabaseBackend, |
485 | OperationState | : ,
486 | |
487 | Ok |
488 | |
489 |