OXYGENHUB
◆ close-proposal-140 oxygenhub / crates / hub-api / src / lib.rs
40.0 KiB · Rust · last changed Close and reopen a proposal through the API and oh 22 days ago source blame history raw
1
//! Types of the OxygenHub JSON API (hub spec §12.1). Everything here is
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
9
use schemars::JsonSchema;
10
use serde::{Deserialize, Serialize};
11
12
/// A repository as the API lists it.
13
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
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
27
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
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).
55
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
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.
65
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
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.
74
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
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,
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,
98
}
99
100
/// Who wrote a change: the linked account when the signing key is linked,
101
/// else the key alone.
102
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
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>,
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
    }
124
}
125
126
/// Signature status of a change as `oxy verify` reports it.
127
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
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.
136
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
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
}
155
156
// ---------------------------------------------------------------- proposals
157
158
/// A proposal: a request to add changes to a target bookmark (hub spec §7).
159
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
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>,
185
    /// Who landed it, how and when, once landed.
186
    #[serde(default)]
187
    pub landed: Option<Landed>,
188
    /// Asked to review and not yet reviewing, in the order asked.
189
    #[serde(default)]
190
    pub requested_reviewers: Vec<String>,
191
    #[serde(default)]
192
    pub labels: Vec<Label>,
193
}
194
195
/// How a proposal was landed.
196
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
197
pub struct Landed {
198
    pub by: String,
199
    /// `web`, or `api (token NAME)`.
200
    pub via: String,
201
    pub when_ms: i64,
202
}
203
204
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
205
#[serde(rename_all = "lowercase")]
206
pub enum ProposalState {
207
    Draft,
208
    Open,
209
    Landed,
210
    Closed,
211
}
212
213
impl ProposalState {
214
    pub fn as_str(self) -> &'static str {
215
        match self {
216
            ProposalState::Draft => "draft",
217
            ProposalState::Open => "open",
218
            ProposalState::Landed => "landed",
219
            ProposalState::Closed => "closed",
220
        }
221
    }
222
223
    pub fn parse(s: &str) -> Option<ProposalState> {
224
        Some(match s {
225
            "draft" => ProposalState::Draft,
226
            "open" => ProposalState::Open,
227
            "landed" => ProposalState::Landed,
228
            "closed" => ProposalState::Closed,
229
            _ => return None,
230
        })
231
    }
