OXYGENHUB
# f2d2776b2a14 oxygenhub / crates / hub-api / src / lib.rs
68.6 KiB · Rust · last changed Board charts and forecasts from the board's history, and its timeline (closes #357, closes #361) 1 day 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,
fac6853c Andy McCall ↶ 609
    /// When it entered the queue (made, or run again), and when a runner
610
    /// claimed it: its wait is `started_ms - queued_ms` (oxygenhub#348).
611
    #[serde(default, skip_serializing_if = "Option::is_none")]
612
    pub queued_ms: Option<i64>,
613
    #[serde(default, skip_serializing_if = "Option::is_none")]
614
    pub ready_ms: Option<i64>,
615
    /// Where its time went, as its runner reported (oxygenflow#35):
616
    /// `image`, `prepare`, `run` and `finish`, in that order.
617
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
618
    pub phases: Vec<FlowPhase>,
619
    /// The most disk and memory it took, as its runner reported, in MiB.
620
    #[serde(default, skip_serializing_if = "Option::is_none")]
621
    pub peak_disk_mib: Option<i64>,
622
    #[serde(default, skip_serializing_if = "Option::is_none")]
623
    pub peak_memory_mib: Option<i64>,
624
}
625
626
/// A phase of a job and its milliseconds.
627
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
628
pub struct FlowPhase {
629
    pub name: String,
630
    pub ms: u64,
631
}
632
633
/// A report: what a Flow job published (OxygenFlow `output { report … }`)
634
/// or an upload, as docs/reports.md describes (oxygenhub#348).
635
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
636
pub struct Report {
637
    /// Its id, as the web page's `?id=` carries it.
638
    pub id: i64,
639
    /// The name the pipeline gave it (`report "frame-timing"`).
640
    pub name: String,
641
    /// `coverage`, `tests`, `performance` or `custom`.
642
    pub kind: String,
643
    pub title: String,
644
    pub summary: String,
645
    pub metrics: Vec<ReportMetric>,
646
    /// Its `[context]` table.
647
    pub context: serde_json::Value,
648
    /// The run and job that published it; none for an upload.
649
    pub run: Option<i64>,
650
    pub job: String,
651
    pub bookmark: String,
652
    /// The state it measured.
653
    pub state: String,
654
    /// How many files it has and their size together.
655
    pub files: i64,
656
    pub bytes: i64,
657
    pub created_ms: i64,
658
    /// When its files expired under retention (docs/reports.md §3.3): its
659
    /// metrics stay, its files are gone.
660
    pub files_expired_ms: Option<i64>,
661
    /// Its page on the hub.
662
    pub url: String,
663
    /// Its files, filled when one report is asked for.
664
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
665
    pub manifest: Vec<ReportFile>,
666
}
667
668
/// A metric of a report.
669
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
670
pub struct ReportMetric {
671
    pub key: String,
672
    pub value: f64,
673
    pub unit: String,
674
    /// `lower`, `higher`, or empty.
675
    pub better: String,
676
    pub fail_above: Option<f64>,
677
    pub fail_below: Option<f64>,
678
}
679
680
/// A file of a report.
681
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
682
pub struct ReportFile {
683
    pub path: String,
684
    pub size: i64,
90326c96 Andy McCall ↶ 685
}
686
687
/// A line of a job's log.
688
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
689
pub struct FlowLogLine {
690
    /// Increasing within the job; pass the last one as `after` for more.
691
    pub seq: i64,
692
    /// Milliseconds since the job started.
693
    pub t: i64,
694
    /// `stdout`, `stderr` or `flow` (the runner's own notes).
695
    pub stream: String,
696
    pub text: String,
697
}
698
b64e2537 Andy McCall ↶ 699
/// A check on a state hash (hub spec §13.1).
700
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
701
pub struct Check {
702
    pub state: String,
703
    pub name: String,
704
    pub status: CheckStatus,
705
    pub summary: String,
706
    pub url: String,
707
    pub reporter: String,
708
    /// The seal attestation's reference when the checker sealed the changes.
709
    pub seal: Option<String>,
710
    pub started_ms: i64,
711
    pub finished_ms: Option<i64>,
712
}
713
714
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
715
#[serde(rename_all = "lowercase")]
716
pub enum CheckStatus {
717
    Queued,
718
    Running,
719
    Passed,
720
    Failed,
721
    Cancelled,
722
    Skipped,
723
}
724
725
impl CheckStatus {
726
    pub fn as_str(self) -> &'static str {
727
        match self {
728
            CheckStatus::Queued => "queued",
729
            CheckStatus::Running => "running",
730
            CheckStatus::Passed => "passed",
731
            CheckStatus::Failed => "failed",
732
            CheckStatus::Cancelled => "cancelled",
733
            CheckStatus::Skipped => "skipped",
734
        }
735
    }
736
737
    pub fn parse(s: &str) -> Option<CheckStatus> {
738
        Some(match s {
739
            "queued" => CheckStatus::Queued,
740
            "running" => CheckStatus::Running,
741
            "passed" => CheckStatus::Passed,
742
            "failed" => CheckStatus::Failed,
743
            "cancelled" => CheckStatus::Cancelled,
744
            "skipped" => CheckStatus::Skipped,
745
            _ => return None,
746
        })
747
    }
