OXYGENHUB
# 617c2840446c oxygenhub / crates / hub-api / src / lib.rs
38.3 KiB · Rust · last changed API: coverage and test reports 1 month ago source blame history raw
8d2caf12 Andy McCall ↶ 1
//! Types of the OxygenHub JSON API (hub spec §12.1). Everything here is
d23464c0 Andy McCall ↶ 2
//! `serde` data with no behaviour, so clients in other languages can be
3
//! generated from it and the server can never drift from them.
4
//!
5
//! Shapes reuse `oxy --json`'s where one exists (hashes as lowercase hex,
6
//! times as milliseconds since the epoch), so tools written against the
7
//! command line work against the hub.
8
b64e2537 Andy McCall ↶ 9
use schemars::JsonSchema;
d23464c0 Andy McCall ↶ 10
use serde::{Deserialize, Serialize};
11
12
/// A repository as the API lists it.
b64e2537 Andy McCall ↶ 13
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 14
pub struct Repository {
15
    pub owner: String,
16
    pub name: String,
17
    pub description: String,
18
    pub default_bookmark: String,
19
    pub visibility: Visibility,
20
    /// Milliseconds since the epoch.
21
    pub created_ms: i64,
22
    pub updated_ms: i64,
23
    /// `https://…/{owner}/{name}`, what `oxy clone` takes.
24
    pub clone_url: String,
25
}
26
b64e2537 Andy McCall ↶ 27
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 28
#[serde(rename_all = "lowercase")]
29
pub enum Visibility {
30
    Public,
31
    Internal,
32
    Private,
33
}
34
35
impl Visibility {
36
    pub fn as_str(self) -> &'static str {
37
        match self {
38
            Visibility::Public => "public",
39
            Visibility::Internal => "internal",
40
            Visibility::Private => "private",
41
        }
42
    }
43
44
    pub fn parse(s: &str) -> Option<Visibility> {
45
        Some(match s {
46
            "public" => Visibility::Public,
47
            "internal" => Visibility::Internal,
48
            "private" => Visibility::Private,
49
            _ => return None,
50
        })
51
    }