232
}
233
234
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
235
#[serde(tag = "kind", rename_all = "lowercase")]
236
pub enum ProposalSource {
237
    /// A bookmark of the same repository.
238
    Bookmark { bookmark: String },
239
    /// A bookmark of a fork.
240
    Fork { owner: String, name: String, bookmark: String },
241
    /// An explicit list of change hashes.
242
    Changes { hashes: Vec<String> },
243
}
244
245
/// A reviewer's approval, counted only when backed by a seal over every
246
/// change of the proposal signed with a key linked to the reviewer.
247
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
248
pub struct Approval {
249
    pub account: String,
250
    pub sealed: bool,
251
    pub key: Option<String>,
252
}
253
254
// ------------------------------------------------------------------ issues
255
256
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
257
pub struct Issue {
258
    pub number: i64,
259
    pub title: String,
260
    pub body: String,
261
    pub author: String,
262
    pub state: String,
263
    pub reason: String,
264
    pub labels: Vec<Label>,
265
    pub assignees: Vec<String>,
266
    pub milestone: Option<String>,
267
    pub comments: i64,
268
    pub locked: bool,
269
    pub pinned: bool,
270
    pub created_ms: i64,
271
    pub updated_ms: i64,
272
    pub closed_ms: Option<i64>,
273
    pub url: String,
274
}
275
276
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
277
pub struct Label {
278
    pub name: String,
279
    pub colour: String,
280
    pub description: String,
281
}
282
283
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
284
pub struct Milestone {
285
    pub title: String,
286
    pub description: String,
287
    pub due_ms: Option<i64>,
288
    pub state: String,
289
    pub open: i64,
290
    pub closed: i64,
291
}
292
293
/// `POST /repos/{o}/{n}/milestones`: create a milestone, or change the
294
/// description and due date of the one with that title (triage).
295
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
296
pub struct NewMilestone {
297
    pub title: String,
298
    #[serde(default)]
299
    pub description: String,
300
    /// `YYYY-MM-DD`, UTC; absent for no due date.
301
    #[serde(default)]
302
    pub due: Option<String>,
303
}
304
305
/// `PATCH /repos/{o}/{n}/milestones/{title}`: only the fields given change
306
/// (triage).
307
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
308
pub struct MilestoneEdit {
309
    #[serde(default)]
310
    pub title: Option<String>,
311
    #[serde(default)]
312
    pub description: Option<String>,
313
    /// `YYYY-MM-DD`; the empty string clears the due date.
314
    #[serde(default)]
315
    pub due: Option<String>,
316
    /// `open` or `closed`.
317
    #[serde(default)]
318
    pub state: Option<String>,
319
}
320
321
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
322
pub struct Comment {
323
    pub id: i64,
324
    pub author: String,
325
    pub body: String,
326
    pub created_ms: i64,
327
    /// For proposal comments: the file and the atom the comment anchors to.
328
    pub path: Option<String>,
329
    pub anchor: Option<Atom>,
330
    /// Where the anchor sits now: its 1-based line in `path` in the
331
    /// projected state, when the atom is still live there.
332
    #[serde(default)]
333
    pub line: Option<usize>,
334
    pub resolved: bool,
335
}
336
337
/// One entry in the caller's inbox (hub spec §10).
338
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
339
pub struct Notification {
340
    pub id: i64,
341
    pub at_ms: i64,
342
    /// `issue.opened`, `proposal.comment`, `mention`, `review`, …
343
    pub kind: String,
344
    pub title: String,
345
    /// The page on the hub, absolute.
346
    pub url: String,
347
    pub actor: String,
348
    pub read: bool,
349
}
350
351
/// `GET /notifications`: the unread count and the newest entries, unread first.
352
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
353
pub struct Inbox {
354
    pub unread: i64,
355
    pub items: Vec<Notification>,
356
}
357
358
/// A file a proposal changes, between the target's state and the
359
/// projected state (hub spec §7.2). Fetch either side's bytes from
360
/// `/proposals/{number}/content/{base|head}/{path}`.
361
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
362
pub struct ProposalFile {
363
    pub path: String,
364
    /// For a rename, the path in the target's state.
365
    pub from: Option<String>,
366
    /// `added`, `removed`, `modified`, `renamed`, `mode` or `replaced`.
367
    pub kind: String,
368
    pub added: usize,
369
    pub removed: usize,
370
}
371
372
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
373
pub struct Atom {
374
    pub change: String,
375
    pub index: u32,
376
}
377
378
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
379
pub struct Review {
380
    pub id: i64,
381
    pub author: String,
382
    pub verdict: String,
383
    pub body: String,
384
    pub sealed: bool,
385
    pub created_ms: i64,
386
    /// The AI assistant that answered for `author`, empty for a person's
387
    /// own review (hub spec §13.4).
388
    #[serde(default, skip_serializing_if = "String::is_empty")]
389
    pub via: String,
390
}
391
392
// ------------------------------------------------------------- repository
393
394
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
395
pub struct TreeEntry {
396
    pub name: String,
397
    pub path: String,
398
    pub kind: String,
399
    pub exec: bool,
400
    pub size: Option<u64>,
401
    pub conflicted: bool,
402
}
403
404
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
405
pub struct BlameLine {
406
    pub line: usize,
407
    pub change: String,
408
    pub index: u32,
409
    pub author: String,
410
    pub when_ms: u64,
411
    pub text: String,
412
}
413
414
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
415
pub struct FileChange {
416
    pub path: String,
417
    pub kind: String,
418
    pub from: Option<String>,
419
    pub added: usize,
420
    pub removed: usize,
421
}
422
423
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
424
pub struct ChangeDetail {
425
    pub change: ChangeSummary,
426
    pub body: String,
427
    pub dependents: Vec<String>,
428
    pub in_bookmarks: Vec<String>,
429
    pub in_tags: Vec<String>,
430
    pub files: Vec<FileChange>,
431
}
432
433
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
434
pub struct History {
435
    pub reference: String,
436
    pub heads: Vec<String>,
437
    pub total: usize,
438
    pub offset: usize,
439
    pub changes: Vec<ChangeSummary>,
440
}
441
442
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
443
pub struct Conflict {
444
    pub bookmark: String,
445
    pub path: String,
446
    pub kind: String,
447
    pub contributors: Vec<String>,
448
}
449
450
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
451
pub struct Push {
452
    pub at_ms: i64,
453
    pub pusher: String,
454
    pub reference: String,
455
    pub ok: bool,
456
    pub reason: String,
457
    pub old_state: String,
458
    pub new_state: String,
459
    pub heads: i64,
460
    pub changes: i64,
461
}
462
463
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
464
pub struct Trust {
465
    pub policy: Option<Policy>,
466
    pub signed: usize,
467
    pub sealed: usize,
468
    pub unsigned: usize,
469
    pub invalid: Vec<String>,
470
    pub hub_key: String,
471
}
472
473
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
474
pub struct Policy {
475
    pub serial: u64,
476
    pub expires_ms: u64,
477
    pub roots: Vec<String>,
478
    pub root_threshold: u32,
479
    pub rules: Vec<Rule>,
480
}
481
482
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
483
pub struct Rule {
484
    pub pattern: String,
485
    pub keys: Vec<String>,
486
    pub threshold: u32,
487
    pub require: String,
488
    pub allow_conflicts: bool,
489
}
490
491
// ---------------------------------------------------------- hooks, checks
492
493
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
494
pub struct Hook {
495
    pub id: i64,
496
    pub url: String,
497
    pub events: String,
498
    pub active: bool,
499
    pub created_ms: i64,
500
}
501
502
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
503
pub struct NewHook {
504
    pub url: String,
505
    pub secret: String,
506
    #[serde(default = "star")]
507
    pub events: String,
508
}
509
510
fn star() -> String {
511
    "*".into()
512
}
513
514
/// An OxygenFlow run (hub spec §13.2).
515
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
516
pub struct FlowRun {
517
    /// The run's number within its repository.
518
    pub number: i64,
519
    pub bookmark: String,
520
    /// The state's hash, as checks are keyed.
521
    pub state: String,
522
    /// Its heads, full change hashes.
523
    pub heads: Vec<String>,
524
    /// `queued`, `running`, `passed`, `failed` or `error` (an invalid pipeline).
525
    pub status: String,
526
    /// `push`, `manual` or `rerun:N`.
527
    pub trigger: String,
528
    pub actor: String,
529
    pub pipeline_hash: String,
530
    /// An invalid pipeline's problems.
531
    pub error: String,
532
    pub created_ms: i64,
533
    pub finished_ms: Option<i64>,
534
    pub url: String,
535
    /// For a run waiting for a runner, its first queued job's 1-based
536
    /// place among all queued jobs.
537
    #[serde(default, skip_serializing_if = "Option::is_none")]
538
    pub queue_position: Option<i64>,
539
    /// Filled by the single-run endpoint.
540
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
541
    pub jobs: Vec<FlowJob>,
542
}
543
544
/// A job of a run.
545
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
546
pub struct FlowJob {
547
    pub name: String,
548
    /// `queued`, `running`, `passed`, `failed`, `skipped` or `error`.
549
    pub status: String,
550
    pub depends_on: Vec<String>,
551
    pub runner: String,
552
    pub exit_code: Option<i64>,
553
    pub error: String,
554
    pub started_ms: Option<i64>,
555
    pub finished_ms: Option<i64>,
556
    /// Log lines stored so far.
557
    pub log_lines: i64,
558
    /// Why a queued job no runner can take waits (OxygenFlow spec §11.4);
559
    /// empty when it only waits its turn.
560
    #[serde(default, skip_serializing_if = "String::is_empty")]
561
    pub waiting: String,
562
    /// Why it ran on its runner (oxygenflow#42): "holds the image, idle,
563
    /// speed 100 (class 3)".
564
    #[serde(default, skip_serializing_if = "String::is_empty")]
565
    pub placed: String,
566
}
567
568
/// A line of a job's log.
569
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
570
pub struct FlowLogLine {
571
    /// Increasing within the job; pass the last one as `after` for more.
572
    pub seq: i64,
573
    /// Milliseconds since the job started.
574
    pub t: i64,
575
    /// `stdout`, `stderr` or `flow` (the runner's own notes).
576
    pub stream: String,
577
    pub text: String,
578
}
579
580
/// A check on a state hash (hub spec §13.1).
581
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
582
pub struct Check {
583
    pub state: String,
584
    pub name: String,
585
    pub status: CheckStatus,
586
    pub summary: String,
587
    pub url: String,
588
    pub reporter: String,
589
    /// The seal attestation's reference when the checker sealed the changes.
590
    pub seal: Option<String>,
591
    pub started_ms: i64,
592
    pub finished_ms: Option<i64>,
593
}
594
595
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
596
#[serde(rename_all = "lowercase")]
597
pub enum CheckStatus {
598
    Queued,
599
    Running,
600
    Passed,
601
    Failed,
602
    Cancelled,
603
    Skipped,
604
}
605
606
impl CheckStatus {
607
    pub fn as_str(self) -> &'static str {
608
        match self {
609
            CheckStatus::Queued => "queued",
610
            CheckStatus::Running => "running",
611
            CheckStatus::Passed => "passed",
612
            CheckStatus::Failed => "failed",
613
            CheckStatus::Cancelled => "cancelled",
614
            CheckStatus::Skipped => "skipped",
615
        }
616
    }
