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

ambee/giterated

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

Add parameters to RepositoryInfoRequest and derive Clone on setting types

Type: Feature

erremilia - ⁨2⁩ years ago

parent: tbd commit: ⁨fcde8d4

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