OXYGENHUB
◆ v0.9.11 oxygenhub / crates / hub-api / src / lib.rs
54.9 KiB · Rust · last changed Your sky over the API: GET /api/v1/user/sky, the dashboard backdrop's data for the Android app; 0.9.11 (refs andymccall/oxygenhub-android#23) 8 days ago source blame history raw
8d2caf12 Andy McCall ↶ 1
//! Types of the OxygenHub JSON API (hub spec §12.1). Everything here is
d23464c0 Andy McCall ↶ 2
//! `serde` data with no behaviour, so clients in other languages can be
3
//! generated from it and the server can never drift from them.
4
//!
5
//! Shapes reuse `oxy --json`'s where one exists (hashes as lowercase hex,
6
//! times as milliseconds since the epoch), so tools written against the
7
//! command line work against the hub.
8
b64e2537 Andy McCall ↶ 9
use schemars::JsonSchema;
d23464c0 Andy McCall ↶ 10
use serde::{Deserialize, Serialize};
11
12
/// A repository as the API lists it.
b64e2537 Andy McCall ↶ 13
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 14
pub struct Repository {
15
    pub owner: String,
16
    pub name: String,
17
    pub description: String,
18
    pub default_bookmark: String,
19
    pub visibility: Visibility,
20
    /// Milliseconds since the epoch.
21
    pub created_ms: i64,
22
    pub updated_ms: i64,
23
    /// `https://…/{owner}/{name}`, what `oxy clone` takes.
24
    pub clone_url: String,
25
}
26
b64e2537 Andy McCall ↶ 27
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 28
#[serde(rename_all = "lowercase")]
29
pub enum Visibility {
30
    Public,
31
    Internal,
32
    Private,
33
}
34
35
impl Visibility {
36
    pub fn as_str(self) -> &'static str {
37
        match self {
38
            Visibility::Public => "public",
39
            Visibility::Internal => "internal",
40
            Visibility::Private => "private",
41
        }
42
    }
43
44
    pub fn parse(s: &str) -> Option<Visibility> {
45
        Some(match s {
46
            "public" => Visibility::Public,
47
            "internal" => Visibility::Internal,
48
            "private" => Visibility::Private,
49
            _ => return None,
50
        })
51
    }
52
}
53
54
/// A bookmark: a name for a set of heads (spec §10.1).
b64e2537 Andy McCall ↶ 55
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 56
pub struct Bookmark {
57
    pub name: String,
58
    pub heads: Vec<String>,
59
    /// Number of changes in the bookmark's state.
60
    pub changes: usize,
61
    pub default: bool,
62
}
63
64
/// A tag: a name for one state, with its attestation when signed.
b64e2537 Andy McCall ↶ 65
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 66
pub struct Tag {
67
    pub name: String,
68
    pub heads: Vec<String>,
69
    pub message: String,
70
    pub signer: Option<String>,
71
}
72
73
/// One change in a history listing.
b64e2537 Andy McCall ↶ 74
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 75
pub struct ChangeSummary {
76
    pub hash: String,
77
    pub message: String,
78
    pub author: Author,
79
    pub when_ms: u64,
80
    pub deps: Vec<String>,
81
    pub head: bool,
82
    pub signature: Signature,
8933faff Andy McCall ↶ 83
    /// Signed for the author by a delegate (an agent), when it was.
84
    #[serde(default, skip_serializing_if = "Option::is_none")]
85
    pub via: Option<Via>,
86
}
87
88
/// A delegate that signed a change for its author (Oxygen spec §14.2).
89
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
90
pub struct Via {
91
    pub name: String,
92
    pub key: String,
93
    /// The delegation's scope, `changes` for an agent.
94
    pub scope: String,
95
    pub expires_ms: Option<u64>,
96
    /// The delegation has since been revoked or withdrawn.
97
    pub revoked: bool,
d23464c0 Andy McCall ↶ 98
}
99
100
/// Who wrote a change: the linked account when the signing key is linked,
101
/// else the key alone.
b64e2537 Andy McCall ↶ 102
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 103
pub struct Author {
104
    pub name: String,
105
    pub email: String,
106
    pub key: String,
107
    /// The hub account this key is linked to, when any.
108
    pub account: Option<String>,
760a7dd3 Andy McCall ↶ 109
    /// Set when the change is signed by a key no account has linked, and
110
    /// says how its owner links it.
111
    #[serde(default, skip_serializing_if = "Option::is_none")]
112
    pub note: Option<String>,
113
}
114
115
impl Author {
116
    /// What `note` says for a key that no account has linked.
117
    pub const UNLINKED: &'static str =
118
        "signed by a key not linked to any account; its owner links it under Settings → Keys (/settings/keys)";
119
120
    /// The note for an author with this key and account.
121
    pub fn note_for(key: &str, account: &Option<String>) -> Option<String> {
122
        (!key.is_empty() && account.is_none()).then(|| Self::UNLINKED.to_string())
123
    }
d23464c0 Andy McCall ↶ 124
}
125
126
/// Signature status of a change as `oxy verify` reports it.
b64e2537 Andy McCall ↶ 127
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 128
#[serde(tag = "status", rename_all = "lowercase")]
129
pub enum Signature {
130
    Unsigned,
131
    Valid { key: String, sealed: bool, revoked: bool },
132
    Invalid { reason: String },
133
}
134
135
/// An RFC 7807 problem response.
b64e2537 Andy McCall ↶ 136
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 137
pub struct Problem {
138
    pub status: u16,
139
    pub title: String,
140
    pub detail: String,
141
}
142
143
#[cfg(test)]
144
mod tests {
145
    use super::*;
146
147
    #[test]
148
    fn visibility_round_trips() {
149
        for v in [Visibility::Public, Visibility::Internal, Visibility::Private] {
150
            assert_eq!(Visibility::parse(v.as_str()), Some(v));
151
        }
152
        assert_eq!(Visibility::parse("secret"), None);
153
    }
154
}
de505df5 Andy McCall ↶ 155
156
// ---------------------------------------------------------------- proposals
157
158
/// A proposal: a request to add changes to a target bookmark (hub spec §7).
b64e2537 Andy McCall ↶ 159
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
de505df5 Andy McCall ↶ 160
pub struct Proposal {
161
    pub number: i64,
162
    pub title: String,
163
    pub body: String,
164
    pub author: String,
165
    pub state: ProposalState,
166
    pub target: String,
167
    pub source: ProposalSource,
168
    /// The changes the proposal adds, dependency order, newest last.
169
    pub changes: Vec<ChangeSummary>,
170
    /// Heads of the projected state (target plus the changes), when computed.
171
    pub projected_heads: Vec<String>,
172
    pub projected_state: Option<String>,
173
    pub conflicted: bool,
174
    pub approvals: Vec<Approval>,
175
    pub landable: bool,
176
    pub blockers: Vec<String>,
177
    pub created_ms: i64,
178
    pub updated_ms: i64,
179
    /// `https://hub/{owner}/{name}/proposal/{number}`.
180
    pub url: String,
181
    /// Where `oxy` fetches the changes from.
182
    pub repository_url: String,
183
    /// The fork's clone URL when the source is a fork.
184
    pub source_url: Option<String>,
0b20f1ec Andy McCall ↶ 185
    /// Who landed it, how and when, once landed.
186
    #[serde(default)]
187
    pub landed: Option<Landed>,
86a69b53 Andy McCall ↶ 188
    /// Who set it to land when its checks pass (oxygenhub#261), while set.
189
    #[serde(default)]
190
    pub auto_land: Option<String>,
cc1cd197 Andy McCall ↶ 191
    /// Asked to review and not yet reviewing, in the order asked.
192
    #[serde(default)]
193
    pub requested_reviewers: Vec<String>,
2291f8cc Andy McCall ↶ 194
    #[serde(default)]
195
    pub labels: Vec<Label>,
0b20f1ec Andy McCall ↶ 196
}
197
198
/// How a proposal was landed.
199
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
200
pub struct Landed {
201
    pub by: String,
202
    /// `web`, or `api (token NAME)`.
203
    pub via: String,
204
    pub when_ms: i64,
de505df5 Andy McCall ↶ 205
}
206
b64e2537 Andy McCall ↶ 207
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
de505df5 Andy McCall ↶ 208
#[serde(rename_all = "lowercase")]
209
pub enum ProposalState {
210
    Draft,
211
    Open,
212
    Landed,
213
    Closed,
214
}
215
216
impl ProposalState {
217
    pub fn as_str(self) -> &'static str {
218
        match self {
219
            ProposalState::Draft => "draft",
220
            ProposalState::Open => "open",
221
            ProposalState::Landed => "landed",
222
            ProposalState::Closed => "closed",
223
        }
224
    }