617
618
    pub fn parse(s: &str) -> Option<CheckStatus> {
619
        Some(match s {
620
            "queued" => CheckStatus::Queued,
621
            "running" => CheckStatus::Running,
622
            "passed" => CheckStatus::Passed,
623
            "failed" => CheckStatus::Failed,
624
            "cancelled" => CheckStatus::Cancelled,
625
            "skipped" => CheckStatus::Skipped,
626
            _ => return None,
627
        })
628
    }
629
}
630
631
/// What a checker posts.
632
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
633
pub struct NewCheck {
634
    pub state: String,
635
    pub name: String,
636
    pub status: CheckStatus,
637
    #[serde(default)]
638
    pub summary: String,
639
    #[serde(default)]
640
    pub url: String,
641
    /// Hex of a seal attestation reference the checker pushed, if any.
642
    #[serde(default)]
643
    pub seal: Option<String>,
644
}
645
646
// ------------------------------------------------------------- accounts
647
648
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
649
pub struct User {
650
    pub username: String,
651
    pub display_name: String,
652
    pub is_admin: bool,
653
    pub keys: Vec<String>,
654
    pub created_ms: i64,
655
}
656
657
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
658
pub struct Organisation {
659
    pub name: String,
660
    pub display_name: String,
661
    pub description: String,
662
    pub members: Vec<String>,
663
}
664
665
/// Forms accepted by the write endpoints.
666
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
667
pub struct NewRepository {
668
    pub owner: String,
669
    pub name: String,
670
    #[serde(default)]
671
    pub description: String,
672
    #[serde(default = "public")]
673
    pub visibility: Visibility,
674
}
675
676
fn public() -> Visibility {
677
    Visibility::Public
678
}
679
680
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
681
pub struct NewIssue {
682
    pub title: String,
683
    #[serde(default)]
684
    pub body: String,
685
    /// Label names; each must exist. Needs triage.
686
    #[serde(default)]
687
    pub labels: Vec<String>,
688
    /// Usernames. Needs triage.
689
    #[serde(default)]
690
    pub assignees: Vec<String>,
691
    /// A milestone's title. Needs triage.
692
    #[serde(default)]
693
    pub milestone: Option<String>,
694
}
695
696
/// `PATCH /repos/{o}/{n}/issues/{number}`: only the fields given change.
697
/// Title and body: the author or triage. The rest: triage.
698
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
699
pub struct IssueEdit {
700
    #[serde(default)]
701
    pub title: Option<String>,
702
    #[serde(default)]
703
    pub body: Option<String>,
704
    /// The whole set of labels.
705
    #[serde(default)]
706
    pub labels: Option<Vec<String>>,
707
    /// The whole set of assignees.
708
    #[serde(default)]
709
    pub assignees: Option<Vec<String>>,
710
    /// A milestone's title; the empty string clears it.
711
    #[serde(default)]
712
    pub milestone: Option<String>,
713
}
714
715
/// The checks a proposal needs, passed, to land on the repository's
716
/// default bookmark (hub spec §13.1). `GET` and `PUT
717
/// /repos/{o}/{n}/checks/required`.
718
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
719
pub struct RequiredChecks {
720
    pub names: Vec<String>,
721
}
722
723
/// A project (hub spec §8.2).
724
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
725
pub struct Project {
726
    pub owner: String,
727
    pub number: i64,
728
    pub title: String,
729
    pub description: String,
730
    pub public: bool,
731
    pub closed: bool,
732
    pub updated_ms: i64,
733
    /// The board on the hub, absolute.
734
    pub url: String,
735
}
736
737
/// A card as the caller may see it.
738
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
739
pub struct ProjectCard {
740
    pub id: i64,
741
    /// `issue`, `proposal` or `note`.
742
    pub kind: String,
743
    /// `owner/name#N`; empty for a note.
744
    pub reference: String,
745
    /// The issue's or proposal's title, or the note.
746
    pub title: String,
747
    /// The issue's or proposal's state; empty for a note.
748
    pub state: String,
749
}
750
751
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
752
pub struct ProjectColumn {
753
    pub id: i64,
754
    pub name: String,
755
    pub cards: Vec<ProjectCard>,
756
}
757
758
/// `GET /projects/{owner}/{n}`.
759
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
760
pub struct Board {
761
    pub project: Project,
762
    pub columns: Vec<ProjectColumn>,
763
}
764
765
/// `POST /projects/{owner}`.
766
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
767
pub struct NewProject {
768
    pub title: String,
769
    #[serde(default)]
770
    pub description: String,
771
    #[serde(default)]
772
    pub private: bool,
773
}
774
775
/// `PATCH /projects/{owner}/{n}`: only the fields given change.
776
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
777
pub struct ProjectEdit {
778
    /// Transfer the board to this owner (#125): one the caller may make
779
    /// boards under. It takes the next number there.
780
    #[serde(default, skip_serializing_if = "Option::is_none")]
781
    pub owner: Option<String>,
782
    #[serde(default)]
783
    pub title: Option<String>,
784
    #[serde(default)]
785
    pub description: Option<String>,
786
    #[serde(default)]
787
    pub private: Option<bool>,
788
    #[serde(default)]
789
    pub closed: Option<bool>,
790
}
791
792
/// `POST /projects/{owner}/{n}/cards`: a reference (`repo#12`) or a note,
793
/// into the column named (by id or name; the first column when absent).
794
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
795
pub struct NewCard {
796
    #[serde(default)]
797
    pub column: Option<String>,
798
    #[serde(default)]
799
    pub reference: String,
800
    #[serde(default)]
801
    pub note: String,
802
}
803
804
/// `PATCH /projects/{owner}/{n}/cards/{id}`: move to a column (id or name).
805
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
806
pub struct CardMove {
807
    pub column: String,
808
}
809
810
/// `POST /repos/{o}/{n}/labels`: create a label, or change one of that name.
811
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
812
pub struct NewLabel {
813
    pub name: String,
814
    /// `#rrggbb`; a default when absent.
815
    #[serde(default)]
816
    pub colour: Option<String>,
817
    #[serde(default)]
818
    pub description: String,
819
}
820
821
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
822
pub struct NewComment {
823
    pub body: String,
824
    /// For a proposal: anchor the comment to this file's line (1-based) of
825
    /// the projected state; the hub records the line's atom.
826
    #[serde(default)]
827
    pub path: Option<String>,
828
    #[serde(default)]
829
    pub line: Option<usize>,
830
}
831
832
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
833
pub struct NewProposal {
834
    pub title: String,
835
    #[serde(default)]
836
    pub body: String,
837
    pub target: String,
838
    /// A bookmark here, or `owner/name:bookmark` of a fork.
839
    pub source: String,
840
    #[serde(default)]
841
    pub draft: bool,
842
}
843
844
/// `POST .../proposals/{number}/reviewers`: accounts to ask for a review.
845
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
846
pub struct ReviewRequest {
847
    pub reviewers: Vec<String>,
848
}
849
850
/// `POST .../proposals/{number}/review-requests`: ask an AI assistant the
851
/// repository may use (hub spec §13.4) to review; it answers as a `comment`
852
/// review via the assistant.
853
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
854
pub struct AssistantRequest {
855
    pub assistant: String,
856
}
857
858
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
859
pub struct NewReview {
860
    pub verdict: String,
861
    #[serde(default)]
862
    pub body: String,
863
}
864
865
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
866
pub struct IssueStateChange {
867
    /// `open` or `closed`.
868
    pub state: String,
869
    #[serde(default)]
870
    pub reason: String,
871
}
872
873
/// A webhook payload's envelope (hub spec §12.2).
874
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
875
pub struct WebhookEnvelope {
876
    pub event: String,
877
    pub delivery: String,
878
    pub repository: Option<Repository>,
879
    pub actor: String,
880
    pub at_ms: i64,
881
    pub data: serde_json::Value,
882
}
883
884
/// A server-sent event on a proposal's stream.
885
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
886
pub struct ProposalEvent {
887
    pub number: i64,
888
    pub kind: String,
889
    pub check: Option<Check>,
890
}
891
892
// --------------------------------------------------------------- releases
893
894
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
895
pub struct Release {
896
    pub tag: String,
897
    pub title: String,
898
    pub notes: String,
899
    pub prerelease: bool,
900
    pub latest: bool,
901
    pub author: String,
902
    pub heads: Vec<String>,
903
    pub signer: Option<String>,
904
    pub assets: Vec<ReleaseAsset>,
905
    pub archives: Vec<String>,
906
    pub created_ms: i64,
907
    pub url: String,
908
}
909
910
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
911
pub struct ReleaseAsset {
912
    pub name: String,
913
    pub size: i64,
914
    /// BLAKE3 of the content, hex.
915
    pub hash: String,
916
    pub content_type: String,
917
    pub downloads: i64,
918
    pub url: String,
919
    /// The OxygenFlow run and job whose artifact has this content, if any.
920
    #[serde(default, skip_serializing_if = "Option::is_none")]
921
    pub built_by: Option<AssetBuild>,
922
}
923
924
/// Where a release asset was built (hub spec §9): a job's artifact with the
925
/// same BLAKE3, and that job's signed receipt when one was kept.
926
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
927
pub struct AssetBuild {
928
    pub run: i64,
929
    pub job: String,
930
    pub artifact: String,
931
    pub run_url: String,
932
    /// The receipt attestation, hex; `None` when the receipt was not signed.
933
    pub receipt: Option<String>,
934
    pub receipt_url: Option<String>,
935
    pub signer: Option<String>,
936
}
937
938
/// `PATCH /repos/{o}/{n}/proposals/{number}`: what is given changes,
939
/// the rest stays (oxygenhub#76).
940
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
941
pub struct ProposalEdit {
942
    #[serde(default, skip_serializing_if = "Option::is_none")]
943
    pub title: Option<String>,
944
    #[serde(default, skip_serializing_if = "Option::is_none")]
945
    pub body: Option<String>,
946
    /// The whole set of labels, by name (triage); oxygenhub#80.
947
    #[serde(default, skip_serializing_if = "Option::is_none")]
948
    pub labels: Option<Vec<String>>,
949
    /// `closed` or `open` (reopen), by its author or with triage access,
950
    /// as the page's Close and Reopen do (oxygenhub#140).
951
    #[serde(default, skip_serializing_if = "Option::is_none")]
952
    pub state: Option<String>,
953
}
954
955
/// `PATCH /repos/{owner}/{name}/releases/{tag}`: what to change; fields
956
/// left out stay as they are.
957
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
958
pub struct ReleaseEdit {
959
    #[serde(default, skip_serializing_if = "Option::is_none")]
960
    pub title: Option<String>,
961
    #[serde(default, skip_serializing_if = "Option::is_none")]
962
    pub notes: Option<String>,
963
    #[serde(default, skip_serializing_if = "Option::is_none")]
964
    pub prerelease: Option<bool>,
965
}
966
967
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
968
pub struct NewRelease {
969
    pub tag: String,
970
    pub title: String,
971
    #[serde(default)]
972
    pub notes: Option<String>,
973
    #[serde(default)]
974
    pub prerelease: bool,
975
}
976
977
/// Every type of the API, for schema generation.
978
pub fn schemas() -> Vec<(&'static str, schemars::Schema)> {
979
    vec![
980
        ("Repository", schemars::schema_for!(Repository)),
981
        ("Visibility", schemars::schema_for!(Visibility)),
982
        ("Bookmark", schemars::schema_for!(Bookmark)),
983
        ("Tag", schemars::schema_for!(Tag)),
984
        ("ChangeSummary", schemars::schema_for!(ChangeSummary)),
985
        ("Author", schemars::schema_for!(Author)),
986
        ("Signature", schemars::schema_for!(Signature)),
987
        ("Problem", schemars::schema_for!(Problem)),
988
        ("Proposal", schemars::schema_for!(Proposal)),
989
        ("ProposalState", schemars::schema_for!(ProposalState)),
990
        ("ProposalSource", schemars::schema_for!(ProposalSource)),
991
        ("Approval", schemars::schema_for!(Approval)),
992
        ("Issue", schemars::schema_for!(Issue)),
993
        ("Label", schemars::schema_for!(Label)),
994
        ("Milestone", schemars::schema_for!(Milestone)),
995
        ("NewMilestone", schemars::schema_for!(NewMilestone)),
996
        ("MilestoneEdit", schemars::schema_for!(MilestoneEdit)),
997
        ("Comment", schemars::schema_for!(Comment)),
998
        ("ProposalFile", schemars::schema_for!(ProposalFile)),
999
        ("Notification", schemars::schema_for!(Notification)),
1000
        ("Inbox", schemars::schema_for!(Inbox)),
1001
        ("Atom", schemars::schema_for!(Atom)),
1002
        ("Review", schemars::schema_for!(Review)),
1003
        ("TreeEntry", schemars::schema_for!(TreeEntry)),
1004
        ("BlameLine", schemars::schema_for!(BlameLine)),
1005
        ("FileChange", schemars::schema_for!(FileChange)),
1006
        ("ChangeDetail", schemars::schema_for!(ChangeDetail)),
1007
        ("History", schemars::schema_for!(History)),
1008
        ("Conflict", schemars::schema_for!(Conflict)),
1009
        ("Push", schemars::schema_for!(Push)),
1010
        ("Trust", schemars::schema_for!(Trust)),
1011
        ("Policy", schemars::schema_for!(Policy)),
1012
        ("Rule", schemars::schema_for!(Rule)),
1013
        ("Hook", schemars::schema_for!(Hook)),
1014
        ("NewHook", schemars::schema_for!(NewHook)),
1015
        ("Check", schemars::schema_for!(Check)),
1016
        ("CheckStatus", schemars::schema_for!(CheckStatus)),
1017
        ("NewCheck", schemars::schema_for!(NewCheck)),
1018
        ("User", schemars::schema_for!(User)),
1019
        ("Organisation", schemars::schema_for!(Organisation)),
1020
        ("NewRepository", schemars::schema_for!(NewRepository)),
1021
        ("NewIssue", schemars::schema_for!(NewIssue)),
1022
        ("IssueEdit", schemars::schema_for!(IssueEdit)),
1023
        ("ReleaseEdit", schemars::schema_for!(ReleaseEdit)),
1024
        ("ProposalEdit", schemars::schema_for!(ProposalEdit)),
1025
        ("NewLabel", schemars::schema_for!(NewLabel)),
1026
        ("RequiredChecks", schemars::schema_for!(RequiredChecks)),
1027
        ("Project", schemars::schema_for!(Project)),
1028
        ("ProjectCard", schemars::schema_for!(ProjectCard)),
1029
        ("ProjectColumn", schemars::schema_for!(ProjectColumn)),
1030
        ("Board", schemars::schema_for!(Board)),
1031
        ("NewProject", schemars::schema_for!(NewProject)),
1032
        ("ProjectEdit", schemars::schema_for!(ProjectEdit)),
1033
        ("NewCard", schemars::schema_for!(NewCard)),
1034
        ("CardMove", schemars::schema_for!(CardMove)),
1035
        ("NewComment", schemars::schema_for!(NewComment)),
1036
        ("NewProposal", schemars::schema_for!(NewProposal)),
1037
        ("NewReview", schemars::schema_for!(NewReview)),
1038
        ("IssueStateChange", schemars::schema_for!(IssueStateChange)),
1039
        ("WebhookEnvelope", schemars::schema_for!(WebhookEnvelope)),
1040
        ("ProposalEvent", schemars::schema_for!(ProposalEvent)),
1041
        ("Release", schemars::schema_for!(Release)),
1042
        ("FlowRun", schemars::schema_for!(FlowRun)),
1043
        ("FlowJob", schemars::schema_for!(FlowJob)),
1044
        ("FlowLogLine", schemars::schema_for!(FlowLogLine)),
1045
        ("AssetBuild", schemars::schema_for!(AssetBuild)),
1046
        ("ReleaseAsset", schemars::schema_for!(ReleaseAsset)),
1047
        ("NewRelease", schemars::schema_for!(NewRelease)),
1048
    ]
1049
}
1050
1051
/// An OxygenFlow runner (`GET /api/v1/runners`, site administrators).
1052
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1053
pub struct Runner {
1054
    pub id: i64,
1055
    pub name: String,
1056
    /// `online`, `offline`, `draining` or `disabled`.
1057
    pub status: String,
1058
    /// What it serves: empty for the whole site, an owner, or `owner/name`.
1059
    pub serves: String,
1060
    pub arch: String,
1061
    pub os: String,
1062
    pub version: String,
1063
    pub labels: Vec<String>,
1064
    pub max_jobs: i64,
1065
    pub memory_mib: Option<i64>,
1066
    pub cpus: Option<i64>,
1067
    /// The key that signs its receipts (KeyId hex), empty until bound.
1068
    pub key: String,
1069
    /// `registered` or `config` (a hub.toml token).
1070
    pub source: String,
1071
    pub last_seen_ms: Option<i64>,
1072
    /// Jobs it is running now.
1073
    pub running: i64,
1074
    /// What it measured at its last claim (oxygenflow#40): free disk in
1075
    /// MiB, the 1-minute load ×100, its speed score (100 on the reference
1076
    /// machine) and class 1–5, its kernel.
1077
    #[serde(default, skip_serializing_if = "Option::is_none")]
1078
    pub free_disk_mib: Option<i64>,
1079
    #[serde(default, skip_serializing_if = "Option::is_none")]
1080
    pub load_x100: Option<i64>,
1081
    #[serde(default, skip_serializing_if = "Option::is_none")]
1082
    pub speed: Option<i64>,
1083
    #[serde(default, skip_serializing_if = "Option::is_none")]
1084
    pub speed_class: Option<i64>,
1085
    #[serde(default, skip_serializing_if = "String::is_empty")]
1086
    pub kernel: String,
1087
}
1088
1089
/// A job a runner ran or is running.
1090
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1091
pub struct RunnerJob {
1092
    pub repo: String,
1093
    pub run: i64,
1094
    pub job: String,
1095
    pub status: String,
1096
    pub started_ms: Option<i64>,
1097
    pub finished_ms: Option<i64>,
1098
}
1099
1100
/// A job in the queue: running ones first, then queued ones in the order
1101
/// runners claim them.
1102
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1103
pub struct QueueItem {
1104
    pub repo: String,
1105
    pub run: i64,
1106
    pub job: String,
1107
    /// `running` or `queued`.
1108
    pub status: String,
1109
    /// The runner holding it, when running.
1110
    pub runner: String,
1111
}
1112
1113
// ------------------------------------------------------------- assistants
1114
1115
/// An AI assistant at a level (hub spec §13.4). The token never leaves the
1116
/// hub: `has_token` says whether one is set.
1117
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1118
pub struct Assistant {
1119
    pub name: String,
1120
    pub endpoint: String,
1121
    pub api: String,
1122
    pub model: String,
1123
    #[serde(default, skip_serializing_if = "String::is_empty")]
1124
    pub headers: String,
1125
    pub enabled: bool,
1126
    pub budget: i64,
1127
    pub has_token: bool,
1128
    /// Where it comes from: empty for the level's own, else `the site` or
1129
    /// `the NAME organisation`.
1130
    #[serde(default, skip_serializing_if = "String::is_empty")]
1131
    pub from: String,
1132
    /// Off because a level above turned a name like it off.
1133
    #[serde(default)]
1134
    pub off_above: bool,
1135
}
1136
1137
/// `POST …/assistants`: add one, or change the one of that name. A
1138
/// `preset` (`anthropic`, `openai`, `gemini`, `deepseek`, `mistral`,
1139
/// `perplexity`, `ollama`) fills what is left out; the model must be one
1140
/// the endpoint lists when it lists any; `token` is write-only.
1141
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1142
pub struct NewAssistant {
1143
    #[serde(default)]
1144
    pub name: String,
1145
    #[serde(default)]
1146
    pub preset: String,
1147
    #[serde(default)]
1148
    pub endpoint: String,
1149
    #[serde(default)]
1150
    pub api: String,
1151
    pub model: String,
1152
    #[serde(default)]
1153
    pub token: String,
1154
    #[serde(default)]
1155
    pub headers: String,
1156
    #[serde(default = "yes")]
1157
    pub enabled: bool,
1158
    #[serde(default)]
1159
    pub budget: Option<i64>,
1160
}
1161
1162
fn yes() -> bool {
1163
    true
1164
}
1165
1166
/// A level's prompt and those it inherits, outermost first.
1167
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1168
pub struct AssistantPrompt {
1169
    pub prompt: String,
1170
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1171
    pub inherited: Vec<(String, String)>,
1172
}
1173
1174
/// `GET /repos/{o}/{n}/coverage`: a coverage report from a Flow job
1175
/// (oxygenhub#113); `percent` values are of lines, functions and branches,
1176
/// absent when nothing was counted.
1177
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1178
pub struct CoverageReport {
1179
    pub id: i64,
1180
    pub run: i64,
1181
    pub job: String,
1182
    pub bookmark: String,
1183
    /// The run's state, by hash.
1184
    pub state: String,
1185
    /// `lcov` or `cobertura`.
1186
    pub format: String,
1187
    pub lines_found: i64,
1188
    pub lines_hit: i64,
1189
    pub percent: Option<f64>,
1190
    pub functions_found: i64,
1191
    pub functions_hit: i64,
1192
    pub branches_found: i64,
1193
    pub branches_hit: i64,
1194
    pub files: i64,
1195
    /// Files the report named that are not in the run's state.
1196
    pub dropped: i64,
1197
    pub created_ms: i64,
1198
    /// The report on the hub's Coverage tab, absolute.
1199
    pub url: String,
1200
    /// Who uploaded it from a workstation (#136), when no Flow job made it;
1201
    /// `run` and `job` are then 0 and "upload".
1202
    #[serde(default, skip_serializing_if = "Option::is_none")]
1203
    pub uploaded_by: Option<String>,
1204
}
1205
1206
/// One file of a coverage report.
1207
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1208
pub struct CoverageFile {
1209
    pub path: String,
1210
    pub lines_found: i64,
1211
    pub lines_hit: i64,
1212
    pub percent: Option<f64>,
1213
    pub functions_found: i64,
1214
    pub functions_hit: i64,
1215
    pub branches_found: i64,
1216
    pub branches_hit: i64,
1217
}
1218
1219
/// `GET /repos/{o}/{n}/coverage/{id}`: a report with its files.
1220
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1221
pub struct CoverageDetail {
1222
    pub report: CoverageReport,
1223
    pub files: Vec<CoverageFile>,
1224
}
1225
1226
/// `GET /repos/{o}/{n}/tests`: a JUnit test report from a Flow job
1227
/// (oxygenhub#114).
1228
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1229
pub struct TestReport {
1230
    pub id: i64,
1231
    pub run: i64,
1232
    pub job: String,
1233
    pub bookmark: String,
1234
    pub state: String,
1235
    pub tests: i64,
1236
    pub passed: i64,
1237
    pub failed: i64,
1238
    pub errors: i64,
1239
    pub skipped: i64,
1240
    /// The cases' times added up.
1241
    pub time_ms: i64,
1242
    pub created_ms: i64,
1243
    pub url: String,
1244
}
1245
1246
/// One test case of a report.
1247
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1248
pub struct TestCase {
1249
    pub suite: String,
1250
    pub classname: String,
1251
    pub name: String,
1252
    /// `passed`, `failed`, `error` or `skipped`.
1253
    pub status: String,
1254
    pub time_ms: i64,
1255
    pub message: String,
1256
    /// A failure's text and output, cut to 16 KiB; empty for a pass.
1257
    pub output: String,
1258
}
1259
1260
/// `GET /repos/{o}/{n}/tests/{id}`: a report with its cases
1261
/// (`?status=failed` for the failed and errored ones).
1262
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1263
pub struct TestReportDetail {
1264
    pub report: TestReport,
1265
    pub cases: Vec<TestCase>,
1266
}