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

ambee/giterated

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

Begin new protocol refactor

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨26651b1

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