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

ambee/giterated

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

Experimental repository diff structure

erremilia - ⁨2⁩ years ago

parent: tbd commit: ⁨0ef533d

⁨giterated-models/src/repository/operations.rs⁩ - ⁨8795⁩ 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::{
11 Commit, IssueLabel, Repository, RepositoryDiff, RepositoryFile, RepositoryIssue,
12 RepositoryTreeEntry, RepositoryView,
13 };
14
15 /// A request to get a repository's information.
16 ///
17 /// # Authentication
18 /// - Instance Authentication
19 /// - Validate request against the `issued_for` public key
20 /// - Validate User token against the user's instance's public key
21 /// # Authorization
22 /// - User Authorization
23 /// - Potential User permissions checks
24 #[derive(Clone, Debug, Serialize, Deserialize)]
25 pub struct RepositoryInfoRequest {
26 pub extra_metadata: bool,
27 pub rev: Option<String>,
28 pub path: Option<String>,
29 }
30
31 impl GiteratedOperation<Repository> for RepositoryInfoRequest {
32 type Success = RepositoryView;
33 type Failure = RepositoryError;
34 }
35
36 /// A request to get a file from a repository using the given id.
37 ///
38 /// # Authentication
39 /// - Instance Authentication
40 /// - Validate request against the `issued_for` public key
41 /// - Validate User token against the user's instance's public key
42 /// # Authorization
43 /// - User Authorization
44 /// - Potential User permissions checks
45 #[derive(Clone, Debug, Serialize, Deserialize)]
46 pub struct RepositoryFileFromIdRequest(pub String);
47
48 impl GiteratedOperation<Repository> for RepositoryFileFromIdRequest {
49 type Success = RepositoryFile;
50 type Failure = RepositoryError;
51 }
52
53 /// A request to get the difference between two repository trees.
54 ///
55 /// # Authentication
56 /// - Instance Authentication
57 /// - Validate request against the `issued_for` public key
58 /// - Validate User token against the user's instance's public key
59 /// # Authorization
60 /// - User Authorization
61 /// - Potential User permissions checks
62 #[derive(Clone, Debug, Serialize, Deserialize)]
63 pub struct RepositoryDiffRequest {
64 pub old_id: String,
65 pub new_id: String,
66 }
67
68 impl GiteratedOperation<Repository> for RepositoryDiffRequest {
69 type Success = RepositoryDiff;
70 type Failure = RepositoryError;
71 }
72
73 /// A request to get the difference between two repository trees as a unified git patch.
74 ///
75 /// # Authentication
76 /// - Instance Authentication
77 /// - Validate request against the `issued_for` public key
78 /// - Validate User token against the user's instance's public key
79 /// # Authorization
80 /// - User Authorization
81 /// - Potential User permissions checks
82 #[derive(Clone, Debug, Serialize, Deserialize)]
83 pub struct RepositoryDiffPatchRequest {
84 pub old_id: String,
85 pub new_id: String,
86 }
87
88 impl GiteratedOperation<Repository> for RepositoryDiffPatchRequest {
89 type Success = String;
90 type Failure = RepositoryError;
91 }
92
93 /// A request to get the commit before the one with the passed id
94 ///
95 /// # Authentication
96 /// - Instance Authentication
97 /// - Validate request against the `issued_for` public key
98 /// - Validate User token against the user's instance's public key
99 /// # Authorization
100 /// - User Authorization
101 /// - Potential User permissions checks
102 #[derive(Clone, Debug, Serialize, Deserialize)]
103 pub struct RepositoryCommitBeforeRequest(pub String);
104
105 impl GiteratedOperation<Repository> for RepositoryCommitBeforeRequest {
106 type Success = Commit;
107 type Failure = RepositoryError;
108 }
109
110 #[derive(Clone, Debug, Serialize, Deserialize)]
111 pub struct RepositoryIssuesCountRequest;
112
113 impl GiteratedOperation<Repository> for RepositoryIssuesCountRequest {
114 type Success = u64;
115 type Failure = RepositoryError;
116 }
117
118 /// A request to get a repository's issues count.
119 ///
120 /// # Authentication
121 /// - Instance Authentication
122 /// - Validate request against the `issued_for` public key
123 /// - Validate User token against the user's instance's public key
124 /// # Authorization
125 /// - User Authorization
126 /// - Potential User permissions checks
127 #[derive(Clone, Debug, Serialize, Deserialize)]
128 pub struct RepositoryIssueLabelsRequest;
129
130 impl GiteratedOperation<Repository> for RepositoryIssueLabelsRequest {
131 type Success = Vec<IssueLabel>;
132 type Failure = RepositoryError;
133 }
134
135 /// A request to get a repository's issue labels.
136 ///
137 /// # Authentication
138 /// - Instance Authentication
139 /// - Validate request against the `issued_for` public key
140 /// - Validate User token against the user's instance's public key
141 /// # Authorization
142 /// - User Authorization
143 /// - Potential User permissions checks
144 #[derive(Clone, Debug, Serialize, Deserialize)]
145 pub struct RepositoryIssuesRequest;
146
147 impl GiteratedOperation<Repository> for RepositoryIssuesRequest {
148 type Success = Vec<RepositoryIssue>;
149 type Failure = RepositoryError;
150 }
151
152 /// A request to inspect the tree of a repository.
153 ///
154 /// # Authentication
155 /// - Instance Authentication
156 /// - Validate request against the `issued_for` public key
157 /// - Validate User token against the user's instance's public key
158 /// # Authorization
159 /// - User Authorization
160 /// - Potential User permissions checks
161 #[derive(Clone, Debug, Serialize, Deserialize)]
162 pub struct RepositoryFileInspectRequest {
163 /// Whether to get extra metadata for every entry (file mode, size and last commit made to it).
164 pub extra_metadata: bool,
165 /// Revision of the repository to get (branch, commit id).
166 pub rev: Option<String>,
167 /// If not given a path, it'll default to the base.
168 pub path: Option<String>,
169 }
170
171 impl GiteratedOperation<Repository> for RepositoryFileInspectRequest {
172 type Success = Vec<RepositoryTreeEntry>;
173 type Failure = RepositoryError;
174 }
175
176 impl<S: Clone + Send + Sync, B: ObjectBackend<S> + std::fmt::Debug> Object<'_, S, Repository, B> {
177 pub async fn info(
178 &mut self,
179 extra_metadata: bool,
180 rev: Option<String>,
181 path: Option<String>,
182 operation_state: &S,
183 ) -> Result<RepositoryView, OperationError<RepositoryError>> {
184 self.request::<RepositoryInfoRequest>(
185 RepositoryInfoRequest {
186 extra_metadata,
187 rev,
188 path,
189 },
190 operation_state,
191 )
192 .await
193 }
194
195 pub async fn file_from_id(
196 &mut self,
197 id: String,
198 operation_state: &S,
199 ) -> Result<RepositoryFile, OperationError<RepositoryError>> {
200 self.request::<RepositoryFileFromIdRequest>(
201 RepositoryFileFromIdRequest(id),
202 operation_state,
203 )
204 .await
205 }
206
207 pub async fn diff(
208 &mut self,
209 old_id: String,
210 new_id: String,
211 operation_state: &S,
212 ) -> Result<RepositoryDiff, OperationError<RepositoryError>> {
213 self.request::<RepositoryDiffRequest>(
214 RepositoryDiffRequest { old_id, new_id },
215 operation_state,
216 )
217 .await
218 }
219
220 pub async fn diff_patch(
221 &mut self,
222 old_id: String,
223 new_id: String,
224 operation_state: &S,
225 ) -> Result<String, OperationError<RepositoryError>> {
226 self.request::<RepositoryDiffPatchRequest>(
227 RepositoryDiffPatchRequest { old_id, new_id },
228 operation_state,
229 )
230 .await
231 }
232
233 pub async fn commit_before(
234 &mut self,
235 id: String,
236 operation_state: &S,
237 ) -> Result<Commit, OperationError<RepositoryError>> {
238 self.request::<RepositoryCommitBeforeRequest>(
239 RepositoryCommitBeforeRequest(id),
240 operation_state,
241 )
242 .await
243 }
244
245 // pub async fn issues_count(&mut self) -> Result<u64, OperationError<RepositoryError>> {
246 // self.request::<RepositoryIssuesCountRequest>(RepositoryIssuesCountRequest)
247 // .await
248 // }
249
250 pub async fn issue_labels(
251 &mut self,
252 operation_state: &S,
253 ) -> Result<Vec<IssueLabel>, OperationError<RepositoryError>> {
254 self.request::<RepositoryIssueLabelsRequest>(RepositoryIssueLabelsRequest, operation_state)
255 .await
256 }
257
258 pub async fn issues(
259 &mut self,
260 operation_state: &S,
261 ) -> Result<Vec<RepositoryIssue>, OperationError<RepositoryError>> {
262 self.request::<RepositoryIssuesRequest>(RepositoryIssuesRequest, operation_state)
263 .await
264 }
265
266 pub async fn inspect_files(
267 &mut self,
268 extra_metadata: bool,
269 rev: Option<&str>,
270 path: Option<&str>,
271 operation_state: &S,
272 ) -> Result<Vec<RepositoryTreeEntry>, OperationError<RepositoryError>> {
273 self.request::<RepositoryFileInspectRequest>(
274 RepositoryFileInspectRequest {
275 extra_metadata,
276 rev: rev.map(|r| r.to_string()),
277 path: path.map(|p| p.to_string()),
278 },
279 operation_state,
280 )
281 .await
282 }
283 }
284