JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Fixed imports!

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨ef0e853

⁨giterated-models/src/repository/operations.rs⁩ - ⁨3557⁩ bytes
Raw
1 use serde::{Deserialize, Serialize};
2
3 use crate::{
4 error::{OperationError, RepositoryError},
5 object::Object,
6 object_backend::ObjectBackend,
7 operation::GiteratedOperation,
8 };
9
10 use super::{IssueLabel, Repository, RepositoryIssue, RepositoryTreeEntry};
11
12 /// A request to get a repository's information.
13 ///
14 /// # Authentication
15 /// - Instance Authentication
16 /// - Validate request against the `issued_for` public key
17 /// - Validate User token against the user's instance's public key
18 /// # Authorization
19 /// - User Authorization
20 /// - Potential User permissions checks
21 #[derive(Clone, Debug, Serialize, Deserialize)]
22 pub struct RepositoryIssuesCountRequest;
23
24 impl GiteratedOperation<Repository> for RepositoryIssuesCountRequest {
25 type Success = u64;
26 type Failure = RepositoryError;
27 }
28
29 /// A request to get a repository's issues count.
30 ///
31 /// # Authentication
32 /// - Instance Authentication
33 /// - Validate request against the `issued_for` public key
34 /// - Validate User token against the user's instance's public key
35 /// # Authorization
36 /// - User Authorization
37 /// - Potential User permissions checks
38 #[derive(Clone, Debug, Serialize, Deserialize)]
39 pub struct RepositoryIssueLabelsRequest;
40
41 impl GiteratedOperation<Repository> for RepositoryIssueLabelsRequest {
42 type Success = Vec<IssueLabel>;
43 type Failure = RepositoryError;
44 }
45
46 /// A request to get a repository's issue labels.
47 ///
48 /// # Authentication
49 /// - Instance Authentication
50 /// - Validate request against the `issued_for` public key
51 /// - Validate User token against the user's instance's public key
52 /// # Authorization
53 /// - User Authorization
54 /// - Potential User permissions checks
55 #[derive(Clone, Debug, Serialize, Deserialize)]
56 pub struct RepositoryIssuesRequest;
57
58 impl GiteratedOperation<Repository> for RepositoryIssuesRequest {
59 type Success = Vec<RepositoryIssue>;
60 type Failure = RepositoryError;
61 }
62
63 /// A request to inspect the tree of a repository.
64 ///
65 /// # Authentication
66 /// - Instance Authentication
67 /// - Validate request against the `issued_for` public key
68 /// - Validate User token against the user's instance's public key
69 /// # Authorization
70 /// - User Authorization
71 /// - Potential User permissions checks
72 #[derive(Clone, Debug, Serialize, Deserialize)]
73 pub struct RepositoryFileInspectRequest {
74 pub path: RepositoryTreeEntry,
75 }
76
77 impl GiteratedOperation<Repository> for RepositoryFileInspectRequest {
78 type Success = Vec<RepositoryTreeEntry>;
79 type Failure = RepositoryError;
80 }
81
82 impl<B: ObjectBackend + std::fmt::Debug> Object<'_, Repository, B> {
83 pub async fn issues_count(&mut self) -> Result<u64, OperationError<RepositoryError>> {
84 self.request::<RepositoryIssuesCountRequest>(RepositoryIssuesCountRequest)
85 .await
86 }
87
88 pub async fn issue_labels(
89 &mut self,
90 ) -> Result<Vec<IssueLabel>, OperationError<RepositoryError>> {
91 self.request::<RepositoryIssueLabelsRequest>(RepositoryIssueLabelsRequest)
92 .await
93 }
94
95 pub async fn issues(
96 &mut self,
97 ) -> Result<Vec<RepositoryIssue>, OperationError<RepositoryError>> {
98 self.request::<RepositoryIssuesRequest>(RepositoryIssuesRequest)
99 .await
100 }
101
102 pub async fn inspect_files(
103 &mut self,
104 entry: &RepositoryTreeEntry,
105 ) -> Result<Vec<RepositoryTreeEntry>, OperationError<RepositoryError>> {
106 self.request::<RepositoryFileInspectRequest>(RepositoryFileInspectRequest {
107 path: entry.clone(),
108 })
109 .await
110 }
111 }
112