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