225
226
    pub fn parse(s: &str) -> Option<ProposalState> {
227
        Some(match s {
228
            "draft" => ProposalState::Draft,
229
            "open" => ProposalState::Open,
230
            "landed" => ProposalState::Landed,
231
            "closed" => ProposalState::Closed,
232
            _ => return None,
233
        })
234
    }
235
}
236
b64e2537 Andy McCall ↶ 237
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
de505df5 Andy McCall ↶ 238
#[serde(tag = "kind", rename_all = "lowercase")]
239
pub enum ProposalSource {
240
    /// A bookmark of the same repository.
241
    Bookmark { bookmark: String },
242
    /// A bookmark of a fork.
243
    Fork { owner: String, name: String, bookmark: String },
244
    /// An explicit list of change hashes.
245
    Changes { hashes: Vec<String> },
246
}
247
248
/// A reviewer's approval, counted only when backed by a seal over every
249
/// change of the proposal signed with a key linked to the reviewer.
b64e2537 Andy McCall ↶ 250
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
de505df5 Andy McCall ↶ 251
pub struct Approval {
252
    pub account: String,
253
    pub sealed: bool,
254
    pub key: Option<String>,
255
}
b64e2537 Andy McCall ↶ 256
257
// ------------------------------------------------------------------ issues
258
259
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
260
pub struct Issue {
261
    pub number: i64,
262
    pub title: String,
263
    pub body: String,
264
    pub author: String,
265
    pub state: String,
266
    pub reason: String,
267
    pub labels: Vec<Label>,
268
    pub assignees: Vec<String>,
269
    pub milestone: Option<String>,
270
    pub comments: i64,
271
    pub locked: bool,
272
    pub pinned: bool,
273
    pub created_ms: i64,
274
    pub updated_ms: i64,
275
    pub closed_ms: Option<i64>,
276
    pub url: String,
277
}
278
279
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
280
pub struct Label {
281
    pub name: String,
282
    pub colour: String,
283
    pub description: String,
284
}
285
286
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
287
pub struct Milestone {
288
    pub title: String,
289
    pub description: String,
290
    pub due_ms: Option<i64>,
291
    pub state: String,
292
    pub open: i64,
293
    pub closed: i64,
294
}
295
5ea4872f Andy McCall ↶ 296
/// `POST /repos/{o}/{n}/milestones`: create a milestone, or change the
297
/// description and due date of the one with that title (triage).
b64e2537 Andy McCall ↶ 298
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5ea4872f Andy McCall ↶ 299
pub struct NewMilestone {
300
    pub title: String,
301
    #[serde(default)]
302
    pub description: String,
303
    /// `YYYY-MM-DD`, UTC; absent for no due date.
304
    #[serde(default)]
305
    pub due: Option<String>,
306
}
307
308
/// `PATCH /repos/{o}/{n}/milestones/{title}`: only the fields given change
309
/// (triage).
310
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5a9a6e9a Andy McCall ↶ 311
#[serde(deny_unknown_fields)]
5ea4872f Andy McCall ↶ 312
pub struct MilestoneEdit {
313
    #[serde(default)]
314
    pub title: Option<String>,
315
    #[serde(default)]
316
    pub description: Option<String>,
317
    /// `YYYY-MM-DD`; the empty string clears the due date.
318
    #[serde(default)]
319
    pub due: Option<String>,
320
    /// `open` or `closed`.
321
    #[serde(default)]
322
    pub state: Option<String>,
323
}
324
325
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
b64e2537 Andy McCall ↶ 326
pub struct Comment {
327
    pub id: i64,
328
    pub author: String,
329
    pub body: String,
330
    pub created_ms: i64,
331
    /// For proposal comments: the file and the atom the comment anchors to.
332
    pub path: Option<String>,
333
    pub anchor: Option<Atom>,
c0fac31d Andy McCall ↶ 334
    /// Where the anchor sits now: its 1-based line in `path` in the
335
    /// projected state, when the atom is still live there.
336
    #[serde(default)]
337
    pub line: Option<usize>,
b64e2537 Andy McCall ↶ 338
    pub resolved: bool,
339
}
340
42a0ba4b Andy McCall ↶ 341
/// One entry in the caller's inbox (hub spec §10).
342
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
343
pub struct Notification {
344
    pub id: i64,
345
    pub at_ms: i64,
346
    /// `issue.opened`, `proposal.comment`, `mention`, `review`, …
347
    pub kind: String,
348
    pub title: String,
349
    /// The page on the hub, absolute.
350
    pub url: String,
351
    pub actor: String,
352
    pub read: bool,
ecac6e8d Andy McCall ↶ 353
    /// The repository it is about, `owner/name` (#305).
354
    #[serde(default)]
355
    pub repository: Option<String>,
356
    /// Why the caller is told: `participating` or `watching`.
357
    #[serde(default)]
358
    pub reason: String,
359
    /// The thread it belongs to (its page, without a fragment), absolute:
360
    /// a client groups the inbox by it.
361
    #[serde(default)]
362
    pub thread: String,
363
    /// The kind as the hub's pages label it ("🐛 New Issue"), when it has one.
364
    #[serde(default)]
365
    pub label: Option<String>,
42a0ba4b Andy McCall ↶ 366
}
367
368
/// `GET /notifications`: the unread count and the newest entries, unread first.
369
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
370
pub struct Inbox {
371
    pub unread: i64,
372
    pub items: Vec<Notification>,
373
}
374
3f02e5ea Andy McCall ↶ 375
/// A file a proposal changes, between the target's state and the
376
/// projected state (hub spec §7.2). Fetch either side's bytes from
377
/// `/proposals/{number}/content/{base|head}/{path}`.
b64e2537 Andy McCall ↶ 378
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
3f02e5ea Andy McCall ↶ 379
pub struct ProposalFile {
380
    pub path: String,
381
    /// For a rename, the path in the target's state.
382
    pub from: Option<String>,
383
    /// `added`, `removed`, `modified`, `renamed`, `mode` or `replaced`.
384
    pub kind: String,
385
    pub added: usize,
386
    pub removed: usize,
387
}
388
389
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
b64e2537 Andy McCall ↶ 390
pub struct Atom {
391
    pub change: String,
392
    pub index: u32,
393
}
394
395
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
396
pub struct Review {
397
    pub id: i64,
398
    pub author: String,
399
    pub verdict: String,
400
    pub body: String,
401
    pub sealed: bool,
402
    pub created_ms: i64,
7d2eb590 Andy McCall ↶ 403
    /// The AI assistant that answered for `author`, empty for a person's
404
    /// own review (hub spec §13.4).
405
    #[serde(default, skip_serializing_if = "String::is_empty")]
406
    pub via: String,
b64e2537 Andy McCall ↶ 407
}
408
409
// ------------------------------------------------------------- repository
410
411
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
412
pub struct TreeEntry {
413
    pub name: String,
414
    pub path: String,
415
    pub kind: String,
416
    pub exec: bool,
417
    pub size: Option<u64>,
418
    pub conflicted: bool,
419
}
420
421
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
422
pub struct BlameLine {
423
    pub line: usize,
424
    pub change: String,
425
    pub index: u32,
426
    pub author: String,
427
    pub when_ms: u64,
428
    pub text: String,
429
}
430
431
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
432
pub struct FileChange {
433
    pub path: String,
434
    pub kind: String,
435
    pub from: Option<String>,
436
    pub added: usize,
437
    pub removed: usize,
d2263e29 Andy McCall ↶ 438
    /// The diff with three lines of context, up to `DIFF_LINES` lines.
439
    #[serde(default)]
440
    pub lines: Vec<DiffLine>,
441
    /// Whether `lines` stops short of the whole diff.
442
    #[serde(default)]
443
    pub truncated: bool,
444
}
445
446
/// Lines of one file's diff the API sends at most.
447
pub const DIFF_LINES: usize = 2000;
448
449
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
450
pub struct DiffLine {
451
    /// `context`, `add`, `del`, or `gap` (lines left out between hunks).
452
    pub kind: String,
453
    #[serde(default, skip_serializing_if = "Option::is_none")]
454
    pub old: Option<u32>,
455
    #[serde(default, skip_serializing_if = "Option::is_none")]
456
    pub new: Option<u32>,
457
    #[serde(default)]
458
    pub text: String,
b64e2537 Andy McCall ↶ 459
}
460
461
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
462
pub struct ChangeDetail {
463
    pub change: ChangeSummary,
464
    pub body: String,
465
    pub dependents: Vec<String>,
466
    pub in_bookmarks: Vec<String>,
467
    pub in_tags: Vec<String>,
468
    pub files: Vec<FileChange>,
469
}
470
471
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
472
pub struct History {
473
    pub reference: String,
474
    pub heads: Vec<String>,
475
    pub total: usize,
476
    pub offset: usize,
477
    pub changes: Vec<ChangeSummary>,
478
}
479
480
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
481
pub struct Conflict {
482
    pub bookmark: String,
483
    pub path: String,
484
    pub kind: String,
485
    pub contributors: Vec<String>,
486
}
487
488
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
489
pub struct Push {
490
    pub at_ms: i64,
491
    pub pusher: String,
492
    pub reference: String,
493
    pub ok: bool,
494
    pub reason: String,
495
    pub old_state: String,
496
    pub new_state: String,
497
    pub heads: i64,
498
    pub changes: i64,
499
}
500
501
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
502
pub struct Trust {
503
    pub policy: Option<Policy>,
504
    pub signed: usize,
505
    pub sealed: usize,
506
    pub unsigned: usize,
507
    pub invalid: Vec<String>,
508
    pub hub_key: String,
509
}
510
511
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
512
pub struct Policy {
513
    pub serial: u64,
514
    pub expires_ms: u64,
515
    pub roots: Vec<String>,
516
    pub root_threshold: u32,
517
    pub rules: Vec<Rule>,
518
}
519
520
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
521
pub struct Rule {
522
    pub pattern: String,
523
    pub keys: Vec<String>,
524
    pub threshold: u32,
525
    pub require: String,
526
    pub allow_conflicts: bool,
527
}
528
529
// ---------------------------------------------------------- hooks, checks
530
531
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
532
pub struct Hook {
533
    pub id: i64,
534
    pub url: String,
535
    pub events: String,
536
    pub active: bool,
537
    pub created_ms: i64,
538
}
539
540
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
541
pub struct NewHook {
542
    pub url: String,
543
    pub secret: String,
544
    #[serde(default = "star")]
545
    pub events: String,
546
}
547
548
fn star() -> String {
549
    "*".into()
550
}
551
90326c96 Andy McCall ↶ 552
/// An OxygenFlow run (hub spec §13.2).
553
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
554
pub struct FlowRun {
555
    /// The run's number within its repository.
556
    pub number: i64,
557
    pub bookmark: String,
558
    /// The state's hash, as checks are keyed.
559
    pub state: String,
560
    /// Its heads, full change hashes.
561
    pub heads: Vec<String>,
562
    /// `queued`, `running`, `passed`, `failed` or `error` (an invalid pipeline).
563
    pub status: String,
564
    /// `push`, `manual` or `rerun:N`.
565
    pub trigger: String,
566
    pub actor: String,
567
    pub pipeline_hash: String,
568
    /// An invalid pipeline's problems.
569
    pub error: String,
570
    pub created_ms: i64,
571
    pub finished_ms: Option<i64>,
572
    pub url: String,
bf3d0754 Andy McCall ↶ 573
    /// For a run waiting for a runner, its first queued job's 1-based
574
    /// place among all queued jobs.
575
    #[serde(default, skip_serializing_if = "Option::is_none")]
576
    pub queue_position: Option<i64>,
90326c96 Andy McCall ↶ 577
    /// Filled by the single-run endpoint.
578
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
579
    pub jobs: Vec<FlowJob>,
580
}
581
582
/// A job of a run.
583
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
584
pub struct FlowJob {
585
    pub name: String,
586
    /// `queued`, `running`, `passed`, `failed`, `skipped` or `error`.
587
    pub status: String,
588
    pub depends_on: Vec<String>,
589
    pub runner: String,
590
    pub exit_code: Option<i64>,
591
    pub error: String,
592
    pub started_ms: Option<i64>,
593
    pub finished_ms: Option<i64>,
594
    /// Log lines stored so far.
595
    pub log_lines: i64,
4d2e44d7 Andy McCall ↶ 596
    /// Why a queued job no runner can take waits (OxygenFlow spec §11.4);
597
    /// empty when it only waits its turn.
598
    #[serde(default, skip_serializing_if = "String::is_empty")]
599
    pub waiting: String,
501d8b26 Andy McCall ↶ 600
    /// Why it ran on its runner (oxygenflow#42): "holds the image, idle,
601
    /// speed 100 (class 3)".
602
    #[serde(default, skip_serializing_if = "String::is_empty")]
603
    pub placed: String,
b1860d60 Andy McCall ↶ 604
    /// Its approval gate (oxygenflow#57): `waiting` while it waits for a
605
    /// person to approve or reject it, `approved` or `rejected` after;
606
    /// empty for a job with no gate.
607
    #[serde(default, skip_serializing_if = "String::is_empty")]
608
    pub approval: String,
90326c96 Andy McCall ↶ 609
}
610
611
/// A line of a job's log.
612
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
613
pub struct FlowLogLine {
614
    /// Increasing within the job; pass the last one as `after` for more.
615
    pub seq: i64,
616
    /// Milliseconds since the job started.
617
    pub t: i64,
618
    /// `stdout`, `stderr` or `flow` (the runner's own notes).
619
    pub stream: String,
620
    pub text: String,
621
}
622
b64e2537 Andy McCall ↶ 623
/// A check on a state hash (hub spec §13.1).
624
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
625
pub struct Check {
626
    pub state: String,
627
    pub name: String,
628
    pub status: CheckStatus,
629
    pub summary: String,
630
    pub url: String,
631
    pub reporter: String,
632
    /// The seal attestation's reference when the checker sealed the changes.
633
    pub seal: Option<String>,
634
    pub started_ms: i64,
635
    pub finished_ms: Option<i64>,
636
}
637
638
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
639
#[serde(rename_all = "lowercase")]
640
pub enum CheckStatus {
641
    Queued,
642
    Running,
643
    Passed,
644
    Failed,
645
    Cancelled,
646
    Skipped,
647
}
648
649
impl CheckStatus {
650
    pub fn as_str(self) -> &'static str {
651
        match self {
652
            CheckStatus::Queued => "queued",
653
            CheckStatus::Running => "running",
654
            CheckStatus::Passed => "passed",
655
            CheckStatus::Failed => "failed",
656
            CheckStatus::Cancelled => "cancelled",
657
            CheckStatus::Skipped => "skipped",
658
        }
659
    }
