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