748
}
749
750
/// What a checker posts.
751
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
752
pub struct NewCheck {
753
    pub state: String,
754
    pub name: String,
755
    pub status: CheckStatus,
756
    #[serde(default)]
757
    pub summary: String,
758
    #[serde(default)]
759
    pub url: String,
760
    /// Hex of a seal attestation reference the checker pushed, if any.
761
    #[serde(default)]
762
    pub seal: Option<String>,
763
}
764
765
// ------------------------------------------------------------- accounts
766
767
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
768
pub struct User {
769
    pub username: String,
770
    pub display_name: String,
771
    pub is_admin: bool,
772
    pub keys: Vec<String>,
773
    pub created_ms: i64,
774
}
775
776
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
777
pub struct Organisation {
778
    pub name: String,
779
    pub display_name: String,
780
    pub description: String,
781
    pub members: Vec<String>,
ecac6e8d Andy McCall ↶ 782
}
783
5714347a Andy McCall ↶ 784
/// `POST /user/runner-token`: a one-time token that registers a runner for
785
/// the caller's own repositories, as a phone does when its owner offers it
786
/// as a runner (oxygenhub-android#8). Spent by `flow runner register` (or
787
/// the app), within 24 hours.
788
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
789
pub struct RunnerToken {
790
    pub token: String,
791
    /// Whose repositories the runner will serve.
792
    pub owner: String,
793
}
794
f4e13830 Andy McCall ↶ 795
/// `GET /user/proposals`: the caller's proposals to act on, as the web
796
/// dashboard lists them: open ones by others in repositories they belong
797
/// to that they have not reviewed yet, and their own open and draft ones.
798
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
799
pub struct UserProposals {
800
    pub review: Vec<ProposalBrief>,
801
    pub authored: Vec<ProposalBrief>,
5d818ec7 Andy McCall ↶ 802
    /// With `?landable=true` (#311): the open proposals the caller could
803
    /// land now, in repositories they can write to, with no blockers.
804
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
805
    pub landable: Vec<ProposalBrief>,
806
}
807
4dfa4599 Andy McCall ↶ 808
/// `GET /user/sky` (oxygenhub-android#23): Your sky's data, as the web
809
/// dashboard's backdrop reads it (docs/backgrounds.md §5): the caller's
810
/// repositories, newest-updated first, and their events of the last 30
811
/// days, newest first.
851a26a2 Andy McCall ↶ 812
/// `GET /repos/{owner}/{name}/sky` gives one repository's in the same shape.
4dfa4599 Andy McCall ↶ 813
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
814
pub struct UserSky {
815
    /// The hub's clock (milliseconds), to age the events by.
816
    pub now: i64,
817
    /// `owner/name` of each repository.
818
    pub repos: Vec<String>,
819
    /// `[repo, kind, at_ms, n]`: an index into `repos`; kind 0 a push of
820
    /// `n` changes, 1 a proposal event, 2 an issue event, 3 a release, 4 a
821
    /// Flow run.
822
    pub events: Vec<[i64; 4]>,
823
}
824
3d086bc3 Andy McCall ↶ 825
/// `GET /user/flow/runs` (oxygenhub-android#26): a run of one of the
826
/// caller's repositories, with its jobs, for a monitor across them all.
827
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
828
pub struct UserFlowRun {
829
    /// `owner/name`.
830
    pub repository: String,
831
    #[serde(flatten)]
832
    pub run: FlowRun,
833
}
834
835
/// `GET /user/flow/runs` query: `before` (created before, ms) pages back.
836
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
837
pub struct UserFlowRunsQuery {
838
    #[serde(default)]
839
    pub limit: Option<i64>,
840
    #[serde(default)]
841
    pub before: Option<i64>,
842
}
843
844
/// `GET /user/starter?owner=X` (#347): the assistants a new repository
845
/// under `owner` may ask for its starting files; empty when none is set up
846
/// or the caller cannot create there.
847
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
848
pub struct StarterAssistants {
849
    pub assistants: Vec<StarterAssistant>,
850
}
851
852
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
853
pub struct StarterAssistant {
854
    pub name: String,
855
    pub model: String,
856
    /// `the site` or `the acme organisation`.
857
    pub from: String,
858
}
859
860
/// `POST /repos/{owner}/{name}/starter`: what to make, and which assistant
861
/// (the first available when not given).
862
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
863
pub struct StarterRequest {
864
    pub description: String,
865
    #[serde(default)]
866
    pub assistant: Option<String>,
867
}
868
869
/// Where a repository's starter stands: `running`, `done` (with the
870
/// change and its files), `failed` (with why), or `none`.
871
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
872
pub struct StarterStatus {
873
    pub status: String,
874
    #[serde(default, skip_serializing_if = "String::is_empty")]
875
    pub assistant: String,
876
    #[serde(default, skip_serializing_if = "String::is_empty")]
877
    pub change: String,
878
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
879
    pub files: Vec<String>,
880
    #[serde(default, skip_serializing_if = "String::is_empty")]
881
    pub error: String,
882
}
883
8f1d76f4 Andy McCall ↶ 884
/// An issue in a list across repositories: `GET /user/issues` (#359),
885
/// the open issues assigned to the caller, newest-updated first.
886
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
887
pub struct IssueBrief {
888
    /// `owner/name`.
889
    pub repository: String,
890
    pub number: i64,
891
    pub title: String,
892
    pub updated_ms: i64,
893
    /// `https://hub/{owner}/{name}/issue/{number}`.
894
    pub url: String,
895
}
896
a22e4aec Andy McCall ↶ 897
/// `POST /user/authenticators` (oxygenhub#356): this phone as a second
898
/// factor. `public_key` is hex of the Keystore key's SubjectPublicKeyInfo
899
/// (or its bare uncompressed P-256 point); `code` is the account's current
900
/// authenticator-app code, which adding a phone needs.
901
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
902
pub struct NewAuthenticator {
903
    pub public_key: String,
904
    pub code: String,
905
}
906
907
/// A phone that approves sign-ins and sensitive actions for its account.
908
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
909
pub struct Authenticator {
910
    /// The sign-in (token) it belongs to: signing that phone out removes it.
911
    pub id: i64,
912
    pub name: String,
913
    pub created_ms: i64,
914
    /// When it last approved something; 0 for never.
915
    pub last_used_ms: i64,
916
    /// The caller's own phone.
917
    #[serde(default)]
918
    pub this: bool,
919
}
920
921
/// An approval waiting for the caller's phone (`GET /user/approvals`).
922
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
923
pub struct PendingApproval {
924
    pub id: String,
925
    /// `signin` or `stepup`.
926
    pub kind: String,
927
    /// What it is for: "Sign in from Firefox on Linux, 203.0.113.9".
928
    pub what: String,
929
    /// The three numbers to offer; the browser shows one of them.
930
    pub choices: Vec<i64>,
931
    pub created_ms: i64,
932
    pub expires_ms: i64,
933
}
934
935
/// `POST /user/approvals/{id}`: the phone's answer. To approve, `number`
936
/// is the one picked and `signature` the hex DER ECDSA signature, by the
937
/// phone's key, over `oxygenhub approval v1\n{id}\n{number}\napprove`.
938
/// A denial needs neither.
939
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
940
pub struct ApprovalAnswer {
941
    pub approve: bool,
942
    #[serde(default)]
943
    pub number: i64,
944
    #[serde(default)]
945
    pub signature: String,
946
}
947
5d818ec7 Andy McCall ↶ 948
/// `GET /user/proposals` query.
949
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
950
pub struct UserProposalsQuery {
951
    /// Also list what the caller can land now (slower: each proposal's
952
    /// projected state is worked out).
953
    #[serde(default)]
954
    pub landable: bool,
f4e13830 Andy McCall ↶ 955
}
956
957
/// A proposal in a list across repositories.
958
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
959
pub struct ProposalBrief {
960
    /// `owner/name`.
961
    pub repository: String,
962
    pub number: i64,
963
    pub title: String,
964
    pub author: String,
965
    pub state: ProposalState,
966
    pub conflicted: bool,
967
    pub updated_ms: i64,
968
    /// `https://hub/{owner}/{name}/proposal/{number}`.
969
    pub url: String,
970
}
971
ecac6e8d Andy McCall ↶ 972
/// `GET /user/orgs` (#302): an organisation the caller belongs to, and
973
/// their role there.
974
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
975
pub struct UserOrg {
976
    pub name: String,
977
    pub display_name: String,
978
    pub role: String,
b64e2537 Andy McCall ↶ 979
}
980
981
/// Forms accepted by the write endpoints.
982
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
983
pub struct NewRepository {
984
    pub owner: String,
985
    pub name: String,
986
    #[serde(default)]
987
    pub description: String,
988
    #[serde(default = "public")]
989
    pub visibility: Visibility,
990
}
991
992
fn public() -> Visibility {
993
    Visibility::Public
994
}
995
996
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
997
pub struct NewIssue {
998
    pub title: String,
999
    #[serde(default)]
1000
    pub body: String,
76f262e1 Andy McCall ↶ 1001
    /// Label names; each must exist. Needs triage.
1002
    #[serde(default)]
1003
    pub labels: Vec<String>,
1004
    /// Usernames. Needs triage.
1005
    #[serde(default)]
1006
    pub assignees: Vec<String>,
1007
    /// A milestone's title. Needs triage.
1008
    #[serde(default)]
1009
    pub milestone: Option<String>,
b64e2537 Andy McCall ↶ 1010
}
1011
76f262e1 Andy McCall ↶ 1012
/// `PATCH /repos/{o}/{n}/issues/{number}`: only the fields given change.
1013
/// Title and body: the author or triage. The rest: triage.
1014
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5a9a6e9a Andy McCall ↶ 1015
#[serde(deny_unknown_fields)]
76f262e1 Andy McCall ↶ 1016
pub struct IssueEdit {
1017
    #[serde(default)]
1018
    pub title: Option<String>,
1019
    #[serde(default)]
1020
    pub body: Option<String>,
1021
    /// The whole set of labels.
1022
    #[serde(default)]
1023
    pub labels: Option<Vec<String>>,
1024
    /// The whole set of assignees.
1025
    #[serde(default)]
1026
    pub assignees: Option<Vec<String>>,
1027
    /// A milestone's title; the empty string clears it.
1028
    #[serde(default)]
1029
    pub milestone: Option<String>,
1030
}
1031
961c10be Andy McCall ↶ 1032
/// The checks a proposal needs, passed, to land on the repository's
1033
/// default bookmark (hub spec §13.1). `GET` and `PUT
1034
/// /repos/{o}/{n}/checks/required`.
1035
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1036
pub struct RequiredChecks {
1037
    pub names: Vec<String>,
1038
}
1039
ef20fdc1 Andy McCall ↶ 1040
/// A project (hub spec §8.2).
1041
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1042
pub struct Project {
1043
    pub owner: String,
1044
    pub number: i64,
1045
    pub title: String,
1046
    pub description: String,
1047
    pub public: bool,
1048
    pub closed: bool,
1049
    pub updated_ms: i64,
1050
    /// The board on the hub, absolute.
1051
    pub url: String,
1052
}
1053
1054
/// A card as the caller may see it.
1055
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1056
pub struct ProjectCard {
1057
    pub id: i64,
1058
    /// `issue`, `proposal` or `note`.
1059
    pub kind: String,
1060
    /// `owner/name#N`; empty for a note.
1061
    pub reference: String,
1062
    /// The issue's or proposal's title, or the note.
1063
    pub title: String,
1064
    /// The issue's or proposal's state; empty for a note.
1065
    pub state: String,
6a306cd0 Andy McCall ↶ 1066
    /// The issue's or proposal's label names (oxygenhub#293).
1067
    #[serde(default)]
1068
    pub labels: Vec<String>,
1069
    /// An issue's assignees' usernames.
1070
    #[serde(default)]
1071
    pub assignees: Vec<String>,
439ecd87 Andy McCall ↶ 1072
    /// When it was archived (ms), for an archived card (oxygenhub#293).
1073
    #[serde(default, skip_serializing_if = "Option::is_none")]
1074
    pub archived_ms: Option<i64>,
ef20fdc1 Andy McCall ↶ 1075
}
1076
1077
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1078
pub struct ProjectColumn {
1079
    pub id: i64,
1080
    pub name: String,
1081
    pub cards: Vec<ProjectCard>,
0bc95135 Andy McCall ↶ 1082
    /// Its work-in-progress limit, when it has one (#361).
1083
    #[serde(default, skip_serializing_if = "Option::is_none")]
1084
    pub wip_limit: Option<i64>,
ef20fdc1 Andy McCall ↶ 1085
}
1086
0bc95135 Andy McCall ↶ 1087
/// A board's saved view (#361): `GET /projects/{owner}/{n}?view=NAME`
1088
/// gives the board with its filter applied.
1089
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1090
pub struct ProjectView {
1091
    pub name: String,
1092
    /// `board` or `table`.
1093
    pub layout: String,
1094
    pub q: String,
1095
    #[serde(default)]
1096
    pub lane: String,
1097
    #[serde(default)]
1098
    pub sort: String,
1099
}
1100
f2d2776b Andy McCall ↶ 1101
/// `GET /projects/{owner}/{n}/charts` (#357): the board's charts and
1102
/// forecasts from its own history.
1103
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1104
pub struct BoardCharts {
1105
    /// The board's columns, in order.
1106
    pub columns: Vec<String>,
1107
    /// Cumulative flow: each day (YYYY-MM-DD) with its cards per column.
1108
    pub cumulative_flow: Vec<FlowDay>,
1109
    /// From leaving the first column to reaching Done, in days: median and
1110
    /// 85th percentile, over `finished` cards; absent before any.
1111
    #[serde(default, skip_serializing_if = "Option::is_none")]
1112
    pub cycle_time_median_days: Option<f64>,
1113
    #[serde(default, skip_serializing_if = "Option::is_none")]
1114
    pub cycle_time_p85_days: Option<f64>,
1115
    pub finished: usize,
1116
    /// Cards that reached Done each week, oldest first.
1117
    pub throughput: Vec<WeekCount>,
1118
    /// The open iteration's burn-down, when one is open.
1119
    #[serde(default, skip_serializing_if = "Option::is_none")]
1120
    pub burn_down: Option<BurnDown>,
1121
    pub forecasts: Vec<BoardForecast>,
1122
}
1123
1124
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1125
pub struct FlowDay {
1126
    pub day: String,
1127
    pub counts: Vec<usize>,
1128
}
1129
1130
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1131
pub struct WeekCount {
1132
    /// The week's first day.
1133
    pub week: String,
1134
    pub done: usize,
1135
}
1136
1137
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1138
pub struct BurnDown {
1139
    pub iteration: String,
1140
    pub first_day: String,
1141
    /// Each day so far: cards left and the scope.
1142
    pub left: Vec<usize>,
1143
    pub scope: Vec<usize>,
1144
}
1145
1146
/// When `remaining` cards are done, at 50% and 85% (YYYY-MM-DD), from
1147
/// `weeks_of_history` weeks of throughput; absent when none reached Done.
1148
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1149
pub struct BoardForecast {
1150
    pub scope: String,
1151
    pub remaining: usize,
1152
    pub weeks_of_history: usize,
1153
    #[serde(default, skip_serializing_if = "Option::is_none")]
1154
    pub p50: Option<String>,
1155
    #[serde(default, skip_serializing_if = "Option::is_none")]
1156
    pub p85: Option<String>,
1157
}
1158
306aec18 Andy McCall ↶ 1159
/// `POST /projects/{owner}/{n}/columns` (#366): a column at the right.
1160
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1161
pub struct NewColumn {
1162
    pub name: String,
1163
}
1164
1165
/// `PATCH /projects/{owner}/{n}/columns/{column}` (#366): rename it, move
1166
/// it to `position` (0 is the leftmost; past the end is the rightmost), or
1167
/// both. What is not given stays.
1168
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1169
pub struct ColumnEdit {
1170
    #[serde(default, skip_serializing_if = "Option::is_none")]
1171
    pub name: Option<String>,
1172
    #[serde(default, skip_serializing_if = "Option::is_none")]
1173
    pub position: Option<i64>,
1174
}
1175
ef20fdc1 Andy McCall ↶ 1176
/// `GET /projects/{owner}/{n}`.
1177
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1178
pub struct Board {
1179
    pub project: Project,
1180
    pub columns: Vec<ProjectColumn>,
0bc95135 Andy McCall ↶ 1181
    /// Its saved views (#361).
1182
    #[serde(default)]
1183
    pub views: Vec<ProjectView>,
1184
    /// The filter applied (`?q=`, or the `?view=`'s), when one was.
1185
    #[serde(default, skip_serializing_if = "String::is_empty")]
1186
    pub filter: String,
ef20fdc1 Andy McCall ↶ 1187
}
1188
1189
/// `POST /projects/{owner}`.
1190
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1191
pub struct NewProject {
1192
    pub title: String,
1193
    #[serde(default)]
1194
    pub description: String,
1195
    #[serde(default)]
1196
    pub private: bool,
1197
}
1198
1199
/// `PATCH /projects/{owner}/{n}`: only the fields given change.
1200
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5a9a6e9a Andy McCall ↶ 1201
#[serde(deny_unknown_fields)]
ef20fdc1 Andy McCall ↶ 1202
pub struct ProjectEdit {
b1e92a62 Andy McCall ↶ 1203
    /// Transfer the board to this owner (#125): one the caller may make
1204
    /// boards under. It takes the next number there.
1205
    #[serde(default, skip_serializing_if = "Option::is_none")]
1206
    pub owner: Option<String>,
ef20fdc1 Andy McCall ↶ 1207
    #[serde(default)]
1208
    pub title: Option<String>,
1209
    #[serde(default)]
1210
    pub description: Option<String>,
1211
    #[serde(default)]
1212
    pub private: Option<bool>,
1213
    #[serde(default)]
1214
    pub closed: Option<bool>,
1215
}
1216
1217
/// `POST /projects/{owner}/{n}/cards`: a reference (`repo#12`) or a note,
1218
/// into the column named (by id or name; the first column when absent).
1219
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1220
pub struct NewCard {
1221
    #[serde(default)]
1222
    pub column: Option<String>,
1223
    #[serde(default)]
1224
    pub reference: String,
1225
    #[serde(default)]
1226
    pub note: String,
1227
}
1228
1229
/// `PATCH /projects/{owner}/{n}/cards/{id}`: move to a column (id or name).
1230
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1231
pub struct CardMove {
1232
    pub column: String,
1233
}
1234
456f4197 Andy McCall ↶ 1235
/// `POST /projects/{owner}/{n}/cards/move` (#289): every card of column
1236
/// `from` to `column` at once, but those `except` names (card ids, or issue
1237
/// and proposal numbers as `12`, `#12`, `name#12` or `owner/name#12`) and,
1238
/// given `state`, only cards whose issue or proposal is in one of them
1239
/// (`closed`, `landed`…). With `dry_run`, nothing moves.
1240
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1241
pub struct CardsMove {
1242
    pub from: String,
1243
    pub column: String,
1244
    #[serde(default)]
1245
    pub except: Vec<String>,
1246
    #[serde(default)]
1247
    pub state: Vec<String>,
1248
    #[serde(default)]
1249
    pub dry_run: bool,
1250
}
1251
1252
/// What a bulk move moved, and what it left in the column.
1253
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1254
pub struct CardsMoved {
1255
    pub moved: Vec<ProjectCard>,
439ecd87 Andy McCall ↶ 1256
    pub kept: Vec<ProjectCard>,
1257
    pub dry_run: bool,
1258
}
1259
1260
/// `POST /projects/{owner}/{n}/cards/archive` (oxygenhub#293): take the
1261
/// cards of column `from` off the board, kept and restorable, but those
1262
/// `except` names and, given `state`, only cards whose issue or proposal is
1263
/// in one of them; given `older_days`, only cards that joined the column
1264
/// more than that many days ago. With `dry_run`, nothing is archived.
1265
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1266
pub struct CardsArchive {
1267
    pub from: String,
1268
    #[serde(default)]
1269
    pub older_days: Option<i64>,
1270
    #[serde(default)]
1271
    pub except: Vec<String>,
1272
    #[serde(default)]
1273
    pub state: Vec<String>,
1274
    #[serde(default)]
1275
    pub dry_run: bool,
1276
}
1277
1278
/// What an archive took off the board, and what it left in the column.
1279
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1280
pub struct CardsArchived {
1281
    pub archived: Vec<ProjectCard>,
456f4197 Andy McCall ↶ 1282
    pub kept: Vec<ProjectCard>,
1283
    pub dry_run: bool,
1284
}
1285
76f262e1 Andy McCall ↶ 1286
/// `POST /repos/{o}/{n}/labels`: create a label, or change one of that name.
1287
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1288
pub struct NewLabel {
1289
    pub name: String,
1290
    /// `#rrggbb`; a default when absent.
1291
    #[serde(default)]
1292
    pub colour: Option<String>,
1293
    #[serde(default)]
1294
    pub description: String,
1295
}
1296
b64e2537 Andy McCall ↶ 1297
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1298
pub struct NewComment {
1299
    pub body: String,
3f4b0ea6 Andy McCall ↶ 1300
    /// For a proposal: anchor the comment to this file's line (1-based) of
1301
    /// the projected state; the hub records the line's atom.
1302
    #[serde(default)]
1303
    pub path: Option<String>,
1304
    #[serde(default)]
1305
    pub line: Option<usize>,
b64e2537 Andy McCall ↶ 1306
}
1307
1308
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1309
pub struct NewProposal {
1310
    pub title: String,
1311
    #[serde(default)]
1312
    pub body: String,
1313
    pub target: String,
1314
    /// A bookmark here, or `owner/name:bookmark` of a fork.
1315
    pub source: String,
1316
    #[serde(default)]
1317
    pub draft: bool,
cc1cd197 Andy McCall ↶ 1318
}
1319
1320
/// `POST .../proposals/{number}/reviewers`: accounts to ask for a review.
1321
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1322
pub struct ReviewRequest {
1323
    pub reviewers: Vec<String>,
7d2eb590 Andy McCall ↶ 1324
}
1325
1326
/// `POST .../proposals/{number}/review-requests`: ask an AI assistant the
1327
/// repository may use (hub spec §13.4) to review; it answers as a `comment`
1328
/// review via the assistant.
1329
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1330
pub struct AssistantRequest {
1331
    pub assistant: String,
b64e2537 Andy McCall ↶ 1332
}
1333
1334
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1335
pub struct NewReview {
1336
    pub verdict: String,
1337
    #[serde(default)]
1338
    pub body: String,
1339
}
1340
1341
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1342
pub struct IssueStateChange {
1343
    /// `open` or `closed`.
1344
    pub state: String,
1345
    #[serde(default)]
1346
    pub reason: String,
1347
}
1348
1349
/// A webhook payload's envelope (hub spec §12.2).
1350
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1351
pub struct WebhookEnvelope {
1352
    pub event: String,
1353
    pub delivery: String,
1354
    pub repository: Option<Repository>,
1355
    pub actor: String,
1356
    pub at_ms: i64,
1357
    pub data: serde_json::Value,
1358
}
1359
1360
/// A server-sent event on a proposal's stream.
1361
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1362
pub struct ProposalEvent {
1363
    pub number: i64,
1364
    pub kind: String,
1365
    pub check: Option<Check>,
1366
}
1367
3f4b0ea6 Andy McCall ↶ 1368
// --------------------------------------------------------------- releases
1369
1370
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1371
pub struct Release {
1372
    pub tag: String,
1373
    pub title: String,
1374
    pub notes: String,
1375
    pub prerelease: bool,
1376
    pub latest: bool,
1377
    pub author: String,
1378
    pub heads: Vec<String>,
1379
    pub signer: Option<String>,
1380
    pub assets: Vec<ReleaseAsset>,
1381
    pub archives: Vec<String>,
1382
    pub created_ms: i64,
1383
    pub url: String,
1384
}
1385
1386
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1387
pub struct ReleaseAsset {
1388
    pub name: String,
1389
    pub size: i64,
1390
    /// BLAKE3 of the content, hex.
1391
    pub hash: String,
1392
    pub content_type: String,
1393
    pub downloads: i64,
1394
    pub url: String,
10708ab8 Andy McCall ↶ 1395
    /// The OxygenFlow run and job whose artifact has this content, if any.
1396
    #[serde(default, skip_serializing_if = "Option::is_none")]
1397
    pub built_by: Option<AssetBuild>,
1398
}
1399
1400
/// Where a release asset was built (hub spec §9): a job's artifact with the
1401
/// same BLAKE3, and that job's signed receipt when one was kept.
1402
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1403
pub struct AssetBuild {
1404
    pub run: i64,
1405
    pub job: String,
1406
    pub artifact: String,
1407
    pub run_url: String,
1408
    /// The receipt attestation, hex; `None` when the receipt was not signed.
1409
    pub receipt: Option<String>,
1410
    pub receipt_url: Option<String>,
1411
    pub signer: Option<String>,
3f4b0ea6 Andy McCall ↶ 1412
}
1413
739a763a Andy McCall ↶ 1414
/// `PATCH /repos/{o}/{n}/proposals/{number}`: what is given changes,
1415
/// the rest stays (oxygenhub#76).
1416
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5a9a6e9a Andy McCall ↶ 1417
#[serde(deny_unknown_fields)]
739a763a Andy McCall ↶ 1418
pub struct ProposalEdit {
1419
    #[serde(default, skip_serializing_if = "Option::is_none")]
1420
    pub title: Option<String>,
1421
    #[serde(default, skip_serializing_if = "Option::is_none")]
1422
    pub body: Option<String>,
2291f8cc Andy McCall ↶ 1423
    /// The whole set of labels, by name (triage); oxygenhub#80.
1424
    #[serde(default, skip_serializing_if = "Option::is_none")]
1425
    pub labels: Option<Vec<String>>,
09ffa7b6 Andy McCall ↶ 1426
    /// `closed`, `open` (reopen a closed one, or make a draft ready for
1427
    /// review) or `draft` (turn an open one back into a draft), by its
1428
    /// author or with triage access, as the page's buttons do
1429
    /// (oxygenhub#140, #313).
71e65fcf Andy McCall ↶ 1430
    #[serde(default, skip_serializing_if = "Option::is_none")]
1431
    pub state: Option<String>,
09ffa7b6 Andy McCall ↶ 1432
    /// `false` makes a draft ready for review, `true` turns an open
1433
    /// proposal back into a draft: the same as `state`, in the words a
1434
    /// proposal is created with (#313).
1435
    #[serde(default, skip_serializing_if = "Option::is_none")]
1436
    pub draft: Option<bool>,
739a763a Andy McCall ↶ 1437
}
1438
ced6d3af Andy McCall ↶ 1439
/// `PATCH /repos/{owner}/{name}/releases/{tag}`: what to change; fields
1440
/// left out stay as they are.
1441
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5a9a6e9a Andy McCall ↶ 1442
#[serde(deny_unknown_fields)]
ced6d3af Andy McCall ↶ 1443
pub struct ReleaseEdit {
1444
    #[serde(default, skip_serializing_if = "Option::is_none")]
1445
    pub title: Option<String>,
1446
    #[serde(default, skip_serializing_if = "Option::is_none")]
1447
    pub notes: Option<String>,
1448
    #[serde(default, skip_serializing_if = "Option::is_none")]
1449
    pub prerelease: Option<bool>,
1450
}
1451
166f6e9b Andy McCall 1452
/// A drop (oxygenhub#279): a small snippet of one or more files, its own
1453
/// Oxygen repository, never listed among repositories. `GET /drops` lists
1454
/// yours, `GET /users/{name}/drops` someone's public ones, and
1455
/// `GET /drops/{id}` one with its files' content.
3f4b0ea6 Andy McCall ↶ 1456
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
166f6e9b Andy McCall 1457
pub struct Drop {
1458
    /// 24 hex digits, unique on the hub.
1459
    pub id: String,
1460
    pub owner: String,
1461
    pub title: String,
1462
    pub description: String,
1463
    /// `public` (listed on its owner's Drops page) or `secret` (unlisted:
1464
    /// readable by anyone with its address).
1465
    pub visibility: String,
1466
    /// The drop's page.
1467
    pub url: String,
1468
    /// What `oxy clone` takes.
1469
    pub clone_url: String,
1470
    pub created_ms: i64,
1471
    pub updated_ms: i64,
1472
    pub files: Vec<DropFile>,
04f9c984 Andy McCall ↶ 1473
    /// How many have starred it, and whether the caller has (oxygenhub#349).
1474
    #[serde(default)]
1475
    pub stars: i64,
1476
    #[serde(default)]
1477
    pub starred: bool,
1478
    /// The drop it was forked from, its page, while that drop exists.
1479
    #[serde(default, skip_serializing_if = "Option::is_none")]
1480
    pub forked_from: Option<String>,
1481
    /// Its files without the site around them, for an `<iframe>` (#280).
1482
    #[serde(default)]
1483
    pub embed_url: String,
1484
}
1485
1486
/// A comment on a drop (oxygenhub#349).
1487
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1488
pub struct DropComment {
1489
    /// Its number on the drop.
1490
    pub id: i64,
1491
    pub author: String,
1492
    /// Markdown.
1493
    pub body: String,
1494
    pub created_ms: i64,
1495
}
1496
1497
/// `POST /drops/{id}/comments`.
1498
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1499
pub struct NewDropComment {
1500
    pub body: String,
1501
}
1502
1c52d940 Andy McCall ↶ 1503
/// `POST /repos/{owner}/{name}/attachments?name=FILE` (oxygenhub#350): a
1504
/// file attached for an issue, comment or proposal to show; the body is the
1505
/// file's bytes.
1506
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1507
pub struct Attachment {
1508
    pub id: i64,
1509
    pub name: String,
1510
    pub size: i64,
1511
    /// Checked from the bytes: an image the page may show, or
1512
    /// `application/octet-stream`.
1513
    pub content_type: String,
1514
    /// An image shown in place; anything else is a download.
1515
    pub inline: bool,
1516
    pub url: String,
1517
    /// What to put in an issue or comment: `![name](url)` for an image,
1518
    /// `[name](url)` otherwise.
1519
    pub markdown: String,
1520
}
1521
04f9c984 Andy McCall ↶ 1522
/// A drop's stars after `PUT` or `DELETE /drops/{id}/star`.
1523
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1524
pub struct DropStars {
1525
    pub stars: i64,
1526
    pub starred: bool,
166f6e9b Andy McCall 1527
}
1528
1529
/// One of a drop's files. Lists carry no content; one drop's view carries
1530
/// the content of each text file up to 512 KiB.
1531
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1532
pub struct DropFile {
1533
    pub name: String,
1534
    pub size: u64,
1535
    #[serde(default, skip_serializing_if = "Option::is_none")]
1536
    pub content: Option<String>,
1537
    /// The file's bytes on the default bookmark.
1538
    pub raw_url: String,
1539
}
1540
1541
/// `POST /drops`: a new drop with at least one file.
1542
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1543
pub struct NewDrop {
1544
    #[serde(default)]
1545
    pub title: String,
1546
    #[serde(default)]
1547
    pub description: String,
1548
    /// Unlisted, readable by anyone with its address.
1549
    #[serde(default)]
1550
    pub secret: bool,
1551
    pub files: Vec<NewDropFile>,
1552
}
1553
1554
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1555
pub struct NewDropFile {
1556
    pub name: String,
1557
    pub content: String,
1558
}
1559
1560
/// `PATCH /drops/{id}`: what to change; what is left out stays.
1561
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5a9a6e9a Andy McCall ↶ 1562
#[serde(deny_unknown_fields)]
166f6e9b Andy McCall 1563
pub struct DropEdit {
1564
    #[serde(default, skip_serializing_if = "Option::is_none")]
1565
    pub title: Option<String>,
1566
    #[serde(default, skip_serializing_if = "Option::is_none")]
1567
    pub description: Option<String>,
1568
    #[serde(default, skip_serializing_if = "Option::is_none")]
1569
    pub secret: Option<bool>,
1570
    /// Files to write, or to remove (`content` null); others are kept.
1571
    #[serde(default)]
1572
    pub files: Vec<DropFileEdit>,
1573
    /// The change's message (default "Edit TITLE").
1574
    #[serde(default, skip_serializing_if = "Option::is_none")]
1575
    pub message: Option<String>,
1576
}
1577
1578
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5a9a6e9a Andy McCall ↶ 1579
#[serde(deny_unknown_fields)]
166f6e9b Andy McCall 1580
pub struct DropFileEdit {
1581
    pub name: String,
1582
    #[serde(default)]
1583
    pub content: Option<String>,
1584
}
1585
ba0a55bb Andy McCall ↶ 1586
/// `POST …/tags` (#295): tag the state of `target` (a bookmark, tag or
1587
/// change; the default bookmark when absent).
166f6e9b Andy McCall 1588
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
ba0a55bb Andy McCall ↶ 1589
pub struct NewTag {
1590
    pub name: String,
1591
    #[serde(default)]
1592
    pub target: Option<String>,
1593
    #[serde(default)]
1594
    pub message: Option<String>,
1595
}
1596
1597
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
3f4b0ea6 Andy McCall ↶ 1598
pub struct NewRelease {
1599
    pub tag: String,
1600
    pub title: String,
1601
    #[serde(default)]
1602
    pub notes: Option<String>,
1603
    #[serde(default)]
1604
    pub prerelease: bool,
1605
}
1606
eb2a3502 Andy McCall ↶ 1607
/// `GET /repos/{o}/{n}/diffusion` (oxygenhub#153): what a repository
1608
/// takes from (the subrepos it pins) and what it diffuses to (the
1609
/// repositories that pin it), each as the Diffusion pages show it.
1610
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1611
pub struct Diffusion {
1612
    pub takes_from: Vec<DiffusionPin>,
1613
    pub diffuses_to: Vec<DiffusionPin>,
1614
}
1615
1616
/// One pin of an upstream by a consumer, both named `owner/name`.
1617
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1618
pub struct DiffusionPin {
1619
    pub upstream: String,
1620
    pub consumer: String,
1621
    /// Where the consumer pins it.
1622
    pub path: String,
1623
    /// The consumer's bookmark its bumps land on.
1624
    pub bookmark: String,
1625
    /// Upstream changes the pin lacks; absent when the hub cannot tell.
1626
    #[serde(default)]
1627
    pub behind: Option<u64>,
1628
    /// `off`, `green` or `any`.
1629
    pub follow: String,
1630
    /// The open bump proposal's number, on the consumer.
1631
    #[serde(default)]
1632
    pub bump: Option<i64>,
1633
    /// The newest run of the bump: number and status.
1634
    #[serde(default)]
1635
    pub run: Option<i64>,
1636
    #[serde(default)]
1637
    pub run_status: Option<String>,
1638
    /// The pill: the upstream's half, then the consumer's.
1639
    pub upstream_state: DiffusionHalf,
1640
    pub consumer_state: DiffusionHalf,
1641
}
1642
1643
/// One half of the Diffusion pill.
1644
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1645
pub struct DiffusionHalf {
1646
    /// `green`, `amber`, `red`, `grey` or `off`.
1647
    pub tone: String,
1648
    /// What the pill says: `checked`, `untested`, `passes`, `up to date`…
1649
    pub word: String,
1650
    /// The sentence behind it.
1651
    pub title: String,
1652
}
1653
b64e2537 Andy McCall ↶ 1654
/// Every type of the API, for schema generation.
1655
pub fn schemas() -> Vec<(&'static str, schemars::Schema)> {
1656
    vec![
1657
        ("Repository", schemars::schema_for!(Repository)),
eb2a3502 Andy McCall ↶ 1658
        ("Diffusion", schemars::schema_for!(Diffusion)),
1659
        ("DiffusionPin", schemars::schema_for!(DiffusionPin)),
1660
        ("DiffusionHalf", schemars::schema_for!(DiffusionHalf)),
b64e2537 Andy McCall ↶ 1661
        ("Visibility", schemars::schema_for!(Visibility)),
1662
        ("Bookmark", schemars::schema_for!(Bookmark)),
1663
        ("Tag", schemars::schema_for!(Tag)),
1664
        ("ChangeSummary", schemars::schema_for!(ChangeSummary)),
1665
        ("Author", schemars::schema_for!(Author)),
1666
        ("Signature", schemars::schema_for!(Signature)),
1667
        ("Problem", schemars::schema_for!(Problem)),
1668
        ("Proposal", schemars::schema_for!(Proposal)),
1669
        ("ProposalState", schemars::schema_for!(ProposalState)),
1670
        ("ProposalSource", schemars::schema_for!(ProposalSource)),
1671
        ("Approval", schemars::schema_for!(Approval)),
1672
        ("Issue", schemars::schema_for!(Issue)),
1673
        ("Label", schemars::schema_for!(Label)),
1674
        ("Milestone", schemars::schema_for!(Milestone)),
5ea4872f Andy McCall ↶ 1675
        ("NewMilestone", schemars::schema_for!(NewMilestone)),
1676
        ("MilestoneEdit", schemars::schema_for!(MilestoneEdit)),
b64e2537 Andy McCall ↶ 1677
        ("Comment", schemars::schema_for!(Comment)),
3f02e5ea Andy McCall ↶ 1678
        ("ProposalFile", schemars::schema_for!(ProposalFile)),
42a0ba4b Andy McCall ↶ 1679
        ("Notification", schemars::schema_for!(Notification)),
1680
        ("Inbox", schemars::schema_for!(Inbox)),
b64e2537 Andy McCall ↶ 1681
        ("Atom", schemars::schema_for!(Atom)),
1682
        ("Review", schemars::schema_for!(Review)),
1683
        ("TreeEntry", schemars::schema_for!(TreeEntry)),
1684
        ("BlameLine", schemars::schema_for!(BlameLine)),
1685
        ("FileChange", schemars::schema_for!(FileChange)),
1686
        ("ChangeDetail", schemars::schema_for!(ChangeDetail)),
1687
        ("History", schemars::schema_for!(History)),
1688
        ("Conflict", schemars::schema_for!(Conflict)),
1689
        ("Push", schemars::schema_for!(Push)),
1690
        ("Trust", schemars::schema_for!(Trust)),
1691
        ("Policy", schemars::schema_for!(Policy)),
1692
        ("Rule", schemars::schema_for!(Rule)),
1693
        ("Hook", schemars::schema_for!(Hook)),
1694
        ("NewHook", schemars::schema_for!(NewHook)),
1695
        ("Check", schemars::schema_for!(Check)),
1696
        ("CheckStatus", schemars::schema_for!(CheckStatus)),
1697
        ("NewCheck", schemars::schema_for!(NewCheck)),
1698
        ("User", schemars::schema_for!(User)),
1699
        ("Organisation", schemars::schema_for!(Organisation)),
1700
        ("NewRepository", schemars::schema_for!(NewRepository)),
1701
        ("NewIssue", schemars::schema_for!(NewIssue)),
76f262e1 Andy McCall ↶ 1702
        ("IssueEdit", schemars::schema_for!(IssueEdit)),
2291f8cc Andy McCall ↶ 1703
        ("ReleaseEdit", schemars::schema_for!(ReleaseEdit)),
1704
        ("ProposalEdit", schemars::schema_for!(ProposalEdit)),
76f262e1 Andy McCall ↶ 1705
        ("NewLabel", schemars::schema_for!(NewLabel)),
961c10be Andy McCall ↶ 1706
        ("RequiredChecks", schemars::schema_for!(RequiredChecks)),
ef20fdc1 Andy McCall ↶ 1707
        ("Project", schemars::schema_for!(Project)),
1708
        ("ProjectCard", schemars::schema_for!(ProjectCard)),
1709
        ("ProjectColumn", schemars::schema_for!(ProjectColumn)),
1710
        ("Board", schemars::schema_for!(Board)),
1711
        ("NewProject", schemars::schema_for!(NewProject)),
1712
        ("ProjectEdit", schemars::schema_for!(ProjectEdit)),
306aec18 Andy McCall ↶ 1713
        ("NewColumn", schemars::schema_for!(NewColumn)),
0bc95135 Andy McCall ↶ 1714
        ("ProjectView", schemars::schema_for!(ProjectView)),
f2d2776b Andy McCall ↶ 1715
        ("BoardCharts", schemars::schema_for!(BoardCharts)),
306aec18 Andy McCall ↶ 1716
        ("ColumnEdit", schemars::schema_for!(ColumnEdit)),
ef20fdc1 Andy McCall ↶ 1717
        ("NewCard", schemars::schema_for!(NewCard)),
1718
        ("CardMove", schemars::schema_for!(CardMove)),
b64e2537 Andy McCall ↶ 1719
        ("NewComment", schemars::schema_for!(NewComment)),
1720
        ("NewProposal", schemars::schema_for!(NewProposal)),
1721
        ("NewReview", schemars::schema_for!(NewReview)),
1722
        ("IssueStateChange", schemars::schema_for!(IssueStateChange)),
1723
        ("WebhookEnvelope", schemars::schema_for!(WebhookEnvelope)),
1724
        ("ProposalEvent", schemars::schema_for!(ProposalEvent)),
3f4b0ea6 Andy McCall ↶ 1725
        ("Release", schemars::schema_for!(Release)),
bf1ab345 Andy McCall ↶ 1726
        ("FlowRun", schemars::schema_for!(FlowRun)),
1727
        ("FlowJob", schemars::schema_for!(FlowJob)),
1728
        ("FlowLogLine", schemars::schema_for!(FlowLogLine)),
fac6853c Andy McCall ↶ 1729
        ("FlowPhase", schemars::schema_for!(FlowPhase)),
1730
        ("Report", schemars::schema_for!(Report)),
1731
        ("ReportMetric", schemars::schema_for!(ReportMetric)),
1732
        ("ReportFile", schemars::schema_for!(ReportFile)),
bf1ab345 Andy McCall ↶ 1733
        ("AssetBuild", schemars::schema_for!(AssetBuild)),
3f4b0ea6 Andy McCall ↶ 1734
        ("ReleaseAsset", schemars::schema_for!(ReleaseAsset)),
1735
        ("NewRelease", schemars::schema_for!(NewRelease)),
166f6e9b Andy McCall 1736
        ("Drop", schemars::schema_for!(Drop)),
04f9c984 Andy McCall ↶ 1737
        ("DropComment", schemars::schema_for!(DropComment)),
1738
        ("NewDropComment", schemars::schema_for!(NewDropComment)),
1739
        ("DropStars", schemars::schema_for!(DropStars)),
1c52d940 Andy McCall ↶ 1740
        ("Attachment", schemars::schema_for!(Attachment)),
166f6e9b Andy McCall 1741
        ("NewDrop", schemars::schema_for!(NewDrop)),
1742
        ("DropEdit", schemars::schema_for!(DropEdit)),
041a945f Andy McCall ↶ 1743
        ("UserProposals", schemars::schema_for!(UserProposals)),
1744
        ("ProposalBrief", schemars::schema_for!(ProposalBrief)),
8f1d76f4 Andy McCall ↶ 1745
        ("IssueBrief", schemars::schema_for!(IssueBrief)),
a22e4aec Andy McCall ↶ 1746
        ("NewAuthenticator", schemars::schema_for!(NewAuthenticator)),
1747
        ("Authenticator", schemars::schema_for!(Authenticator)),
1748
        ("PendingApproval", schemars::schema_for!(PendingApproval)),
1749
        ("ApprovalAnswer", schemars::schema_for!(ApprovalAnswer)),
041a945f Andy McCall ↶ 1750
        ("StarterAssistants", schemars::schema_for!(StarterAssistants)),
1751
        ("StarterStatus", schemars::schema_for!(StarterStatus)),
1752
        ("StarterRequest", schemars::schema_for!(StarterRequest)),
1753
        ("TestReport", schemars::schema_for!(TestReport)),
1754
        ("TestReportDetail", schemars::schema_for!(TestReportDetail)),
b64e2537 Andy McCall ↶ 1755
    ]
1756
}
b66e70b7 Andy McCall ↶ 1757
1758
/// An OxygenFlow runner (`GET /api/v1/runners`, site administrators).
1759
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1760
pub struct Runner {
1761
    pub id: i64,
1762
    pub name: String,
1763
    /// `online`, `offline`, `draining` or `disabled`.
1764
    pub status: String,
1765
    /// What it serves: empty for the whole site, an owner, or `owner/name`.
1766
    pub serves: String,
1767
    pub arch: String,
1768
    pub os: String,
1769
    pub version: String,
1770
    pub labels: Vec<String>,
1771
    pub max_jobs: i64,
1772
    pub memory_mib: Option<i64>,
1773
    pub cpus: Option<i64>,
1774
    /// The key that signs its receipts (KeyId hex), empty until bound.
1775
    pub key: String,
1776
    /// `registered` or `config` (a hub.toml token).
1777
    pub source: String,
1778
    pub last_seen_ms: Option<i64>,
1779
    /// Jobs it is running now.
1780
    pub running: i64,
2fb70d01 Andy McCall ↶ 1781
    /// What it measured at its last claim (oxygenflow#40): free disk in
1782
    /// MiB, the 1-minute load ×100, its speed score (100 on the reference
1783
    /// machine) and class 1–5, its kernel.
1784
    #[serde(default, skip_serializing_if = "Option::is_none")]
1785
    pub free_disk_mib: Option<i64>,
1786
    #[serde(default, skip_serializing_if = "Option::is_none")]
1787
    pub load_x100: Option<i64>,
1788
    #[serde(default, skip_serializing_if = "Option::is_none")]
1789
    pub speed: Option<i64>,
1790
    #[serde(default, skip_serializing_if = "Option::is_none")]
1791
    pub speed_class: Option<i64>,
1792
    #[serde(default, skip_serializing_if = "String::is_empty")]
1793
    pub kernel: String,
b66e70b7 Andy McCall ↶ 1794
}
1795
1796
/// A job a runner ran or is running.
1797
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1798
pub struct RunnerJob {
1799
    pub repo: String,
1800
    pub run: i64,
1801
    pub job: String,
1802
    pub status: String,
1803
    pub started_ms: Option<i64>,
1804
    pub finished_ms: Option<i64>,
1805
}
1806
1807
/// A job in the queue: running ones first, then queued ones in the order
1808
/// runners claim them.
1809
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1810
pub struct QueueItem {
1811
    pub repo: String,
1812
    pub run: i64,
1813
    pub job: String,
1814
    /// `running` or `queued`.
1815
    pub status: String,
1816
    /// The runner holding it, when running.
1817
    pub runner: String,
1818
}
62ceb2ee Andy McCall ↶ 1819
1820
// ------------------------------------------------------------- assistants
1821
1822
/// An AI assistant at a level (hub spec §13.4). The token never leaves the
1823
/// hub: `has_token` says whether one is set.
1824
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1825
pub struct Assistant {
1826
    pub name: String,
1827
    pub endpoint: String,
1828
    pub api: String,
1829
    pub model: String,
1830
    #[serde(default, skip_serializing_if = "String::is_empty")]
1831
    pub headers: String,
1832
    pub enabled: bool,
1833
    pub budget: i64,
1834
    pub has_token: bool,
1835
    /// Where it comes from: empty for the level's own, else `the site` or
1836
    /// `the NAME organisation`.
1837
    #[serde(default, skip_serializing_if = "String::is_empty")]
1838
    pub from: String,
1839
    /// Off because a level above turned a name like it off.
1840
    #[serde(default)]
1841
    pub off_above: bool,
1842
}
1843
1844
/// `POST …/assistants`: add one, or change the one of that name. A
1845
/// `preset` (`anthropic`, `openai`, `gemini`, `deepseek`, `mistral`,
1846
/// `perplexity`, `ollama`) fills what is left out; the model must be one
1847
/// the endpoint lists when it lists any; `token` is write-only.
1848
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1849
pub struct NewAssistant {
1850
    #[serde(default)]
1851
    pub name: String,
1852
    #[serde(default)]
1853
    pub preset: String,
1854
    #[serde(default)]
1855
    pub endpoint: String,
1856
    #[serde(default)]
1857
    pub api: String,
1858
    pub model: String,
1859
    #[serde(default)]
1860
    pub token: String,
1861
    #[serde(default)]
1862
    pub headers: String,
1863
    #[serde(default = "yes")]
1864
    pub enabled: bool,
1865
    #[serde(default)]
1866
    pub budget: Option<i64>,
1867
}
1868
1869
fn yes() -> bool {
1870
    true
1871
}
1872
1873
/// A level's prompt and those it inherits, outermost first.
1874
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1875
pub struct AssistantPrompt {
1876
    pub prompt: String,
1877
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1878
    pub inherited: Vec<(String, String)>,
1879
}
617c2840 Andy McCall ↶ 1880
1881
/// `GET /repos/{o}/{n}/coverage`: a coverage report from a Flow job
1882
/// (oxygenhub#113); `percent` values are of lines, functions and branches,
1883
/// absent when nothing was counted.
1884
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1885
pub struct CoverageReport {
1886
    pub id: i64,
1887
    pub run: i64,
1888
    pub job: String,
1889
    pub bookmark: String,
1890
    /// The run's state, by hash.
1891
    pub state: String,
1892
    /// `lcov` or `cobertura`.
1893
    pub format: String,
1894
    pub lines_found: i64,
1895
    pub lines_hit: i64,
1896
    pub percent: Option<f64>,
1897
    pub functions_found: i64,
1898
    pub functions_hit: i64,
1899
    pub branches_found: i64,
1900
    pub branches_hit: i64,
1901
    pub files: i64,
1902
    /// Files the report named that are not in the run's state.
1903
    pub dropped: i64,
1904
    pub created_ms: i64,
1905
    /// The report on the hub's Coverage tab, absolute.
1906
    pub url: String,
40dd3f86 Andy McCall ↶ 1907
    /// Who uploaded it from a workstation (#136), when no Flow job made it;
1908
    /// `run` and `job` are then 0 and "upload".
1909
    #[serde(default, skip_serializing_if = "Option::is_none")]
1910
    pub uploaded_by: Option<String>,
617c2840 Andy McCall ↶ 1911
}
1912
1913
/// One file of a coverage report.
1914
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1915
pub struct CoverageFile {
1916
    pub path: String,
1917
    pub lines_found: i64,
1918
    pub lines_hit: i64,
1919
    pub percent: Option<f64>,
1920
    pub functions_found: i64,
1921
    pub functions_hit: i64,
1922
    pub branches_found: i64,
1923
    pub branches_hit: i64,
1924
}
1925
1926
/// `GET /repos/{o}/{n}/coverage/{id}`: a report with its files.
1927
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1928
pub struct CoverageDetail {
1929
    pub report: CoverageReport,
1930
    pub files: Vec<CoverageFile>,
1931
}
1932
1933
/// `GET /repos/{o}/{n}/tests`: a JUnit test report from a Flow job
1934
/// (oxygenhub#114).
1935
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1936
pub struct TestReport {
1937
    pub id: i64,
1938
    pub run: i64,
1939
    pub job: String,
1940
    pub bookmark: String,
1941
    pub state: String,
1942
    pub tests: i64,
1943
    pub passed: i64,
1944
    pub failed: i64,
1945
    pub errors: i64,
1946
    pub skipped: i64,
1947
    /// The cases' times added up.
1948
    pub time_ms: i64,
1949
    pub created_ms: i64,
1950
    pub url: String,
1951
}
1952
1953
/// One test case of a report.
1954
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1955
pub struct TestCase {
1956
    pub suite: String,
1957
    pub classname: String,
1958
    pub name: String,
1959
    /// `passed`, `failed`, `error` or `skipped`.
1960
    pub status: String,
1961
    pub time_ms: i64,
1962
    pub message: String,
1963
    /// A failure's text and output, cut to 16 KiB; empty for a pass.
1964
    pub output: String,
1965
}
1966
1967
/// `GET /repos/{o}/{n}/tests/{id}`: a report with its cases
1968
/// (`?status=failed` for the failed and errored ones).
1969
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1970
pub struct TestReportDetail {
1971
    pub report: TestReport,
1972
    pub cases: Vec<TestCase>,
1973
}
9bbca80f Andy McCall ↶ 1974
1975
/// `GET /api/v1/admin/runner-updates` (oxygenhub#322): where runner builds
1976
/// come from, every level's settings, the test groups, each runner's policy
1977
/// and what it is offered, and the builds held back (#326). Site
1978
/// administrators only.
1979
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1980
pub struct RunnerUpdates {
1981
    /// The repository whose releases carry runner builds (`owner/name`).
1982
    pub repo: String,
1983
    pub settings: Vec<UpdateSetting>,
1984
    pub groups: Vec<RunnerGroup>,
1985
    pub runners: Vec<RunnerUpdate>,
1986
    pub holds: Vec<HeldBuild>,
1987
}
1988
1989
/// One level's update settings; `None` inherits from the next level out.
1990
/// `PUT /api/v1/admin/runner-updates/settings` takes one.
1991
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1992
pub struct UpdateSetting {
1993
    /// `site`, `owner`, `group` or `runner`.
1994
    pub scope: String,
1995
    /// Empty for the site; the owner's name, the group's id, the runner's id.
1996
    #[serde(default)]
1997
    pub key: String,
1998
    #[serde(default)]
1999
    pub updates: Option<bool>,
2000
    /// `stable`, `canary` or a version.
2001
    #[serde(default)]
2002
    pub channel: Option<String>,
2003
    /// Hours (UTC) in which updates may start, `02-05`.
2004
    #[serde(default)]
2005
    pub window: Option<String>,
2006
    #[serde(default)]
2007
    pub dry_run: Option<bool>,
2008
}
2009
2010
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2011
pub struct RunnerGroup {
2012
    pub id: i64,
2013
    /// Empty for a group of the site's runners.
2014
    pub owner: String,
2015
    pub name: String,
2016
    /// A share of the runners in reach; `None`: chosen ones.
2017
    pub percent: Option<i64>,
2018
    /// Its runners now, by name.
2019
    pub members: Vec<String>,
1ec29691 Andy McCall ↶ 2020
    /// The wave it takes a version in (oxygenflow#84); `None`: after every wave.
2021
    #[serde(default, skip_serializing_if = "Option::is_none")]
2022
    pub wave: Option<i64>,
9bbca80f Andy McCall ↶ 2023
}
2024
2025
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2026
pub struct RunnerUpdate {
2027
    pub id: i64,
2028
    pub name: String,
2029
    /// The owner it serves; empty for the site's.
2030
    pub owner: String,
2031
    pub version: String,
2032
    pub groups: Vec<String>,
2033
    pub updates: bool,
2034
    pub channel: String,
2035
    #[serde(default)]
2036
    pub window: Option<String>,
2037
    pub dry_run: bool,
2038
    /// Where each setting came from, in the order updates, channel, window, dry run.
2039
    pub from: Vec<String>,
2040
    /// What the hub would offer it now, in words.
2041
    pub now: String,
2042
    /// What it last said about its update.
2043
    pub said: String,
2044
}
2045
2046
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2047
pub struct HeldBuild {
2048
    pub version: String,
2049
    pub runner: String,
2050
    pub why: String,
2051
    pub at_ms: i64,
2052
}