660
661
    pub fn parse(s: &str) -> Option<CheckStatus> {
662
        Some(match s {
663
            "queued" => CheckStatus::Queued,
664
            "running" => CheckStatus::Running,
665
            "passed" => CheckStatus::Passed,
666
            "failed" => CheckStatus::Failed,
667
            "cancelled" => CheckStatus::Cancelled,
668
            "skipped" => CheckStatus::Skipped,
669
            _ => return None,
670
        })
671
    }
672
}
673
674
/// What a checker posts.
675
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
676
pub struct NewCheck {
677
    pub state: String,
678
    pub name: String,
679
    pub status: CheckStatus,
680
    #[serde(default)]
681
    pub summary: String,
682
    #[serde(default)]
683
    pub url: String,
684
    /// Hex of a seal attestation reference the checker pushed, if any.
685
    #[serde(default)]
686
    pub seal: Option<String>,
687
}
688
689
// ------------------------------------------------------------- accounts
690
691
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
692
pub struct User {
693
    pub username: String,
694
    pub display_name: String,
695
    pub is_admin: bool,
696
    pub keys: Vec<String>,
697
    pub created_ms: i64,
698
}
699
700
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
701
pub struct Organisation {
702
    pub name: String,
703
    pub display_name: String,
704
    pub description: String,
705
    pub members: Vec<String>,
ecac6e8d Andy McCall ↶ 706
}
707
5714347a Andy McCall ↶ 708
/// `POST /user/runner-token`: a one-time token that registers a runner for
709
/// the caller's own repositories, as a phone does when its owner offers it
710
/// as a runner (oxygenhub-android#8). Spent by `flow runner register` (or
711
/// the app), within 24 hours.
712
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
713
pub struct RunnerToken {
714
    pub token: String,
715
    /// Whose repositories the runner will serve.
716
    pub owner: String,
717
}
718
f4e13830 Andy McCall ↶ 719
/// `GET /user/proposals`: the caller's proposals to act on, as the web
720
/// dashboard lists them: open ones by others in repositories they belong
721
/// to that they have not reviewed yet, and their own open and draft ones.
722
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
723
pub struct UserProposals {
724
    pub review: Vec<ProposalBrief>,
725
    pub authored: Vec<ProposalBrief>,
5d818ec7 Andy McCall ↶ 726
    /// With `?landable=true` (#311): the open proposals the caller could
727
    /// land now, in repositories they can write to, with no blockers.
728
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
729
    pub landable: Vec<ProposalBrief>,
730
}
731
4dfa4599 Andy McCall ↶ 732
/// `GET /user/sky` (oxygenhub-android#23): Your sky's data, as the web
733
/// dashboard's backdrop reads it (docs/backgrounds.md §5): the caller's
734
/// repositories, newest-updated first, and their events of the last 30
735
/// days, newest first.
736
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
737
pub struct UserSky {
738
    /// The hub's clock (milliseconds), to age the events by.
739
    pub now: i64,
740
    /// `owner/name` of each repository.
741
    pub repos: Vec<String>,
742
    /// `[repo, kind, at_ms, n]`: an index into `repos`; kind 0 a push of
743
    /// `n` changes, 1 a proposal event, 2 an issue event, 3 a release, 4 a
744
    /// Flow run.
745
    pub events: Vec<[i64; 4]>,
746
}
747
5d818ec7 Andy McCall ↶ 748
/// `GET /user/proposals` query.
749
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
750
pub struct UserProposalsQuery {
751
    /// Also list what the caller can land now (slower: each proposal's
752
    /// projected state is worked out).
753
    #[serde(default)]
754
    pub landable: bool,
f4e13830 Andy McCall ↶ 755
}
756
757
/// A proposal in a list across repositories.
758
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
759
pub struct ProposalBrief {
760
    /// `owner/name`.
761
    pub repository: String,
762
    pub number: i64,
763
    pub title: String,
764
    pub author: String,
765
    pub state: ProposalState,
766
    pub conflicted: bool,
767
    pub updated_ms: i64,
768
    /// `https://hub/{owner}/{name}/proposal/{number}`.
769
    pub url: String,
770
}
771
ecac6e8d Andy McCall ↶ 772
/// `GET /user/orgs` (#302): an organisation the caller belongs to, and
773
/// their role there.
774
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
775
pub struct UserOrg {
776
    pub name: String,
777
    pub display_name: String,
778
    pub role: String,
b64e2537 Andy McCall ↶ 779
}
780
781
/// Forms accepted by the write endpoints.
782
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
783
pub struct NewRepository {
784
    pub owner: String,
785
    pub name: String,
786
    #[serde(default)]
787
    pub description: String,
788
    #[serde(default = "public")]
789
    pub visibility: Visibility,
790
}
791
792
fn public() -> Visibility {
793
    Visibility::Public
794
}
795
796
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
797
pub struct NewIssue {
798
    pub title: String,
799
    #[serde(default)]
800
    pub body: String,
76f262e1 Andy McCall ↶ 801
    /// Label names; each must exist. Needs triage.
802
    #[serde(default)]
803
    pub labels: Vec<String>,
804
    /// Usernames. Needs triage.
805
    #[serde(default)]
806
    pub assignees: Vec<String>,
807
    /// A milestone's title. Needs triage.
808
    #[serde(default)]
809
    pub milestone: Option<String>,
b64e2537 Andy McCall ↶ 810
}
811
76f262e1 Andy McCall ↶ 812
/// `PATCH /repos/{o}/{n}/issues/{number}`: only the fields given change.
813
/// Title and body: the author or triage. The rest: triage.
814
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5a9a6e9a Andy McCall ↶ 815
#[serde(deny_unknown_fields)]
76f262e1 Andy McCall ↶ 816
pub struct IssueEdit {
817
    #[serde(default)]
818
    pub title: Option<String>,
819
    #[serde(default)]
820
    pub body: Option<String>,
821
    /// The whole set of labels.
822
    #[serde(default)]
823
    pub labels: Option<Vec<String>>,
824
    /// The whole set of assignees.
825
    #[serde(default)]
826
    pub assignees: Option<Vec<String>>,
827
    /// A milestone's title; the empty string clears it.
828
    #[serde(default)]
829
    pub milestone: Option<String>,
830
}
831
961c10be Andy McCall ↶ 832
/// The checks a proposal needs, passed, to land on the repository's
833
/// default bookmark (hub spec §13.1). `GET` and `PUT
834
/// /repos/{o}/{n}/checks/required`.
835
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
836
pub struct RequiredChecks {
837
    pub names: Vec<String>,
838
}
839
ef20fdc1 Andy McCall ↶ 840
/// A project (hub spec §8.2).
841
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
842
pub struct Project {
843
    pub owner: String,
844
    pub number: i64,
845
    pub title: String,
846
    pub description: String,
847
    pub public: bool,
848
    pub closed: bool,
849
    pub updated_ms: i64,
850
    /// The board on the hub, absolute.
851
    pub url: String,
852
}
853
854
/// A card as the caller may see it.
855
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
856
pub struct ProjectCard {
857
    pub id: i64,
858
    /// `issue`, `proposal` or `note`.
859
    pub kind: String,
860
    /// `owner/name#N`; empty for a note.
861
    pub reference: String,
862
    /// The issue's or proposal's title, or the note.
863
    pub title: String,
864
    /// The issue's or proposal's state; empty for a note.
865
    pub state: String,
6a306cd0 Andy McCall ↶ 866
    /// The issue's or proposal's label names (oxygenhub#293).
867
    #[serde(default)]
868
    pub labels: Vec<String>,
869
    /// An issue's assignees' usernames.
870
    #[serde(default)]
871
    pub assignees: Vec<String>,
439ecd87 Andy McCall ↶ 872
    /// When it was archived (ms), for an archived card (oxygenhub#293).
873
    #[serde(default, skip_serializing_if = "Option::is_none")]
874
    pub archived_ms: Option<i64>,
ef20fdc1 Andy McCall ↶ 875
}
876
877
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
878
pub struct ProjectColumn {
879
    pub id: i64,
880
    pub name: String,
881
    pub cards: Vec<ProjectCard>,
882
}
883
884
/// `GET /projects/{owner}/{n}`.
885
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
886
pub struct Board {
887
    pub project: Project,
888
    pub columns: Vec<ProjectColumn>,
889
}
890
891
/// `POST /projects/{owner}`.
892
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
893
pub struct NewProject {
894
    pub title: String,
895
    #[serde(default)]
896
    pub description: String,
897
    #[serde(default)]
898
    pub private: bool,
899
}
900
901
/// `PATCH /projects/{owner}/{n}`: only the fields given change.
902
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5a9a6e9a Andy McCall ↶ 903
#[serde(deny_unknown_fields)]
ef20fdc1 Andy McCall ↶ 904
pub struct ProjectEdit {
b1e92a62 Andy McCall ↶ 905
    /// Transfer the board to this owner (#125): one the caller may make
906
    /// boards under. It takes the next number there.
907
    #[serde(default, skip_serializing_if = "Option::is_none")]
908
    pub owner: Option<String>,
ef20fdc1 Andy McCall ↶ 909
    #[serde(default)]
910
    pub title: Option<String>,
911
    #[serde(default)]
912
    pub description: Option<String>,
913
    #[serde(default)]
914
    pub private: Option<bool>,
915
    #[serde(default)]
916
    pub closed: Option<bool>,
917
}
918
919
/// `POST /projects/{owner}/{n}/cards`: a reference (`repo#12`) or a note,
920
/// into the column named (by id or name; the first column when absent).
921
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
922
pub struct NewCard {
923
    #[serde(default)]
924
    pub column: Option<String>,
925
    #[serde(default)]
926
    pub reference: String,
927
    #[serde(default)]
928
    pub note: String,
929
}
930
931
/// `PATCH /projects/{owner}/{n}/cards/{id}`: move to a column (id or name).
932
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
933
pub struct CardMove {
934
    pub column: String,
935
}
936
456f4197 Andy McCall ↶ 937
/// `POST /projects/{owner}/{n}/cards/move` (#289): every card of column
938
/// `from` to `column` at once, but those `except` names (card ids, or issue
939
/// and proposal numbers as `12`, `#12`, `name#12` or `owner/name#12`) and,
940
/// given `state`, only cards whose issue or proposal is in one of them
941
/// (`closed`, `landed`…). With `dry_run`, nothing moves.
942
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
943
pub struct CardsMove {
944
    pub from: String,
945
    pub column: String,
946
    #[serde(default)]
947
    pub except: Vec<String>,
948
    #[serde(default)]
949
    pub state: Vec<String>,
950
    #[serde(default)]
951
    pub dry_run: bool,
952
}
953
954
/// What a bulk move moved, and what it left in the column.
955
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
956
pub struct CardsMoved {
957
    pub moved: Vec<ProjectCard>,
439ecd87 Andy McCall ↶ 958
    pub kept: Vec<ProjectCard>,
959
    pub dry_run: bool,
960
}
961
962
/// `POST /projects/{owner}/{n}/cards/archive` (oxygenhub#293): take the
963
/// cards of column `from` off the board, kept and restorable, but those
964
/// `except` names and, given `state`, only cards whose issue or proposal is
965
/// in one of them; given `older_days`, only cards that joined the column
966
/// more than that many days ago. With `dry_run`, nothing is archived.
967
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
968
pub struct CardsArchive {
969
    pub from: String,
970
    #[serde(default)]
971
    pub older_days: Option<i64>,
972
    #[serde(default)]
973
    pub except: Vec<String>,
974
    #[serde(default)]
975
    pub state: Vec<String>,
976
    #[serde(default)]
977
    pub dry_run: bool,
978
}
979
980
/// What an archive took off the board, and what it left in the column.
981
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
982
pub struct CardsArchived {
983
    pub archived: Vec<ProjectCard>,
456f4197 Andy McCall ↶ 984
    pub kept: Vec<ProjectCard>,
985
    pub dry_run: bool,
986
}
987
76f262e1 Andy McCall ↶ 988
/// `POST /repos/{o}/{n}/labels`: create a label, or change one of that name.
989
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
990
pub struct NewLabel {
991
    pub name: String,
992
    /// `#rrggbb`; a default when absent.
993
    #[serde(default)]
994
    pub colour: Option<String>,
995
    #[serde(default)]
996
    pub description: String,
997
}
998
b64e2537 Andy McCall ↶ 999
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1000
pub struct NewComment {
1001
    pub body: String,
3f4b0ea6 Andy McCall ↶ 1002
    /// For a proposal: anchor the comment to this file's line (1-based) of
1003
    /// the projected state; the hub records the line's atom.
1004
    #[serde(default)]
1005
    pub path: Option<String>,
1006
    #[serde(default)]
1007
    pub line: Option<usize>,
b64e2537 Andy McCall ↶ 1008
}
1009
1010
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1011
pub struct NewProposal {
1012
    pub title: String,
1013
    #[serde(default)]
1014
    pub body: String,
1015
    pub target: String,
1016
    /// A bookmark here, or `owner/name:bookmark` of a fork.
1017
    pub source: String,
1018
    #[serde(default)]
1019
    pub draft: bool,
cc1cd197 Andy McCall ↶ 1020
}
1021
1022
/// `POST .../proposals/{number}/reviewers`: accounts to ask for a review.
1023
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1024
pub struct ReviewRequest {
1025
    pub reviewers: Vec<String>,
7d2eb590 Andy McCall ↶ 1026
}
1027
1028
/// `POST .../proposals/{number}/review-requests`: ask an AI assistant the
1029
/// repository may use (hub spec §13.4) to review; it answers as a `comment`
1030
/// review via the assistant.
1031
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1032
pub struct AssistantRequest {
1033
    pub assistant: String,
b64e2537 Andy McCall ↶ 1034
}
1035
1036
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1037
pub struct NewReview {
1038
    pub verdict: String,
1039
    #[serde(default)]
1040
    pub body: String,
1041
}
1042
1043
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1044
pub struct IssueStateChange {
1045
    /// `open` or `closed`.
1046
    pub state: String,
1047
    #[serde(default)]
1048
    pub reason: String,
1049
}
1050
1051
/// A webhook payload's envelope (hub spec §12.2).
1052
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1053
pub struct WebhookEnvelope {
1054
    pub event: String,
1055
    pub delivery: String,
1056
    pub repository: Option<Repository>,
1057
    pub actor: String,
1058
    pub at_ms: i64,
1059
    pub data: serde_json::Value,
1060
}
1061
1062
/// A server-sent event on a proposal's stream.
1063
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1064
pub struct ProposalEvent {
1065
    pub number: i64,
1066
    pub kind: String,
1067
    pub check: Option<Check>,
1068
}
1069
3f4b0ea6 Andy McCall ↶ 1070
// --------------------------------------------------------------- releases
1071
1072
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1073
pub struct Release {
1074
    pub tag: String,
1075
    pub title: String,
1076
    pub notes: String,
1077
    pub prerelease: bool,
1078
    pub latest: bool,
1079
    pub author: String,
1080
    pub heads: Vec<String>,
1081
    pub signer: Option<String>,
1082
    pub assets: Vec<ReleaseAsset>,
1083
    pub archives: Vec<String>,
1084
    pub created_ms: i64,
1085
    pub url: String,
1086
}
1087
1088
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1089
pub struct ReleaseAsset {
1090
    pub name: String,
1091
    pub size: i64,
1092
    /// BLAKE3 of the content, hex.
1093
    pub hash: String,
1094
    pub content_type: String,
1095
    pub downloads: i64,
1096
    pub url: String,
10708ab8 Andy McCall ↶ 1097
    /// The OxygenFlow run and job whose artifact has this content, if any.
1098
    #[serde(default, skip_serializing_if = "Option::is_none")]
1099
    pub built_by: Option<AssetBuild>,
1100
}
1101
1102
/// Where a release asset was built (hub spec §9): a job's artifact with the
1103
/// same BLAKE3, and that job's signed receipt when one was kept.
1104
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1105
pub struct AssetBuild {
1106
    pub run: i64,
1107
    pub job: String,
1108
    pub artifact: String,
1109
    pub run_url: String,
1110
    /// The receipt attestation, hex; `None` when the receipt was not signed.
1111
    pub receipt: Option<String>,
1112
    pub receipt_url: Option<String>,
1113
    pub signer: Option<String>,
97fc47fe Andy McCall ↶ 1114
    /// The asset's SLSA provenance, signed by the hub (oxygenhub#239):
1115
    /// `cosign verify-blob-attestation --key …/.well-known/oxyhub-signing.pem
d2c1d6a7 Andy McCall ↶ 1116
    /// --type slsaprovenance1 --insecure-ignore-tlog=true --signature PROVENANCE ASSET`. `None` when the
97fc47fe Andy McCall ↶ 1117
    /// receipt was not signed.
1118
    #[serde(default)]
1119
    pub provenance_url: Option<String>,
3f4b0ea6 Andy McCall ↶ 1120
}
1121
739a763a Andy McCall ↶ 1122
/// `PATCH /repos/{o}/{n}/proposals/{number}`: what is given changes,
1123
/// the rest stays (oxygenhub#76).
1124
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5a9a6e9a Andy McCall ↶ 1125
#[serde(deny_unknown_fields)]
739a763a Andy McCall ↶ 1126
pub struct ProposalEdit {
1127
    #[serde(default, skip_serializing_if = "Option::is_none")]
1128
    pub title: Option<String>,
1129
    #[serde(default, skip_serializing_if = "Option::is_none")]
1130
    pub body: Option<String>,
2291f8cc Andy McCall ↶ 1131
    /// The whole set of labels, by name (triage); oxygenhub#80.
1132
    #[serde(default, skip_serializing_if = "Option::is_none")]
1133
    pub labels: Option<Vec<String>>,
09ffa7b6 Andy McCall ↶ 1134
    /// `closed`, `open` (reopen a closed one, or make a draft ready for
1135
    /// review) or `draft` (turn an open one back into a draft), by its
1136
    /// author or with triage access, as the page's buttons do
1137
    /// (oxygenhub#140, #313).
71e65fcf Andy McCall ↶ 1138
    #[serde(default, skip_serializing_if = "Option::is_none")]
1139
    pub state: Option<String>,
09ffa7b6 Andy McCall ↶ 1140
    /// `false` makes a draft ready for review, `true` turns an open
1141
    /// proposal back into a draft: the same as `state`, in the words a
1142
    /// proposal is created with (#313).
1143
    #[serde(default, skip_serializing_if = "Option::is_none")]
1144
    pub draft: Option<bool>,
739a763a Andy McCall ↶ 1145
}
1146
ced6d3af Andy McCall ↶ 1147
/// `PATCH /repos/{owner}/{name}/releases/{tag}`: what to change; fields
1148
/// left out stay as they are.
1149
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5a9a6e9a Andy McCall ↶ 1150
#[serde(deny_unknown_fields)]
ced6d3af Andy McCall ↶ 1151
pub struct ReleaseEdit {
1152
    #[serde(default, skip_serializing_if = "Option::is_none")]
1153
    pub title: Option<String>,
1154
    #[serde(default, skip_serializing_if = "Option::is_none")]
1155
    pub notes: Option<String>,
1156
    #[serde(default, skip_serializing_if = "Option::is_none")]
1157
    pub prerelease: Option<bool>,
1158
}
1159
166f6e9b Andy McCall 1160
/// A drop (oxygenhub#279): a small snippet of one or more files, its own
1161
/// Oxygen repository, never listed among repositories. `GET /drops` lists
1162
/// yours, `GET /users/{name}/drops` someone's public ones, and
1163
/// `GET /drops/{id}` one with its files' content.
3f4b0ea6 Andy McCall ↶ 1164
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
166f6e9b Andy McCall 1165
pub struct Drop {
1166
    /// 24 hex digits, unique on the hub.
1167
    pub id: String,
1168
    pub owner: String,
1169
    pub title: String,
1170
    pub description: String,
1171
    /// `public` (listed on its owner's Drops page) or `secret` (unlisted:
1172
    /// readable by anyone with its address).
1173
    pub visibility: String,
1174
    /// The drop's page.
1175
    pub url: String,
1176
    /// What `oxy clone` takes.
1177
    pub clone_url: String,
1178
    pub created_ms: i64,
1179
    pub updated_ms: i64,
1180
    pub files: Vec<DropFile>,
1181
}
1182
1183
/// One of a drop's files. Lists carry no content; one drop's view carries
1184
/// the content of each text file up to 512 KiB.
1185
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1186
pub struct DropFile {
1187
    pub name: String,
1188
    pub size: u64,
1189
    #[serde(default, skip_serializing_if = "Option::is_none")]
1190
    pub content: Option<String>,
1191
    /// The file's bytes on the default bookmark.
1192
    pub raw_url: String,
1193
}
1194
1195
/// `POST /drops`: a new drop with at least one file.
1196
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1197
pub struct NewDrop {
1198
    #[serde(default)]
1199
    pub title: String,
1200
    #[serde(default)]
1201
    pub description: String,
1202
    /// Unlisted, readable by anyone with its address.
1203
    #[serde(default)]
1204
    pub secret: bool,
1205
    pub files: Vec<NewDropFile>,
1206
}
1207
1208
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1209
pub struct NewDropFile {
1210
    pub name: String,
1211
    pub content: String,
1212
}
1213
1214
/// `PATCH /drops/{id}`: what to change; what is left out stays.
1215
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5a9a6e9a Andy McCall ↶ 1216
#[serde(deny_unknown_fields)]
166f6e9b Andy McCall 1217
pub struct DropEdit {
1218
    #[serde(default, skip_serializing_if = "Option::is_none")]
1219
    pub title: Option<String>,
1220
    #[serde(default, skip_serializing_if = "Option::is_none")]
1221
    pub description: Option<String>,
1222
    #[serde(default, skip_serializing_if = "Option::is_none")]
1223
    pub secret: Option<bool>,
1224
    /// Files to write, or to remove (`content` null); others are kept.
1225
    #[serde(default)]
1226
    pub files: Vec<DropFileEdit>,
1227
    /// The change's message (default "Edit TITLE").
1228
    #[serde(default, skip_serializing_if = "Option::is_none")]
1229
    pub message: Option<String>,
1230
}
1231
1232
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5a9a6e9a Andy McCall ↶ 1233
#[serde(deny_unknown_fields)]
166f6e9b Andy McCall 1234
pub struct DropFileEdit {
1235
    pub name: String,
1236
    #[serde(default)]
1237
    pub content: Option<String>,
1238
}
1239
ba0a55bb Andy McCall ↶ 1240
/// `POST …/tags` (#295): tag the state of `target` (a bookmark, tag or
1241
/// change; the default bookmark when absent).
166f6e9b Andy McCall 1242
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
ba0a55bb Andy McCall ↶ 1243
pub struct NewTag {
1244
    pub name: String,
1245
    #[serde(default)]
1246
    pub target: Option<String>,
1247
    #[serde(default)]
1248
    pub message: Option<String>,
1249
}
1250
1251
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
3f4b0ea6 Andy McCall ↶ 1252
pub struct NewRelease {
1253
    pub tag: String,
1254
    pub title: String,
1255
    #[serde(default)]
1256
    pub notes: Option<String>,
1257
    #[serde(default)]
1258
    pub prerelease: bool,
1259
}
1260
eb2a3502 Andy McCall ↶ 1261
/// `GET /repos/{o}/{n}/diffusion` (oxygenhub#153): what a repository
1262
/// takes from (the subrepos it pins) and what it diffuses to (the
1263
/// repositories that pin it), each as the Diffusion pages show it.
1264
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1265
pub struct Diffusion {
1266
    pub takes_from: Vec<DiffusionPin>,
1267
    pub diffuses_to: Vec<DiffusionPin>,
1268
}
1269
1270
/// One pin of an upstream by a consumer, both named `owner/name`.
1271
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1272
pub struct DiffusionPin {
1273
    pub upstream: String,
1274
    pub consumer: String,
1275
    /// Where the consumer pins it.
1276
    pub path: String,
1277
    /// The consumer's bookmark its bumps land on.
1278
    pub bookmark: String,
1279
    /// Upstream changes the pin lacks; absent when the hub cannot tell.
1280
    #[serde(default)]
1281
    pub behind: Option<u64>,
1282
    /// `off`, `green` or `any`.
1283
    pub follow: String,
1284
    /// The open bump proposal's number, on the consumer.
1285
    #[serde(default)]
1286
    pub bump: Option<i64>,
1287
    /// The newest run of the bump: number and status.
1288
    #[serde(default)]
1289
    pub run: Option<i64>,
1290
    #[serde(default)]
1291
    pub run_status: Option<String>,
1292
    /// The pill: the upstream's half, then the consumer's.
1293
    pub upstream_state: DiffusionHalf,
1294
    pub consumer_state: DiffusionHalf,
1295
}
1296
1297
/// One half of the Diffusion pill.
1298
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1299
pub struct DiffusionHalf {
1300
    /// `green`, `amber`, `red`, `grey` or `off`.
1301
    pub tone: String,
1302
    /// What the pill says: `checked`, `untested`, `passes`, `up to date`…
1303
    pub word: String,
1304
    /// The sentence behind it.
1305
    pub title: String,
1306
}
1307
b64e2537 Andy McCall ↶ 1308
/// Every type of the API, for schema generation.
1309
pub fn schemas() -> Vec<(&'static str, schemars::Schema)> {
1310
    vec![
1311
        ("Repository", schemars::schema_for!(Repository)),
eb2a3502 Andy McCall ↶ 1312
        ("Diffusion", schemars::schema_for!(Diffusion)),
1313
        ("DiffusionPin", schemars::schema_for!(DiffusionPin)),
1314
        ("DiffusionHalf", schemars::schema_for!(DiffusionHalf)),
b64e2537 Andy McCall ↶ 1315
        ("Visibility", schemars::schema_for!(Visibility)),
1316
        ("Bookmark", schemars::schema_for!(Bookmark)),
1317
        ("Tag", schemars::schema_for!(Tag)),
1318
        ("ChangeSummary", schemars::schema_for!(ChangeSummary)),
1319
        ("Author", schemars::schema_for!(Author)),
1320
        ("Signature", schemars::schema_for!(Signature)),
1321
        ("Problem", schemars::schema_for!(Problem)),
1322
        ("Proposal", schemars::schema_for!(Proposal)),
1323
        ("ProposalState", schemars::schema_for!(ProposalState)),
1324
        ("ProposalSource", schemars::schema_for!(ProposalSource)),
1325
        ("Approval", schemars::schema_for!(Approval)),
1326
        ("Issue", schemars::schema_for!(Issue)),
1327
        ("Label", schemars::schema_for!(Label)),
1328
        ("Milestone", schemars::schema_for!(Milestone)),
5ea4872f Andy McCall ↶ 1329
        ("NewMilestone", schemars::schema_for!(NewMilestone)),
1330
        ("MilestoneEdit", schemars::schema_for!(MilestoneEdit)),
b64e2537 Andy McCall ↶ 1331
        ("Comment", schemars::schema_for!(Comment)),
3f02e5ea Andy McCall ↶ 1332
        ("ProposalFile", schemars::schema_for!(ProposalFile)),
42a0ba4b Andy McCall ↶ 1333
        ("Notification", schemars::schema_for!(Notification)),
1334
        ("Inbox", schemars::schema_for!(Inbox)),
b64e2537 Andy McCall ↶ 1335
        ("Atom", schemars::schema_for!(Atom)),
1336
        ("Review", schemars::schema_for!(Review)),
1337
        ("TreeEntry", schemars::schema_for!(TreeEntry)),
1338
        ("BlameLine", schemars::schema_for!(BlameLine)),
1339
        ("FileChange", schemars::schema_for!(FileChange)),
1340
        ("ChangeDetail", schemars::schema_for!(ChangeDetail)),
1341
        ("History", schemars::schema_for!(History)),
1342
        ("Conflict", schemars::schema_for!(Conflict)),
1343
        ("Push", schemars::schema_for!(Push)),
1344
        ("Trust", schemars::schema_for!(Trust)),
1345
        ("Policy", schemars::schema_for!(Policy)),
1346
        ("Rule", schemars::schema_for!(Rule)),
1347
        ("Hook", schemars::schema_for!(Hook)),
1348
        ("NewHook", schemars::schema_for!(NewHook)),
1349
        ("Check", schemars::schema_for!(Check)),
1350
        ("CheckStatus", schemars::schema_for!(CheckStatus)),
1351
        ("NewCheck", schemars::schema_for!(NewCheck)),
1352
        ("User", schemars::schema_for!(User)),
1353
        ("Organisation", schemars::schema_for!(Organisation)),
1354
        ("NewRepository", schemars::schema_for!(NewRepository)),
1355
        ("NewIssue", schemars::schema_for!(NewIssue)),
76f262e1 Andy McCall ↶ 1356
        ("IssueEdit", schemars::schema_for!(IssueEdit)),
2291f8cc Andy McCall ↶ 1357
        ("ReleaseEdit", schemars::schema_for!(ReleaseEdit)),
1358
        ("ProposalEdit", schemars::schema_for!(ProposalEdit)),
76f262e1 Andy McCall ↶ 1359
        ("NewLabel", schemars::schema_for!(NewLabel)),
961c10be Andy McCall ↶ 1360
        ("RequiredChecks", schemars::schema_for!(RequiredChecks)),
ef20fdc1 Andy McCall ↶ 1361
        ("Project", schemars::schema_for!(Project)),
1362
        ("ProjectCard", schemars::schema_for!(ProjectCard)),
1363
        ("ProjectColumn", schemars::schema_for!(ProjectColumn)),
1364
        ("Board", schemars::schema_for!(Board)),
1365
        ("NewProject", schemars::schema_for!(NewProject)),
1366
        ("ProjectEdit", schemars::schema_for!(ProjectEdit)),
1367
        ("NewCard", schemars::schema_for!(NewCard)),
1368
        ("CardMove", schemars::schema_for!(CardMove)),
b64e2537 Andy McCall ↶ 1369
        ("NewComment", schemars::schema_for!(NewComment)),
1370
        ("NewProposal", schemars::schema_for!(NewProposal)),
1371
        ("NewReview", schemars::schema_for!(NewReview)),
1372
        ("IssueStateChange", schemars::schema_for!(IssueStateChange)),
1373
        ("WebhookEnvelope", schemars::schema_for!(WebhookEnvelope)),
1374
        ("ProposalEvent", schemars::schema_for!(ProposalEvent)),
3f4b0ea6 Andy McCall ↶ 1375
        ("Release", schemars::schema_for!(Release)),
bf1ab345 Andy McCall ↶ 1376
        ("FlowRun", schemars::schema_for!(FlowRun)),
1377
        ("FlowJob", schemars::schema_for!(FlowJob)),
1378
        ("FlowLogLine", schemars::schema_for!(FlowLogLine)),
1379
        ("AssetBuild", schemars::schema_for!(AssetBuild)),
3f4b0ea6 Andy McCall ↶ 1380
        ("ReleaseAsset", schemars::schema_for!(ReleaseAsset)),
1381
        ("NewRelease", schemars::schema_for!(NewRelease)),
166f6e9b Andy McCall 1382
        ("Drop", schemars::schema_for!(Drop)),
1383
        ("NewDrop", schemars::schema_for!(NewDrop)),
1384
        ("DropEdit", schemars::schema_for!(DropEdit)),
b64e2537 Andy McCall ↶ 1385
    ]
1386
}
b66e70b7 Andy McCall ↶ 1387
1388
/// An OxygenFlow runner (`GET /api/v1/runners`, site administrators).
1389
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1390
pub struct Runner {
1391
    pub id: i64,
1392
    pub name: String,
1393
    /// `online`, `offline`, `draining` or `disabled`.
1394
    pub status: String,
1395
    /// What it serves: empty for the whole site, an owner, or `owner/name`.
1396
    pub serves: String,
1397
    pub arch: String,
1398
    pub os: String,
1399
    pub version: String,
1400
    pub labels: Vec<String>,
1401
    pub max_jobs: i64,
1402
    pub memory_mib: Option<i64>,
1403
    pub cpus: Option<i64>,
1404
    /// The key that signs its receipts (KeyId hex), empty until bound.
1405
    pub key: String,
1406
    /// `registered` or `config` (a hub.toml token).
1407
    pub source: String,
1408
    pub last_seen_ms: Option<i64>,
1409
    /// Jobs it is running now.
1410
    pub running: i64,
2fb70d01 Andy McCall ↶ 1411
    /// What it measured at its last claim (oxygenflow#40): free disk in
1412
    /// MiB, the 1-minute load ×100, its speed score (100 on the reference
1413
    /// machine) and class 1–5, its kernel.
1414
    #[serde(default, skip_serializing_if = "Option::is_none")]
1415
    pub free_disk_mib: Option<i64>,
1416
    #[serde(default, skip_serializing_if = "Option::is_none")]
1417
    pub load_x100: Option<i64>,
1418
    #[serde(default, skip_serializing_if = "Option::is_none")]
1419
    pub speed: Option<i64>,
1420
    #[serde(default, skip_serializing_if = "Option::is_none")]
1421
    pub speed_class: Option<i64>,
1422
    #[serde(default, skip_serializing_if = "String::is_empty")]
1423
    pub kernel: String,
b66e70b7 Andy McCall ↶ 1424
}
1425
1426
/// A job a runner ran or is running.
1427
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1428
pub struct RunnerJob {
1429
    pub repo: String,
1430
    pub run: i64,
1431
    pub job: String,
1432
    pub status: String,
1433
    pub started_ms: Option<i64>,
1434
    pub finished_ms: Option<i64>,
1435
}
1436
1437
/// A job in the queue: running ones first, then queued ones in the order
1438
/// runners claim them.
1439
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1440
pub struct QueueItem {
1441
    pub repo: String,
1442
    pub run: i64,
1443
    pub job: String,
1444
    /// `running` or `queued`.
1445
    pub status: String,
1446
    /// The runner holding it, when running.
1447
    pub runner: String,
1448
}
62ceb2ee Andy McCall ↶ 1449
1450
// ------------------------------------------------------------- assistants
1451
1452
/// An AI assistant at a level (hub spec §13.4). The token never leaves the
1453
/// hub: `has_token` says whether one is set.
1454
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1455
pub struct Assistant {
1456
    pub name: String,
1457
    pub endpoint: String,
1458
    pub api: String,
1459
    pub model: String,
1460
    #[serde(default, skip_serializing_if = "String::is_empty")]
1461
    pub headers: String,
1462
    pub enabled: bool,
1463
    pub budget: i64,
1464
    pub has_token: bool,
1465
    /// Where it comes from: empty for the level's own, else `the site` or
1466
    /// `the NAME organisation`.
1467
    #[serde(default, skip_serializing_if = "String::is_empty")]
1468
    pub from: String,
1469
    /// Off because a level above turned a name like it off.
1470
    #[serde(default)]
1471
    pub off_above: bool,
1472
}
1473
1474
/// `POST …/assistants`: add one, or change the one of that name. A
1475
/// `preset` (`anthropic`, `openai`, `gemini`, `deepseek`, `mistral`,
1476
/// `perplexity`, `ollama`) fills what is left out; the model must be one
1477
/// the endpoint lists when it lists any; `token` is write-only.
1478
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1479
pub struct NewAssistant {
1480
    #[serde(default)]
1481
    pub name: String,
1482
    #[serde(default)]
1483
    pub preset: String,
1484
    #[serde(default)]
1485
    pub endpoint: String,
1486
    #[serde(default)]
1487
    pub api: String,
1488
    pub model: String,
1489
    #[serde(default)]
1490
    pub token: String,
1491
    #[serde(default)]
1492
    pub headers: String,
1493
    #[serde(default = "yes")]
1494
    pub enabled: bool,
1495
    #[serde(default)]
1496
    pub budget: Option<i64>,
1497
}
1498
1499
fn yes() -> bool {
1500
    true
1501
}
1502
1503
/// A level's prompt and those it inherits, outermost first.
1504
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1505
pub struct AssistantPrompt {
1506
    pub prompt: String,
1507
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1508
    pub inherited: Vec<(String, String)>,
1509
}
617c2840 Andy McCall ↶ 1510
1511
/// `GET /repos/{o}/{n}/coverage`: a coverage report from a Flow job
1512
/// (oxygenhub#113); `percent` values are of lines, functions and branches,
1513
/// absent when nothing was counted.
1514
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1515
pub struct CoverageReport {
1516
    pub id: i64,
1517
    pub run: i64,
1518
    pub job: String,
1519
    pub bookmark: String,
1520
    /// The run's state, by hash.
1521
    pub state: String,
1522
    /// `lcov` or `cobertura`.
1523
    pub format: String,
1524
    pub lines_found: i64,
1525
    pub lines_hit: i64,
1526
    pub percent: Option<f64>,
1527
    pub functions_found: i64,
1528
    pub functions_hit: i64,
1529
    pub branches_found: i64,
1530
    pub branches_hit: i64,
1531
    pub files: i64,
1532
    /// Files the report named that are not in the run's state.
1533
    pub dropped: i64,
1534
    pub created_ms: i64,
1535
    /// The report on the hub's Coverage tab, absolute.
1536
    pub url: String,
40dd3f86 Andy McCall ↶ 1537
    /// Who uploaded it from a workstation (#136), when no Flow job made it;
1538
    /// `run` and `job` are then 0 and "upload".
1539
    #[serde(default, skip_serializing_if = "Option::is_none")]
1540
    pub uploaded_by: Option<String>,
617c2840 Andy McCall ↶ 1541
}
1542
1543
/// One file of a coverage report.
1544
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1545
pub struct CoverageFile {
1546
    pub path: String,
1547
    pub lines_found: i64,
1548
    pub lines_hit: i64,
1549
    pub percent: Option<f64>,
1550
    pub functions_found: i64,
1551
    pub functions_hit: i64,
1552
    pub branches_found: i64,
1553
    pub branches_hit: i64,
1554
}
1555
1556
/// `GET /repos/{o}/{n}/coverage/{id}`: a report with its files.
1557
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1558
pub struct CoverageDetail {
1559
    pub report: CoverageReport,
1560
    pub files: Vec<CoverageFile>,
1561
}
1562
1563
/// `GET /repos/{o}/{n}/tests`: a JUnit test report from a Flow job
1564
/// (oxygenhub#114).
1565
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1566
pub struct TestReport {
1567
    pub id: i64,
1568
    pub run: i64,
1569
    pub job: String,
1570
    pub bookmark: String,
1571
    pub state: String,
1572
    pub tests: i64,
1573
    pub passed: i64,
1574
    pub failed: i64,
1575
    pub errors: i64,
1576
    pub skipped: i64,
1577
    /// The cases' times added up.
1578
    pub time_ms: i64,
1579
    pub created_ms: i64,
1580
    pub url: String,
1581
}
1582
1583
/// One test case of a report.
1584
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1585
pub struct TestCase {
1586
    pub suite: String,
1587
    pub classname: String,
1588
    pub name: String,
1589
    /// `passed`, `failed`, `error` or `skipped`.
1590
    pub status: String,
1591
    pub time_ms: i64,
1592
    pub message: String,
1593
    /// A failure's text and output, cut to 16 KiB; empty for a pass.
1594
    pub output: String,
1595
}
1596
1597
/// `GET /repos/{o}/{n}/tests/{id}`: a report with its cases
1598
/// (`?status=failed` for the failed and errored ones).
1599
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1600
pub struct TestReportDetail {
1601
    pub report: TestReport,
1602
    pub cases: Vec<TestCase>,
1603
}
9bbca80f Andy McCall ↶ 1604
1605
/// `GET /api/v1/admin/runner-updates` (oxygenhub#322): where runner builds
1606
/// come from, every level's settings, the test groups, each runner's policy
1607
/// and what it is offered, and the builds held back (#326). Site
1608
/// administrators only.
1609
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1610
pub struct RunnerUpdates {
1611
    /// The repository whose releases carry runner builds (`owner/name`).
1612
    pub repo: String,
1613
    pub settings: Vec<UpdateSetting>,
1614
    pub groups: Vec<RunnerGroup>,
1615
    pub runners: Vec<RunnerUpdate>,
1616
    pub holds: Vec<HeldBuild>,
1617
}
1618
1619
/// One level's update settings; `None` inherits from the next level out.
1620
/// `PUT /api/v1/admin/runner-updates/settings` takes one.
1621
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1622
pub struct UpdateSetting {
1623
    /// `site`, `owner`, `group` or `runner`.
1624
    pub scope: String,
1625
    /// Empty for the site; the owner's name, the group's id, the runner's id.
1626
    #[serde(default)]
1627
    pub key: String,
1628
    #[serde(default)]
1629
    pub updates: Option<bool>,
1630
    /// `stable`, `canary` or a version.
1631
    #[serde(default)]
1632
    pub channel: Option<String>,
1633
    /// Hours (UTC) in which updates may start, `02-05`.
1634
    #[serde(default)]
1635
    pub window: Option<String>,
1636
    #[serde(default)]
1637
    pub dry_run: Option<bool>,
1638
}
1639
1640
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1641
pub struct RunnerGroup {
1642
    pub id: i64,
1643
    /// Empty for a group of the site's runners.
1644
    pub owner: String,
1645
    pub name: String,
1646
    /// A share of the runners in reach; `None`: chosen ones.
1647
    pub percent: Option<i64>,
1648
    /// Its runners now, by name.
1649
    pub members: Vec<String>,
1650
}
1651
1652
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1653
pub struct RunnerUpdate {
1654
    pub id: i64,
1655
    pub name: String,
1656
    /// The owner it serves; empty for the site's.
1657
    pub owner: String,
1658
    pub version: String,
1659
    pub groups: Vec<String>,
1660
    pub updates: bool,
1661
    pub channel: String,
1662
    #[serde(default)]
1663
    pub window: Option<String>,
1664
    pub dry_run: bool,
1665
    /// Where each setting came from, in the order updates, channel, window, dry run.
1666
    pub from: Vec<String>,
1667
    /// What the hub would offer it now, in words.
1668
    pub now: String,
1669
    /// What it last said about its update.
1670
    pub said: String,
1671
}
1672
1673
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1674
pub struct HeldBuild {
1675
    pub version: String,
1676
    pub runner: String,
1677
    pub why: String,
1678
    pub at_ms: i64,
1679
}