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

ambee/giterated

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

Fix handling stack

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨c53b026

⁨giterated-models/src/repository/operations.rs⁩ - ⁨4669⁩ 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 /// Whether to get extra metadata for every entry (file mode, size and last commit made to it).
87 pub extra_metadata: bool,
88 /// Revision of the repository to get (branch, commit id).
89 pub rev: Option<String>,
90 /// If not given a path, it'll default to the base.
91 pub path: Option<String>,
92 }
93
94 impl GiteratedOperation<Repository> for RepositoryFileInspectRequest {
95 type Success = Vec<RepositoryTreeEntry>;
96 type Failure = RepositoryError;
97 }
98
99 impl<B: ObjectBackend + std::fmt::Debug> Object<'_, Repository, B> {
100 pub async fn info(
101 &mut self,
102 extra_metadata: bool,
103 rev: Option<String>,
104 path: Option<String>,
105 ) -> Result<RepositoryView, OperationError<RepositoryError>> {
106 self.request::<RepositoryInfoRequest>(RepositoryInfoRequest {
107 extra_metadata,
108 rev,
109 path,
110 })
111 .await
112 }
113 // pub async fn issues_count(&mut self) -> Result<u64, OperationError<RepositoryError>> {
114 // self.request::<RepositoryIssuesCountRequest>(RepositoryIssuesCountRequest)
115 // .await
116 // }
117
118 pub async fn issue_labels(
119 &mut self,
120 ) -> Result<Vec<IssueLabel>, OperationError<RepositoryError>> {
121 self.request::<RepositoryIssueLabelsRequest>(RepositoryIssueLabelsRequest)
122 .await
123 }
124
125 pub async fn issues(
126 &mut self,
127 ) -> Result<Vec<RepositoryIssue>, OperationError<RepositoryError>> {
128 self.request::<RepositoryIssuesRequest>(RepositoryIssuesRequest)
129 .await
130 }
131
132 pub async fn inspect_files(
133 &mut self,
134 extra_metadata: bool,
135 rev: Option<&str>,
136 path: Option<&str>,
137 ) -> Result<Vec<RepositoryTreeEntry>, OperationError<RepositoryError>> {
138 self.request::<RepositoryFileInspectRequest>(RepositoryFileInspectRequest {
139 extra_metadata,
140 rev: rev.map(|r| r.to_string()),
141 path: path.map(|p| p.to_string()),
142 })
143 .await
144 }
145 }
146