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

ambee/giterated

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

test

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨4c7437a

⁨giterated-models/src/repository/operations.rs⁩ - ⁨4302⁩ 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, Commit};
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 rev: Option<String>,
87 pub path: String,
88 }
89
90 impl GiteratedOperation<Repository> for RepositoryFileInspectRequest {
91 type Success = Vec<RepositoryTreeEntry>;
92 type Failure = RepositoryError;
93 }
94
95 impl<B: ObjectBackend + std::fmt::Debug> Object<'_, Repository, B> {
96 pub async fn info(&mut self, extra_metadata: bool, rev: Option<String>, path: Option<String>) -> Result<RepositoryView, OperationError<RepositoryError>> {
97 self.request::<RepositoryInfoRequest>(RepositoryInfoRequest {
98 extra_metadata,
99 rev,
100 path,
101 })
102 .await
103 }
104 // pub async fn issues_count(&mut self) -> Result<u64, OperationError<RepositoryError>> {
105 // self.request::<RepositoryIssuesCountRequest>(RepositoryIssuesCountRequest)
106 // .await
107 // }
108
109 pub async fn issue_labels(
110 &mut self,
111 ) -> Result<Vec<IssueLabel>, OperationError<RepositoryError>> {
112 self.request::<RepositoryIssueLabelsRequest>(RepositoryIssueLabelsRequest)
113 .await
114 }
115
116 pub async fn issues(
117 &mut self,
118 ) -> Result<Vec<RepositoryIssue>, OperationError<RepositoryError>> {
119 self.request::<RepositoryIssuesRequest>(RepositoryIssuesRequest)
120 .await
121 }
122
123 pub async fn inspect_files(
124 &mut self,
125 path: &String,
126 rev: Option<&str>
127 ) -> Result<Vec<RepositoryTreeEntry>, OperationError<RepositoryError>> {
128 self.request::<RepositoryFileInspectRequest>(RepositoryFileInspectRequest {
129 rev: rev.map(|r| r.to_string()),
130 path: path.clone(),
131 })
132 .await
133 }
134 }
135