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, RepositoryFile, RepositoryDiff, Commit};
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
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 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
#[derive(Clone, Debug, Serialize, Deserialize)]
|
43 |
pub struct RepositoryFileFromIdRequest(pub String);
|
44 |
|
45 |
impl GiteratedOperation<Repository> for RepositoryFileFromIdRequest {
|
46 |
type Success = RepositoryFile;
|
47 |
type Failure = RepositoryError;
|
48 |
}
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
#[derive(Clone, Debug, Serialize, Deserialize)]
|
60 |
pub struct RepositoryDiffRequest {
|
61 |
pub old_id: String,
|
62 |
pub new_id: String,
|
63 |
}
|
64 |
|
65 |
impl GiteratedOperation<Repository> for RepositoryDiffRequest {
|
66 |
type Success = RepositoryDiff;
|
67 |
type Failure = RepositoryError;
|
68 |
}
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
#[derive(Clone, Debug, Serialize, Deserialize)]
|
80 |
pub struct RepositoryCommitBeforeRequest(pub String);
|
81 |
|
82 |
impl GiteratedOperation<Repository> for RepositoryCommitBeforeRequest {
|
83 |
type Success = Commit;
|
84 |
type Failure = RepositoryError;
|
85 |
}
|
86 |
|
87 |
#[derive(Clone, Debug, Serialize, Deserialize)]
|
88 |
pub struct RepositoryIssuesCountRequest;
|
89 |
|
90 |
impl GiteratedOperation<Repository> for RepositoryIssuesCountRequest {
|
91 |
type Success = u64;
|
92 |
type Failure = RepositoryError;
|
93 |
}
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
#[derive(Clone, Debug, Serialize, Deserialize)]
|
105 |
pub struct RepositoryIssueLabelsRequest;
|
106 |
|
107 |
impl GiteratedOperation<Repository> for RepositoryIssueLabelsRequest {
|
108 |
type Success = Vec<IssueLabel>;
|
109 |
type Failure = RepositoryError;
|
110 |
}
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
#[derive(Clone, Debug, Serialize, Deserialize)]
|
122 |
pub struct RepositoryIssuesRequest;
|
123 |
|
124 |
impl GiteratedOperation<Repository> for RepositoryIssuesRequest {
|
125 |
type Success = Vec<RepositoryIssue>;
|
126 |
type Failure = RepositoryError;
|
127 |
}
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
#[derive(Clone, Debug, Serialize, Deserialize)]
|
139 |
pub struct RepositoryFileInspectRequest {
|
140 |
|
141 |
pub extra_metadata: bool,
|
142 |
|
143 |
pub rev: Option<String>,
|
144 |
|
145 |
pub path: Option<String>,
|
146 |
}
|
147 |
|
148 |
impl GiteratedOperation<Repository> for RepositoryFileInspectRequest {
|
149 |
type Success = Vec<RepositoryTreeEntry>;
|
150 |
type Failure = RepositoryError;
|
151 |
}
|
152 |
|
153 |
impl<B: ObjectBackend + std::fmt::Debug> Object<'_, Repository, B> {
|
154 |
pub async fn info(
|
155 |
&mut self,
|
156 |
extra_metadata: bool,
|
157 |
rev: Option<String>,
|
158 |
path: Option<String>,
|
159 |
) -> Result<RepositoryView, OperationError<RepositoryError>> {
|
160 |
self.request::<RepositoryInfoRequest>(RepositoryInfoRequest {
|
161 |
extra_metadata,
|
162 |
rev,
|
163 |
path,
|
164 |
})
|
165 |
.await
|
166 |
}
|
167 |
|
168 |
pub async fn file_from_id(
|
169 |
&mut self,
|
170 |
id: String,
|
171 |
) -> Result<RepositoryFile, OperationError<RepositoryError>> {
|
172 |
self.request::<RepositoryFileFromIdRequest>(RepositoryFileFromIdRequest(id)).await
|
173 |
}
|
174 |
|
175 |
pub async fn diff(
|
176 |
&mut self,
|
177 |
old_id: String,
|
178 |
new_id: String,
|
179 |
) -> Result<RepositoryDiff, OperationError<RepositoryError>> {
|
180 |
self.request::<RepositoryDiffRequest>(RepositoryDiffRequest { old_id, new_id }).await
|
181 |
}
|
182 |
|
183 |
pub async fn commit_before(
|
184 |
&mut self,
|
185 |
id: String,
|
186 |
) -> Result<Commit, OperationError<RepositoryError>> {
|
187 |
self.request::<RepositoryCommitBeforeRequest>(RepositoryCommitBeforeRequest(id)).await
|
188 |
}
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
pub async fn issue_labels(
|
196 |
&mut self,
|
197 |
) -> Result<Vec<IssueLabel>, OperationError<RepositoryError>> {
|
198 |
self.request::<RepositoryIssueLabelsRequest>(RepositoryIssueLabelsRequest)
|
199 |
.await
|
200 |
}
|
201 |
|
202 |
pub async fn issues(
|
203 |
&mut self,
|
204 |
) -> Result<Vec<RepositoryIssue>, OperationError<RepositoryError>> {
|
205 |
self.request::<RepositoryIssuesRequest>(RepositoryIssuesRequest)
|
206 |
.await
|
207 |
}
|
208 |
|
209 |
pub async fn inspect_files(
|
210 |
&mut self,
|
211 |
extra_metadata: bool,
|
212 |
rev: Option<&str>,
|
213 |
path: Option<&str>,
|
214 |
) -> Result<Vec<RepositoryTreeEntry>, OperationError<RepositoryError>> {
|
215 |
self.request::<RepositoryFileInspectRequest>(RepositoryFileInspectRequest {
|
216 |
extra_metadata,
|
217 |
rev: rev.map(|r| r.to_string()),
|
218 |
path: path.map(|p| p.to_string()),
|
219 |
})
|
220 |
.await
|
221 |
}
|
222 |
}
|
223 |
|