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

ambee/giterated

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

Fixes

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨b87f0a3

⁨giterated-models/src/repository/operations.rs⁩ - ⁨3994⁩ 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, RepositoryView};
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 RepositoryInfoRequest;
23
24 impl GiteratedOperation<Repository> for RepositoryInfoRequest {
25 type Success = RepositoryView;
26 type Failure = RepositoryError;
27 }
28
29 #[derive(Clone, Debug, Serialize, Deserialize)]
30 pub struct RepositoryIssuesCountRequest;
31
32 impl GiteratedOperation<Repository> for RepositoryIssuesCountRequest {
33 type Success = u64;
34 type Failure = RepositoryError;
35 }
36
37 /// A request to get a repository's issues count.
38 ///
39 /// # Authentication
40 /// - Instance Authentication
41 /// - Validate request against the `issued_for` public key
42 /// - Validate User token against the user's instance's public key
43 /// # Authorization
44 /// - User Authorization
45 /// - Potential User permissions checks
46 #[derive(Clone, Debug, Serialize, Deserialize)]
47 pub struct RepositoryIssueLabelsRequest;
48
49 impl GiteratedOperation<Repository> for RepositoryIssueLabelsRequest {
50 type Success = Vec<IssueLabel>;
51 type Failure = RepositoryError;
52 }
53
54 /// A request to get a repository's issue labels.
55 ///
56 /// # Authentication
57 /// - Instance Authentication
58 /// - Validate request against the `issued_for` public key
59 /// - Validate User token against the user's instance's public key
60 /// # Authorization
61 /// - User Authorization
62 /// - Potential User permissions checks
63 #[derive(Clone, Debug, Serialize, Deserialize)]
64 pub struct RepositoryIssuesRequest;
65
66 impl GiteratedOperation<Repository> for RepositoryIssuesRequest {
67 type Success = Vec<RepositoryIssue>;
68 type Failure = RepositoryError;
69 }
70
71 /// A request to inspect the tree of a repository.
72 ///
73 /// # Authentication
74 /// - Instance Authentication
75 /// - Validate request against the `issued_for` public key
76 /// - Validate User token against the user's instance's public key
77 /// # Authorization
78 /// - User Authorization
79 /// - Potential User permissions checks
80 #[derive(Clone, Debug, Serialize, Deserialize)]
81 pub struct RepositoryFileInspectRequest {
82 pub path: RepositoryTreeEntry,
83 }
84
85 impl GiteratedOperation<Repository> for RepositoryFileInspectRequest {
86 type Success = Vec<RepositoryTreeEntry>;
87 type Failure = RepositoryError;
88 }
89
90 impl<B: ObjectBackend + std::fmt::Debug> Object<'_, Repository, B> {
91 pub async fn info(&mut self) -> Result<RepositoryView, OperationError<RepositoryError>> {
92 self.request::<RepositoryInfoRequest>(RepositoryInfoRequest)
93 .await
94 }
95 // pub async fn issues_count(&mut self) -> Result<u64, OperationError<RepositoryError>> {
96 // self.request::<RepositoryIssuesCountRequest>(RepositoryIssuesCountRequest)
97 // .await
98 // }
99
100 pub async fn issue_labels(
101 &mut self,
102 ) -> Result<Vec<IssueLabel>, OperationError<RepositoryError>> {
103 self.request::<RepositoryIssueLabelsRequest>(RepositoryIssueLabelsRequest)
104 .await
105 }
106
107 pub async fn issues(
108 &mut self,
109 ) -> Result<Vec<RepositoryIssue>, OperationError<RepositoryError>> {
110 self.request::<RepositoryIssuesRequest>(RepositoryIssuesRequest)
111 .await
112 }
113
114 pub async fn inspect_files(
115 &mut self,
116 entry: &RepositoryTreeEntry,
117 ) -> Result<Vec<RepositoryTreeEntry>, OperationError<RepositoryError>> {
118 self.request::<RepositoryFileInspectRequest>(RepositoryFileInspectRequest {
119 path: entry.clone(),
120 })
121 .await
122 }
123 }
124