52
}
53
54
/// A bookmark: a name for a set of heads (spec §10.1).
b64e2537 Andy McCall ↶ 55
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 56
pub struct Bookmark {
57
    pub name: String,
58
    pub heads: Vec<String>,
59
    /// Number of changes in the bookmark's state.
60
    pub changes: usize,
61
    pub default: bool,
62
}
63
64
/// A tag: a name for one state, with its attestation when signed.
b64e2537 Andy McCall ↶ 65
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 66
pub struct Tag {
67
    pub name: String,
68
    pub heads: Vec<String>,
69
    pub message: String,
70
    pub signer: Option<String>,
71
}
72
73
/// One change in a history listing.
b64e2537 Andy McCall ↶ 74
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 75
pub struct ChangeSummary {
76
    pub hash: String,
77
    pub message: String,
78
    pub author: Author,
79
    pub when_ms: u64,
80
    pub deps: Vec<String>,
81
    pub head: bool,
82
    pub signature: Signature,
8933faff Andy McCall ↶ 83
    /// Signed for the author by a delegate (an agent), when it was.
84
    #[serde(default, skip_serializing_if = "Option::is_none")]
85
    pub via: Option<Via>,
86
}
87
88
/// A delegate that signed a change for its author (Oxygen spec §14.2).
89
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
90
pub struct Via {
91
    pub name: String,
92
    pub key: String,
93
    /// The delegation's scope, `changes` for an agent.
94
    pub scope: String,
95
    pub expires_ms: Option<u64>,
96
    /// The delegation has since been revoked or withdrawn.
97
    pub revoked: bool,
d23464c0 Andy McCall ↶ 98
}
99
100
/// Who wrote a change: the linked account when the signing key is linked,
101
/// else the key alone.
b64e2537 Andy McCall ↶ 102
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 103
pub struct Author {
104
    pub name: String,
105
    pub email: String,
106
    pub key: String,
107
    /// The hub account this key is linked to, when any.
108
    pub account: Option<String>,
760a7dd3 Andy McCall ↶ 109
    /// Set when the change is signed by a key no account has linked, and
110
    /// says how its owner links it.
111
    #[serde(default, skip_serializing_if = "Option::is_none")]
112
    pub note: Option<String>,
113
}
114
115
impl Author {
116
    /// What `note` says for a key that no account has linked.
117
    pub const UNLINKED: &'static str =
118
        "signed by a key not linked to any account; its owner links it under Settings → Keys (/settings/keys)";
119
120
    /// The note for an author with this key and account.
121
    pub fn note_for(key: &str, account: &Option<String>) -> Option<String> {
122
        (!key.is_empty() && account.is_none()).then(|| Self::UNLINKED.to_string())
123
    }
d23464c0 Andy McCall ↶ 124
}
125
126
/// Signature status of a change as `oxy verify` reports it.
b64e2537 Andy McCall ↶ 127
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 128
#[serde(tag = "status", rename_all = "lowercase")]
129
pub enum Signature {
130
    Unsigned,
131
    Valid { key: String, sealed: bool, revoked: bool },
132
    Invalid { reason: String },
133
}
134
135
/// An RFC 7807 problem response.
b64e2537 Andy McCall ↶ 136
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 137
pub struct Problem {
138
    pub status: u16,
139
    pub title: String,
140
    pub detail: String,
141
}
142
143
#[cfg(test)]
144
mod tests {
145
    use super::*;
146
147
    #[test]
148
    fn visibility_round_trips() {
149
        for v in [Visibility::Public, Visibility::Internal, Visibility::Private] {
150
            assert_eq!(Visibility::parse(v.as_str()), Some(v));
151
        }
152
        assert_eq!(Visibility::parse("secret"), None);
153
    }
154
}
de505df5 Andy McCall ↶ 155
156
// ---------------------------------------------------------------- proposals
157
158
/// A proposal: a request to add changes to a target bookmark (hub spec §7).
b64e2537 Andy McCall ↶ 159
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
de505df5 Andy McCall ↶ 160
pub struct Proposal {
161
    pub number: i64,
162
    pub title: String,
163
    pub body: String,
164
    pub author: String,
165
    pub state: ProposalState,
166
    pub target: String,
167
    pub source: ProposalSource,
168
    /// The changes the proposal adds, dependency order, newest last.
169
    pub changes: Vec<ChangeSummary>,
170
    /// Heads of the projected state (target plus the changes), when computed.
171
    pub projected_heads: Vec<String>,
172
    pub projected_state: Option<String>,
173
    pub conflicted: bool,
174
    pub approvals: Vec<Approval>,
175
    pub landable: bool,
176
    pub blockers: Vec<String>,
177
    pub created_ms: i64,
178
    pub updated_ms: i64,
179
    /// `https://hub/{owner}/{name}/proposal/{number}`.
180
    pub url: String,
181
    /// Where `oxy` fetches the changes from.
182
    pub repository_url: String,
183
    /// The fork's clone URL when the source is a fork.
184
    pub source_url: Option<String>,
0b20f1ec Andy McCall ↶ 185
    /// Who landed it, how and when, once landed.
186
    #[serde(default)]
187
    pub landed: Option<Landed>,
cc1cd197 Andy McCall ↶ 188
    /// Asked to review and not yet reviewing, in the order asked.
189
    #[serde(default)]
190
    pub requested_reviewers: Vec<String>,
2291f8cc Andy McCall ↶ 191
    #[serde(default)]
192
    pub labels: Vec<Label>,
0b20f1ec Andy McCall ↶ 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,
de505df5 Andy McCall ↶ 202
}
203
b64e2537 Andy McCall ↶ 204
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
de505df5 Andy McCall ↶ 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
b64e2537 Andy McCall ↶ 234
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
de505df5 Andy McCall ↶ 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.
b64e2537 Andy McCall ↶ 247
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
de505df5 Andy McCall ↶ 248
pub struct Approval {
249
    pub account: String,
250
    pub sealed: bool,
251
    pub key: Option<String>,
252
}
b64e2537 Andy McCall ↶ 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
5ea4872f Andy McCall ↶ 293
/// `POST /repos/{o}/{n}/milestones`: create a milestone, or change the
294
/// description and due date of the one with that title (triage).
b64e2537 Andy McCall ↶ 295
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5ea4872f Andy McCall ↶ 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)]
b64e2537 Andy McCall ↶ 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
42a0ba4b Andy McCall ↶ 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
3f02e5ea Andy McCall ↶ 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}`.
b64e2537 Andy McCall ↶ 357
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
3f02e5ea Andy McCall ↶ 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)]
b64e2537 Andy McCall ↶ 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,
7d2eb590 Andy McCall ↶ 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,
b64e2537 Andy McCall ↶ 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
90326c96 Andy McCall ↶ 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,
bf3d0754 Andy McCall ↶ 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>,
90326c96 Andy McCall ↶ 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,
4d2e44d7 Andy McCall ↶ 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,
90326c96 Andy McCall ↶ 558
}
559
560
/// A line of a job's log.
561
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
562
pub struct FlowLogLine {
563
    /// Increasing within the job; pass the last one as `after` for more.
564
    pub seq: i64,
565
    /// Milliseconds since the job started.
566
    pub t: i64,
567
    /// `stdout`, `stderr` or `flow` (the runner's own notes).
568
    pub stream: String,
569
    pub text: String,
570
}
571
b64e2537 Andy McCall ↶ 572
/// A check on a state hash (hub spec §13.1).
573
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
574
pub struct Check {
575
    pub state: String,
576
    pub name: String,
577
    pub status: CheckStatus,
578
    pub summary: String,
579
    pub url: String,
580
    pub reporter: String,
581
    /// The seal attestation's reference when the checker sealed the changes.
582
    pub seal: Option<String>,
583
    pub started_ms: i64,
584
    pub finished_ms: Option<i64>,
585
}
586
587
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
588
#[serde(rename_all = "lowercase")]
589
pub enum CheckStatus {
590
    Queued,
591
    Running,
592
    Passed,
593
    Failed,
594
    Cancelled,
595
    Skipped,
596
}
597
598
impl CheckStatus {
599
    pub fn as_str(self) -> &'static str {
600
        match self {
601
            CheckStatus::Queued => "queued",
602
            CheckStatus::Running => "running",
603
            CheckStatus::Passed => "passed",
604
            CheckStatus::Failed => "failed",
605
            CheckStatus::Cancelled => "cancelled",
606
            CheckStatus::Skipped => "skipped",
607
        }
608
    }
609
610
    pub fn parse(s: &str) -> Option<CheckStatus> {
611
        Some(match s {
612
            "queued" => CheckStatus::Queued,
613
            "running" => CheckStatus::Running,
614
            "passed" => CheckStatus::Passed,
615
            "failed" => CheckStatus::Failed,
616
            "cancelled" => CheckStatus::Cancelled,
617
            "skipped" => CheckStatus::Skipped,
618
            _ => return None,
619
        })
620
    }
621
}
622
623
/// What a checker posts.
624
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
625
pub struct NewCheck {
626
    pub state: String,
627
    pub name: String,
628
    pub status: CheckStatus,
629
    #[serde(default)]
630
    pub summary: String,
631
    #[serde(default)]
632
    pub url: String,
633
    /// Hex of a seal attestation reference the checker pushed, if any.
634
    #[serde(default)]
635
    pub seal: Option<String>,
636
}
637
638
// ------------------------------------------------------------- accounts
639
640
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
641
pub struct User {
642
    pub username: String,
643
    pub display_name: String,
644
    pub is_admin: bool,
645
    pub keys: Vec<String>,
646
    pub created_ms: i64,
647
}
648
649
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
650
pub struct Organisation {
651
    pub name: String,
652
    pub display_name: String,
653
    pub description: String,
654
    pub members: Vec<String>,
655
}
656
657
/// Forms accepted by the write endpoints.
658
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
659
pub struct NewRepository {
660
    pub owner: String,
661
    pub name: String,
662
    #[serde(default)]
663
    pub description: String,
664
    #[serde(default = "public")]
665
    pub visibility: Visibility,
666
}
667
668
fn public() -> Visibility {
669
    Visibility::Public
670
}
671
672
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
673
pub struct NewIssue {
674
    pub title: String,
675
    #[serde(default)]
676
    pub body: String,
76f262e1 Andy McCall ↶ 677
    /// Label names; each must exist. Needs triage.
678
    #[serde(default)]
679
    pub labels: Vec<String>,
680
    /// Usernames. Needs triage.
681
    #[serde(default)]
682
    pub assignees: Vec<String>,
683
    /// A milestone's title. Needs triage.
684
    #[serde(default)]
685
    pub milestone: Option<String>,
b64e2537 Andy McCall ↶ 686
}
687
76f262e1 Andy McCall ↶ 688
/// `PATCH /repos/{o}/{n}/issues/{number}`: only the fields given change.
689
/// Title and body: the author or triage. The rest: triage.
690
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
691
pub struct IssueEdit {
692
    #[serde(default)]
693
    pub title: Option<String>,
694
    #[serde(default)]
695
    pub body: Option<String>,
696
    /// The whole set of labels.
697
    #[serde(default)]
698
    pub labels: Option<Vec<String>>,
699
    /// The whole set of assignees.
700
    #[serde(default)]
701
    pub assignees: Option<Vec<String>>,
702
    /// A milestone's title; the empty string clears it.
703
    #[serde(default)]
704
    pub milestone: Option<String>,
705
}
706
961c10be Andy McCall ↶ 707
/// The checks a proposal needs, passed, to land on the repository's
708
/// default bookmark (hub spec §13.1). `GET` and `PUT
709
/// /repos/{o}/{n}/checks/required`.
710
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
711
pub struct RequiredChecks {
712
    pub names: Vec<String>,
713
}
714
ef20fdc1 Andy McCall ↶ 715
/// A project (hub spec §8.2).
716
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
717
pub struct Project {
718
    pub owner: String,
719
    pub number: i64,
720
    pub title: String,
721
    pub description: String,
722
    pub public: bool,
723
    pub closed: bool,
724
    pub updated_ms: i64,
725
    /// The board on the hub, absolute.
726
    pub url: String,
727
}
728
729
/// A card as the caller may see it.
730
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
731
pub struct ProjectCard {
732
    pub id: i64,
733
    /// `issue`, `proposal` or `note`.
734
    pub kind: String,
735
    /// `owner/name#N`; empty for a note.
736
    pub reference: String,
737
    /// The issue's or proposal's title, or the note.
738
    pub title: String,
739
    /// The issue's or proposal's state; empty for a note.
740
    pub state: String,
741
}
742
743
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
744
pub struct ProjectColumn {
745
    pub id: i64,
746
    pub name: String,
747
    pub cards: Vec<ProjectCard>,
748
}
749
750
/// `GET /projects/{owner}/{n}`.
751
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
752
pub struct Board {
753
    pub project: Project,
754
    pub columns: Vec<ProjectColumn>,
755
}
756
757
/// `POST /projects/{owner}`.
758
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
759
pub struct NewProject {
760
    pub title: String,
761
    #[serde(default)]
762
    pub description: String,
763
    #[serde(default)]
764
    pub private: bool,
765
}
766
767
/// `PATCH /projects/{owner}/{n}`: only the fields given change.
768
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
769
pub struct ProjectEdit {
770
    #[serde(default)]
771
    pub title: Option<String>,
772
    #[serde(default)]
773
    pub description: Option<String>,
774
    #[serde(default)]
775
    pub private: Option<bool>,
776
    #[serde(default)]
777
    pub closed: Option<bool>,
778
}
779
780
/// `POST /projects/{owner}/{n}/cards`: a reference (`repo#12`) or a note,
781
/// into the column named (by id or name; the first column when absent).
782
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
783
pub struct NewCard {
784
    #[serde(default)]
785
    pub column: Option<String>,
786
    #[serde(default)]
787
    pub reference: String,
788
    #[serde(default)]
789
    pub note: String,
790
}
791
792
/// `PATCH /projects/{owner}/{n}/cards/{id}`: move to a column (id or name).
793
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
794
pub struct CardMove {
795
    pub column: String,
796
}
797
76f262e1 Andy McCall ↶ 798
/// `POST /repos/{o}/{n}/labels`: create a label, or change one of that name.
799
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
800
pub struct NewLabel {
801
    pub name: String,
802
    /// `#rrggbb`; a default when absent.
803
    #[serde(default)]
804
    pub colour: Option<String>,
805
    #[serde(default)]
806
    pub description: String,
807
}
808
b64e2537 Andy McCall ↶ 809
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
810
pub struct NewComment {
811
    pub body: String,
3f4b0ea6 Andy McCall ↶ 812
    /// For a proposal: anchor the comment to this file's line (1-based) of
813
    /// the projected state; the hub records the line's atom.
814
    #[serde(default)]
815
    pub path: Option<String>,
816
    #[serde(default)]
817
    pub line: Option<usize>,
b64e2537 Andy McCall ↶ 818
}
819
820
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
821
pub struct NewProposal {
822
    pub title: String,
823
    #[serde(default)]
824
    pub body: String,
825
    pub target: String,
826
    /// A bookmark here, or `owner/name:bookmark` of a fork.
827
    pub source: String,
828
    #[serde(default)]
829
    pub draft: bool,
cc1cd197 Andy McCall ↶ 830
}
831
832
/// `POST .../proposals/{number}/reviewers`: accounts to ask for a review.
833
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
834
pub struct ReviewRequest {
835
    pub reviewers: Vec<String>,
7d2eb590 Andy McCall ↶ 836
}
837
838
/// `POST .../proposals/{number}/review-requests`: ask an AI assistant the
839
/// repository may use (hub spec §13.4) to review; it answers as a `comment`
840
/// review via the assistant.
841
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
842
pub struct AssistantRequest {
843
    pub assistant: String,
b64e2537 Andy McCall ↶ 844
}
845
846
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
847
pub struct NewReview {
848
    pub verdict: String,
849
    #[serde(default)]
850
    pub body: String,
851
}
852
853
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
854
pub struct IssueStateChange {
855
    /// `open` or `closed`.
856
    pub state: String,
857
    #[serde(default)]
858
    pub reason: String,
859
}
860
861
/// A webhook payload's envelope (hub spec §12.2).
862
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
863
pub struct WebhookEnvelope {
864
    pub event: String,
865
    pub delivery: String,
866
    pub repository: Option<Repository>,
867
    pub actor: String,
868
    pub at_ms: i64,
869
    pub data: serde_json::Value,
870
}
871
872
/// A server-sent event on a proposal's stream.
873
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
874
pub struct ProposalEvent {
875
    pub number: i64,
876
    pub kind: String,
877
    pub check: Option<Check>,
878
}
879
3f4b0ea6 Andy McCall ↶ 880
// --------------------------------------------------------------- releases
881
882
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
883
pub struct Release {
884
    pub tag: String,
885
    pub title: String,
886
    pub notes: String,
887
    pub prerelease: bool,
888
    pub latest: bool,
889
    pub author: String,
890
    pub heads: Vec<String>,
891
    pub signer: Option<String>,
892
    pub assets: Vec<ReleaseAsset>,
893
    pub archives: Vec<String>,
894
    pub created_ms: i64,
895
    pub url: String,
896
}
897
898
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
899
pub struct ReleaseAsset {
900
    pub name: String,
901
    pub size: i64,
902
    /// BLAKE3 of the content, hex.
903
    pub hash: String,
904
    pub content_type: String,
905
    pub downloads: i64,
906
    pub url: String,
10708ab8 Andy McCall ↶ 907
    /// The OxygenFlow run and job whose artifact has this content, if any.
908
    #[serde(default, skip_serializing_if = "Option::is_none")]
909
    pub built_by: Option<AssetBuild>,
910
}
911
912
/// Where a release asset was built (hub spec §9): a job's artifact with the
913
/// same BLAKE3, and that job's signed receipt when one was kept.
914
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
915
pub struct AssetBuild {
916
    pub run: i64,
917
    pub job: String,
918
    pub artifact: String,
919
    pub run_url: String,
920
    /// The receipt attestation, hex; `None` when the receipt was not signed.
921
    pub receipt: Option<String>,
922
    pub receipt_url: Option<String>,
923
    pub signer: Option<String>,
3f4b0ea6 Andy McCall ↶ 924
}
925
739a763a Andy McCall ↶ 926
/// `PATCH /repos/{o}/{n}/proposals/{number}`: what is given changes,
927
/// the rest stays (oxygenhub#76).
928
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
929
pub struct ProposalEdit {
930
    #[serde(default, skip_serializing_if = "Option::is_none")]
931
    pub title: Option<String>,
932
    #[serde(default, skip_serializing_if = "Option::is_none")]
933
    pub body: Option<String>,
2291f8cc Andy McCall ↶ 934
    /// The whole set of labels, by name (triage); oxygenhub#80.
935
    #[serde(default, skip_serializing_if = "Option::is_none")]
936
    pub labels: Option<Vec<String>>,
739a763a Andy McCall ↶ 937
}
938
ced6d3af Andy McCall ↶ 939
/// `PATCH /repos/{owner}/{name}/releases/{tag}`: what to change; fields
940
/// left out stay as they are.
941
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
942
pub struct ReleaseEdit {
943
    #[serde(default, skip_serializing_if = "Option::is_none")]
944
    pub title: Option<String>,
945
    #[serde(default, skip_serializing_if = "Option::is_none")]
946
    pub notes: Option<String>,
947
    #[serde(default, skip_serializing_if = "Option::is_none")]
948
    pub prerelease: Option<bool>,
949
}
950
3f4b0ea6 Andy McCall ↶ 951
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
952
pub struct NewRelease {
953
    pub tag: String,
954
    pub title: String,
955
    #[serde(default)]
956
    pub notes: Option<String>,
957
    #[serde(default)]
958
    pub prerelease: bool,
959
}
960
b64e2537 Andy McCall ↶ 961
/// Every type of the API, for schema generation.
962
pub fn schemas() -> Vec<(&'static str, schemars::Schema)> {
963
    vec![
964
        ("Repository", schemars::schema_for!(Repository)),
965
        ("Visibility", schemars::schema_for!(Visibility)),
966
        ("Bookmark", schemars::schema_for!(Bookmark)),
967
        ("Tag", schemars::schema_for!(Tag)),
968
        ("ChangeSummary", schemars::schema_for!(ChangeSummary)),
969
        ("Author", schemars::schema_for!(Author)),
970
        ("Signature", schemars::schema_for!(Signature)),
971
        ("Problem", schemars::schema_for!(Problem)),
972
        ("Proposal", schemars::schema_for!(Proposal)),
973
        ("ProposalState", schemars::schema_for!(ProposalState)),
974
        ("ProposalSource", schemars::schema_for!(ProposalSource)),
975
        ("Approval", schemars::schema_for!(Approval)),
976
        ("Issue", schemars::schema_for!(Issue)),
977
        ("Label", schemars::schema_for!(Label)),
978
        ("Milestone", schemars::schema_for!(Milestone)),
5ea4872f Andy McCall ↶ 979
        ("NewMilestone", schemars::schema_for!(NewMilestone)),
980
        ("MilestoneEdit", schemars::schema_for!(MilestoneEdit)),
b64e2537 Andy McCall ↶ 981
        ("Comment", schemars::schema_for!(Comment)),
3f02e5ea Andy McCall ↶ 982
        ("ProposalFile", schemars::schema_for!(ProposalFile)),
42a0ba4b Andy McCall ↶ 983
        ("Notification", schemars::schema_for!(Notification)),
984
        ("Inbox", schemars::schema_for!(Inbox)),
b64e2537 Andy McCall ↶ 985
        ("Atom", schemars::schema_for!(Atom)),
986
        ("Review", schemars::schema_for!(Review)),
987
        ("TreeEntry", schemars::schema_for!(TreeEntry)),
988
        ("BlameLine", schemars::schema_for!(BlameLine)),
989
        ("FileChange", schemars::schema_for!(FileChange)),
990
        ("ChangeDetail", schemars::schema_for!(ChangeDetail)),
991
        ("History", schemars::schema_for!(History)),
992
        ("Conflict", schemars::schema_for!(Conflict)),
993
        ("Push", schemars::schema_for!(Push)),
994
        ("Trust", schemars::schema_for!(Trust)),
995
        ("Policy", schemars::schema_for!(Policy)),
996
        ("Rule", schemars::schema_for!(Rule)),
997
        ("Hook", schemars::schema_for!(Hook)),
998
        ("NewHook", schemars::schema_for!(NewHook)),
999
        ("Check", schemars::schema_for!(Check)),
1000
        ("CheckStatus", schemars::schema_for!(CheckStatus)),
1001
        ("NewCheck", schemars::schema_for!(NewCheck)),
1002
        ("User", schemars::schema_for!(User)),
1003
        ("Organisation", schemars::schema_for!(Organisation)),
1004
        ("NewRepository", schemars::schema_for!(NewRepository)),
1005
        ("NewIssue", schemars::schema_for!(NewIssue)),
76f262e1 Andy McCall ↶ 1006
        ("IssueEdit", schemars::schema_for!(IssueEdit)),
2291f8cc Andy McCall ↶ 1007
        ("ReleaseEdit", schemars::schema_for!(ReleaseEdit)),
1008
        ("ProposalEdit", schemars::schema_for!(ProposalEdit)),
76f262e1 Andy McCall ↶ 1009
        ("NewLabel", schemars::schema_for!(NewLabel)),
961c10be Andy McCall ↶ 1010
        ("RequiredChecks", schemars::schema_for!(RequiredChecks)),
ef20fdc1 Andy McCall ↶ 1011
        ("Project", schemars::schema_for!(Project)),
1012
        ("ProjectCard", schemars::schema_for!(ProjectCard)),
1013
        ("ProjectColumn", schemars::schema_for!(ProjectColumn)),
1014
        ("Board", schemars::schema_for!(Board)),
1015
        ("NewProject", schemars::schema_for!(NewProject)),
1016
        ("ProjectEdit", schemars::schema_for!(ProjectEdit)),
1017
        ("NewCard", schemars::schema_for!(NewCard)),
1018
        ("CardMove", schemars::schema_for!(CardMove)),
b64e2537 Andy McCall ↶ 1019
        ("NewComment", schemars::schema_for!(NewComment)),
1020
        ("NewProposal", schemars::schema_for!(NewProposal)),
1021
        ("NewReview", schemars::schema_for!(NewReview)),
1022
        ("IssueStateChange", schemars::schema_for!(IssueStateChange)),
1023
        ("WebhookEnvelope", schemars::schema_for!(WebhookEnvelope)),
1024
        ("ProposalEvent", schemars::schema_for!(ProposalEvent)),
3f4b0ea6 Andy McCall ↶ 1025
        ("Release", schemars::schema_for!(Release)),
bf1ab345 Andy McCall ↶ 1026
        ("FlowRun", schemars::schema_for!(FlowRun)),
1027
        ("FlowJob", schemars::schema_for!(FlowJob)),
1028
        ("FlowLogLine", schemars::schema_for!(FlowLogLine)),
1029
        ("AssetBuild", schemars::schema_for!(AssetBuild)),
3f4b0ea6 Andy McCall ↶ 1030
        ("ReleaseAsset", schemars::schema_for!(ReleaseAsset)),
1031
        ("NewRelease", schemars::schema_for!(NewRelease)),
b64e2537 Andy McCall ↶ 1032
    ]
1033
}
b66e70b7 Andy McCall ↶ 1034
1035
/// An OxygenFlow runner (`GET /api/v1/runners`, site administrators).
1036
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1037
pub struct Runner {
1038
    pub id: i64,
1039
    pub name: String,
1040
    /// `online`, `offline`, `draining` or `disabled`.
1041
    pub status: String,
1042
    /// What it serves: empty for the whole site, an owner, or `owner/name`.
1043
    pub serves: String,
1044
    pub arch: String,
1045
    pub os: String,
1046
    pub version: String,
1047
    pub labels: Vec<String>,
1048
    pub max_jobs: i64,
1049
    pub memory_mib: Option<i64>,
1050
    pub cpus: Option<i64>,
1051
    /// The key that signs its receipts (KeyId hex), empty until bound.
1052
    pub key: String,
1053
    /// `registered` or `config` (a hub.toml token).
1054
    pub source: String,
1055
    pub last_seen_ms: Option<i64>,
1056
    /// Jobs it is running now.
1057
    pub running: i64,
1058
}
1059
1060
/// A job a runner ran or is running.
1061
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1062
pub struct RunnerJob {
1063
    pub repo: String,
1064
    pub run: i64,
1065
    pub job: String,
1066
    pub status: String,
1067
    pub started_ms: Option<i64>,
1068
    pub finished_ms: Option<i64>,
1069
}
1070
1071
/// A job in the queue: running ones first, then queued ones in the order
1072
/// runners claim them.
1073
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1074
pub struct QueueItem {
1075
    pub repo: String,
1076
    pub run: i64,
1077
    pub job: String,
1078
    /// `running` or `queued`.
1079
    pub status: String,
1080
    /// The runner holding it, when running.
1081
    pub runner: String,
1082
}
62ceb2ee Andy McCall ↶ 1083
1084
// ------------------------------------------------------------- assistants
1085
1086
/// An AI assistant at a level (hub spec §13.4). The token never leaves the
1087
/// hub: `has_token` says whether one is set.
1088
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1089
pub struct Assistant {
1090
    pub name: String,
1091
    pub endpoint: String,
1092
    pub api: String,
1093
    pub model: String,
1094
    #[serde(default, skip_serializing_if = "String::is_empty")]
1095
    pub headers: String,
1096
    pub enabled: bool,
1097
    pub budget: i64,
1098
    pub has_token: bool,
1099
    /// Where it comes from: empty for the level's own, else `the site` or
1100
    /// `the NAME organisation`.
1101
    #[serde(default, skip_serializing_if = "String::is_empty")]
1102
    pub from: String,
1103
    /// Off because a level above turned a name like it off.
1104
    #[serde(default)]
1105
    pub off_above: bool,
1106
}
1107
1108
/// `POST …/assistants`: add one, or change the one of that name. A
1109
/// `preset` (`anthropic`, `openai`, `gemini`, `deepseek`, `mistral`,
1110
/// `perplexity`, `ollama`) fills what is left out; the model must be one
1111
/// the endpoint lists when it lists any; `token` is write-only.
1112
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1113
pub struct NewAssistant {
1114
    #[serde(default)]
1115
    pub name: String,
1116
    #[serde(default)]
1117
    pub preset: String,
1118
    #[serde(default)]
1119
    pub endpoint: String,
1120
    #[serde(default)]
1121
    pub api: String,
1122
    pub model: String,
1123
    #[serde(default)]
1124
    pub token: String,
1125
    #[serde(default)]
1126
    pub headers: String,
1127
    #[serde(default = "yes")]
1128
    pub enabled: bool,
1129
    #[serde(default)]
1130
    pub budget: Option<i64>,
1131
}
1132
1133
fn yes() -> bool {
1134
    true
1135
}
1136
1137
/// A level's prompt and those it inherits, outermost first.
1138
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1139
pub struct AssistantPrompt {
1140
    pub prompt: String,
1141
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1142
    pub inherited: Vec<(String, String)>,
1143
}
617c2840 Andy McCall ↶ 1144
1145
/// `GET /repos/{o}/{n}/coverage`: a coverage report from a Flow job
1146
/// (oxygenhub#113); `percent` values are of lines, functions and branches,
1147
/// absent when nothing was counted.
1148
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1149
pub struct CoverageReport {
1150
    pub id: i64,
1151
    pub run: i64,
1152
    pub job: String,
1153
    pub bookmark: String,
1154
    /// The run's state, by hash.
1155
    pub state: String,
1156
    /// `lcov` or `cobertura`.
1157
    pub format: String,
1158
    pub lines_found: i64,
1159
    pub lines_hit: i64,
1160
    pub percent: Option<f64>,
1161
    pub functions_found: i64,
1162
    pub functions_hit: i64,
1163
    pub branches_found: i64,
1164
    pub branches_hit: i64,
1165
    pub files: i64,
1166
    /// Files the report named that are not in the run's state.
1167
    pub dropped: i64,
1168
    pub created_ms: i64,
1169
    /// The report on the hub's Coverage tab, absolute.
1170
    pub url: String,
1171
}
1172
1173
/// One file of a coverage report.
1174
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1175
pub struct CoverageFile {
1176
    pub path: String,
1177
    pub lines_found: i64,
1178
    pub lines_hit: i64,
1179
    pub percent: Option<f64>,
1180
    pub functions_found: i64,
1181
    pub functions_hit: i64,
1182
    pub branches_found: i64,
1183
    pub branches_hit: i64,
1184
}
1185
1186
/// `GET /repos/{o}/{n}/coverage/{id}`: a report with its files.
1187
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1188
pub struct CoverageDetail {
1189
    pub report: CoverageReport,
1190
    pub files: Vec<CoverageFile>,
1191
}
1192
1193
/// `GET /repos/{o}/{n}/tests`: a JUnit test report from a Flow job
1194
/// (oxygenhub#114).
1195
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1196
pub struct TestReport {
1197
    pub id: i64,
1198
    pub run: i64,
1199
    pub job: String,
1200
    pub bookmark: String,
1201
    pub state: String,
1202
    pub tests: i64,
1203
    pub passed: i64,
1204
    pub failed: i64,
1205
    pub errors: i64,
1206
    pub skipped: i64,
1207
    /// The cases' times added up.
1208
    pub time_ms: i64,
1209
    pub created_ms: i64,
1210
    pub url: String,
1211
}
1212
1213
/// One test case of a report.
1214
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1215
pub struct TestCase {
1216
    pub suite: String,
1217
    pub classname: String,
1218
    pub name: String,
1219
    /// `passed`, `failed`, `error` or `skipped`.
1220
    pub status: String,
1221
    pub time_ms: i64,
1222
    pub message: String,
1223
    /// A failure's text and output, cut to 16 KiB; empty for a pass.
1224
    pub output: String,
1225
}
1226
1227
/// `GET /repos/{o}/{n}/tests/{id}`: a report with its cases
1228
/// (`?status=failed` for the failed and errored ones).
1229
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1230
pub struct TestReportDetail {
1231
    pub report: TestReport,
1232
    pub cases: Vec<TestCase>,
1233
}