1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
#[derive(Copy, Clone, Deserialize, Serialize, ToSchema)]
pub enum ReviewState {
Draft,
Open,
Dropped,
Closed,
}
impl TryFrom<u8> for ReviewState {
type Error = &'static str;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(ReviewState::Draft),
1 => Ok(ReviewState::Open),
2 => Ok(ReviewState::Dropped),
3 => Ok(ReviewState::Closed),
_ => Err("Invalid review state"),
}
}
}
#[derive(Copy, Clone, Deserialize, Serialize, ToSchema)]
pub enum Rewrite {
Disabled,
History,
Rebase,
}
impl TryFrom<u8> for Rewrite {
type Error = &'static str;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(Rewrite::Disabled),
1 => Ok(Rewrite::History),
2 => Ok(Rewrite::Rebase),
_ => Err("Invalid review state"),
}
}
}
#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize, ToSchema)]
pub enum UserReviewRole {
Reviewer,
Watcher,
None,
}
impl TryFrom<u8> for UserReviewRole {
type Error = &'static str;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(UserReviewRole::None),
1 => Ok(UserReviewRole::Reviewer),
2 => Ok(UserReviewRole::Watcher),
_ => Err("Invalid role"),
}
}
}
impl From<UserReviewRole> for u8 {
fn from(value: UserReviewRole) -> u8 {
match value {
UserReviewRole::None => 0,
UserReviewRole::Reviewer => 1,
UserReviewRole::Watcher => 2,
}
}
}
#[derive(Debug, Deserialize, Serialize, PartialEq, ToSchema)]
pub struct User {
#[schema(example = "jsmith")]
pub id: String,
#[schema(example = "John Smith")]
pub name: String,
#[schema(example = true)]
pub active: bool,
}
#[derive(Deserialize, Serialize, ToSchema)]
pub struct Users {
#[schema(example = 0u32)]
pub offset: u32,
#[schema(example = 10u32)]
pub limit: u32,
#[schema(example = 42u32)]
pub total_count: u32,
#[schema(example = true)]
pub more: bool,
pub users: Vec<User>,
}
#[derive(Serialize, ToSchema)]
pub struct ReviewUserEntry {
pub user: User,
#[schema(example = UserReviewRole::Reviewer)]
pub role: UserReviewRole,
}
#[derive(Serialize, ToSchema)]
pub struct Review {
#[schema(example = 1000u64)]
pub id: u64,
#[schema(example = "FAKE-512: Add more features")]
pub title: String,
#[schema(example = "We're adding more features because features are what we want.")]
pub description: String,
pub owner: User,
pub users: Vec<ReviewUserEntry>,
#[schema(example = ReviewState::Open)]
pub state: ReviewState,
#[schema(example = 37.5)]
pub progress: f32,
#[schema(example = "r/user/TASK-123456")]
pub branch: String,
#[schema(example = false)]
pub archived: bool,
}
#[derive(Deserialize, Serialize, ToSchema)]
pub struct ReviewEntry {
#[schema(example = 1000u64)]
pub id: u64,
#[schema(example = "FAKE-512: Add more features")]
pub title: String,
pub owner: User,
#[schema(example = ReviewState::Open)]
pub state: ReviewState,
#[schema(example = 37.5)]
pub progress: f32,
#[schema(example = "r/user/TASK-123456")]
pub branch: String,
}
#[derive(Deserialize, Serialize, ToSchema)]
pub struct Reviews {
#[schema(example = 0u32)]
pub offset: u32,
#[schema(example = 10u32)]
pub limit: u32,
#[schema(example = 42u32)]
pub total_count: u32,
#[schema(example = true)]
pub more: bool,
pub reviews: Vec<ReviewEntry>,
}
#[derive(Debug, Deserialize, PartialEq, Serialize, ToSchema)]
pub struct ProjectUserEntry {
pub user: User,
#[schema(example = UserReviewRole::Reviewer)]
pub default_role: UserReviewRole,
#[schema(example = false)]
pub maintainer: bool,
}
#[derive(Deserialize, Serialize, ToSchema)]
pub struct ProjectUserEntryData {
#[schema(example = UserReviewRole::Reviewer)]
pub default_role: Option<UserReviewRole>,
#[schema(example = false)]
pub maintainer: Option<bool>,
}
#[derive(Debug, Deserialize, PartialEq, Serialize, ToSchema)]
pub struct Project {
#[schema(example = "fake")]
pub id: String,
#[schema(example = "FAKE: Features All Kids Erase")]
pub title: String,
#[schema(example = "Example project")]
pub description: String,
#[schema(example = "ssh://git.example.org/srv/git/")]
pub remote: String,
#[schema(example = "b3BlbNNz...AQIDBA==")]
pub remote_key_abbrev: String,
#[schema(example = "main")]
pub main_branch: String,
pub users: Vec<ProjectUserEntry>,
}
#[derive(Deserialize, Serialize, ToSchema)]
pub struct ProjectData<'r> {
#[schema(example = "FAKE: Features All Kids Erase")]
pub title: Option<&'r str>,
#[schema(example = "Example project")]
pub description: Option<&'r str>,
#[schema(example = "ssh://git.example.org/srv/git/")]
pub remote: Option<&'r str>,
#[schema(example = "b3BlbNNz...AQIDBA==")]
pub remote_key: Option<String>,
#[schema(example = "main")]
pub main_branch: Option<&'r str>,
}
#[derive(Deserialize, Serialize, ToSchema)]
pub struct ProjectEntry {
#[schema(example = "fake")]
pub id: String,
#[schema(example = "FAKE: Features All Kids Erase")]
pub title: String,
}
#[derive(Deserialize, Serialize, ToSchema)]
pub struct Projects {
#[schema(example = 0u32)]
pub offset: u32,
#[schema(example = 10u32)]
pub limit: u32,
#[schema(example = 1u32)]
pub total_count: u32,
#[schema(example = false)]
pub more: bool,
pub projects: Vec<ProjectEntry>,
}
#[derive(Deserialize, Serialize, ToSchema)]
pub struct StatusResponse {
pub ok: bool,
#[serde(
skip_serializing_if = "Option::is_none",
// &'static str is problematic for serde, only used in tests anyway.
skip_deserializing,
)]
pub error: Option<&'static str>,
}
#[derive(Debug, Deserialize, PartialEq, Serialize, ToSchema)]
pub struct UserKey {
#[schema(example = 1u64)]
pub id: u64,
#[schema(example = "ssh-rsa")]
pub kind: String,
#[schema(example = "AAAAfoobar==")]
pub data: String,
#[schema(example = "user@host 1970-01-01")]
pub comment: String,
}
#[derive(Deserialize, Serialize, ToSchema)]
pub struct UserKeyData<'r> {
#[schema(example = "ssh-rsa")]
pub kind: &'r str,
#[schema(example = "AAAAfoobar==")]
pub data: &'r str,
#[schema(example = "user@host 1970-01-01")]
pub comment: Option<&'r str>,
}
#[derive(Deserialize, Serialize, ToSchema)]
pub struct UserKeys {
#[schema(example = 0u32)]
pub offset: u32,
#[schema(example = 10u32)]
pub limit: u32,
#[schema(example = 2u32)]
pub total_count: u32,
#[schema(example = false)]
pub more: bool,
pub keys: Vec<UserKey>,
}
#[derive(Debug, Deserialize, PartialEq, Serialize, ToSchema)]
pub struct LocalizationString {
#[schema(example = "IDS_GENERIC_WELCOME")]
pub id: String,
#[schema(example = "strings/strings.grd")]
pub file: String,
#[schema(example = "Generic greating")]
pub description: String,
#[schema(example = "This should be a positive greating")]
pub meaning: String,
#[schema(example = "Hello!")]
pub source: String,
pub placeholders: Vec<LocalizationPlaceholder>,
pub placeholder_offset: Vec<usize>,
#[schema(example = "123456")]
pub translation_id: i64,
pub translations: Vec<TranslationString>,
}
#[derive(Debug, Deserialize, PartialEq, Serialize, ToSchema)]
pub struct LocalizationPlaceholder {
#[schema(example = "NAME")]
pub id: String,
#[schema(example = "%1$d")]
pub content: String,
#[schema(example = "42")]
pub example: String,
}
#[derive(Debug, Deserialize, PartialEq, Serialize, ToSchema)]
pub struct TranslationString {
#[schema(example = "sv")]
pub language: String,
#[schema(example = "Hej!")]
pub translation: String,
pub placeholder_offset: Vec<usize>,
}
|