OXYGENHUB
# f3e5e2bc78e9 oxygenhub / crates / hub-api / src / lib.rs
38.5 KiB · Rust · last changed Transfer a project to another owner 25 days 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 {
b1e92a62 Andy McCall ↶ 770
    /// Transfer the board to this owner (#125): one the caller may make
771
    /// boards under. It takes the next number there.
772
    #[serde(default, skip_serializing_if = "Option::is_none")]
773
    pub owner: Option<String>,
ef20fdc1 Andy McCall ↶ 774
    #[serde(default)]
775
    pub title: Option<String>,
776
    #[serde(default)]
777
    pub description: Option<String>,
778
    #[serde(default)]
779
    pub private: Option<bool>,
780
    #[serde(default)]
781
    pub closed: Option<bool>,
782
}
783
784
/// `POST /projects/{owner}/{n}/cards`: a reference (`repo#12`) or a note,
785
/// into the column named (by id or name; the first column when absent).
786
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
787
pub struct NewCard {
788
    #[serde(default)]
789
    pub column: Option<String>,
790
    #[serde(default)]
791
    pub reference: String,
792
    #[serde(default)]
793
    pub note: String,
794
}
795
796
/// `PATCH /projects/{owner}/{n}/cards/{id}`: move to a column (id or name).
797
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
798
pub struct CardMove {
799
    pub column: String,
800
}
801
76f262e1 Andy McCall ↶ 802
/// `POST /repos/{o}/{n}/labels`: create a label, or change one of that name.
803
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
804
pub struct NewLabel {
805
    pub name: String,
806
    /// `#rrggbb`; a default when absent.
807
    #[serde(default)]
808
    pub colour: Option<String>,
809
    #[serde(default)]
810
    pub description: String,
811
}
812
b64e2537 Andy McCall ↶ 813
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
814
pub struct NewComment {
815
    pub body: String,
3f4b0ea6 Andy McCall ↶ 816
    /// For a proposal: anchor the comment to this file's line (1-based) of
817
    /// the projected state; the hub records the line's atom.
818
    #[serde(default)]
819
    pub path: Option<String>,
820
    #[serde(default)]
821
    pub line: Option<usize>,
b64e2537 Andy McCall ↶ 822
}
823
824
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
825
pub struct NewProposal {
826
    pub title: String,
827
    #[serde(default)]
828
    pub body: String,
829
    pub target: String,
830
    /// A bookmark here, or `owner/name:bookmark` of a fork.
831
    pub source: String,
832
    #[serde(default)]
833
    pub draft: bool,
cc1cd197 Andy McCall ↶ 834
}
835
836
/// `POST .../proposals/{number}/reviewers`: accounts to ask for a review.
837
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
838
pub struct ReviewRequest {
839
    pub reviewers: Vec<String>,
7d2eb590 Andy McCall ↶ 840
}
841
842
/// `POST .../proposals/{number}/review-requests`: ask an AI assistant the
843
/// repository may use (hub spec §13.4) to review; it answers as a `comment`
844
/// review via the assistant.
845
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
846
pub struct AssistantRequest {
847
    pub assistant: String,
b64e2537 Andy McCall ↶ 848
}
849
850
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
851
pub struct NewReview {
852
    pub verdict: String,
853
    #[serde(default)]
854
    pub body: String,
855
}
856
857
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
858
pub struct IssueStateChange {
859
    /// `open` or `closed`.
860
    pub state: String,
861
    #[serde(default)]
862
    pub reason: String,
863
}
864
865
/// A webhook payload's envelope (hub spec §12.2).
866
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
867
pub struct WebhookEnvelope {
868
    pub event: String,
869
    pub delivery: String,
870
    pub repository: Option<Repository>,
871
    pub actor: String,
872
    pub at_ms: i64,
873
    pub data: serde_json::Value,
874
}
875
876
/// A server-sent event on a proposal's stream.
877
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
878
pub struct ProposalEvent {
879
    pub number: i64,
880
    pub kind: String,
881
    pub check: Option<Check>,
882
}
883
3f4b0ea6 Andy McCall ↶ 884
// --------------------------------------------------------------- releases
885
886
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
887
pub struct Release {
888
    pub tag: String,
889
    pub title: String,
890
    pub notes: String,
891
    pub prerelease: bool,
892
    pub latest: bool,
893
    pub author: String,
894
    pub heads: Vec<String>,
895
    pub signer: Option<String>,
896
    pub assets: Vec<ReleaseAsset>,
897
    pub archives: Vec<String>,
898
    pub created_ms: i64,
899
    pub url: String,
900
}
901
902
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
903
pub struct ReleaseAsset {
904
    pub name: String,
905
    pub size: i64,
906
    /// BLAKE3 of the content, hex.
907
    pub hash: String,
908
    pub content_type: String,
909
    pub downloads: i64,
910
    pub url: String,
10708ab8 Andy McCall ↶ 911
    /// The OxygenFlow run and job whose artifact has this content, if any.
912
    #[serde(default, skip_serializing_if = "Option::is_none")]
913
    pub built_by: Option<AssetBuild>,
914
}
915
916
/// Where a release asset was built (hub spec §9): a job's artifact with the
917
/// same BLAKE3, and that job's signed receipt when one was kept.
918
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
919
pub struct AssetBuild {
920
    pub run: i64,
921
    pub job: String,
922
    pub artifact: String,
923
    pub run_url: String,
924
    /// The receipt attestation, hex; `None` when the receipt was not signed.
925
    pub receipt: Option<String>,
926
    pub receipt_url: Option<String>,
927
    pub signer: Option<String>,
3f4b0ea6 Andy McCall ↶ 928
}
929
739a763a Andy McCall ↶ 930
/// `PATCH /repos/{o}/{n}/proposals/{number}`: what is given changes,
931
/// the rest stays (oxygenhub#76).
932
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
933
pub struct ProposalEdit {
934
    #[serde(default, skip_serializing_if = "Option::is_none")]
935
    pub title: Option<String>,
936
    #[serde(default, skip_serializing_if = "Option::is_none")]
937
    pub body: Option<String>,
2291f8cc Andy McCall ↶ 938
    /// The whole set of labels, by name (triage); oxygenhub#80.
939
    #[serde(default, skip_serializing_if = "Option::is_none")]
940
    pub labels: Option<Vec<String>>,
739a763a Andy McCall ↶ 941
}
942
ced6d3af Andy McCall ↶ 943
/// `PATCH /repos/{owner}/{name}/releases/{tag}`: what to change; fields
944
/// left out stay as they are.
945
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
946
pub struct ReleaseEdit {
947
    #[serde(default, skip_serializing_if = "Option::is_none")]
948
    pub title: Option<String>,
949
    #[serde(default, skip_serializing_if = "Option::is_none")]
950
    pub notes: Option<String>,
951
    #[serde(default, skip_serializing_if = "Option::is_none")]
952
    pub prerelease: Option<bool>,
953
}
954
3f4b0ea6 Andy McCall ↶ 955
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
956
pub struct NewRelease {
957
    pub tag: String,
958
    pub title: String,
959
    #[serde(default)]
960
    pub notes: Option<String>,
961
    #[serde(default)]
962
    pub prerelease: bool,
963
}
964
b64e2537 Andy McCall ↶ 965
/// Every type of the API, for schema generation.
966
pub fn schemas() -> Vec<(&'static str, schemars::Schema)> {
967
    vec![
968
        ("Repository", schemars::schema_for!(Repository)),
969
        ("Visibility", schemars::schema_for!(Visibility)),
970
        ("Bookmark", schemars::schema_for!(Bookmark)),
971
        ("Tag", schemars::schema_for!(Tag)),
972
        ("ChangeSummary", schemars::schema_for!(ChangeSummary)),
973
        ("Author", schemars::schema_for!(Author)),
974
        ("Signature", schemars::schema_for!(Signature)),
975
        ("Problem", schemars::schema_for!(Problem)),
976
        ("Proposal", schemars::schema_for!(Proposal)),
977
        ("ProposalState", schemars::schema_for!(ProposalState)),
978
        ("ProposalSource", schemars::schema_for!(ProposalSource)),
979
        ("Approval", schemars::schema_for!(Approval)),
980
        ("Issue", schemars::schema_for!(Issue)),
981
        ("Label", schemars::schema_for!(Label)),
982
        ("Milestone", schemars::schema_for!(Milestone)),
5ea4872f Andy McCall ↶ 983
        ("NewMilestone", schemars::schema_for!(NewMilestone)),
984
        ("MilestoneEdit", schemars::schema_for!(MilestoneEdit)),
b64e2537 Andy McCall ↶ 985
        ("Comment", schemars::schema_for!(Comment)),
3f02e5ea Andy McCall ↶ 986
        ("ProposalFile", schemars::schema_for!(ProposalFile)),
42a0ba4b Andy McCall ↶ 987
        ("Notification", schemars::schema_for!(Notification)),
988
        ("Inbox", schemars::schema_for!(Inbox)),
b64e2537 Andy McCall ↶ 989
        ("Atom", schemars::schema_for!(Atom)),
990
        ("Review", schemars::schema_for!(Review)),
991
        ("TreeEntry", schemars::schema_for!(TreeEntry)),
992
        ("BlameLine", schemars::schema_for!(BlameLine)),
993
        ("FileChange", schemars::schema_for!(FileChange)),
994
        ("ChangeDetail", schemars::schema_for!(ChangeDetail)),
995
        ("History", schemars::schema_for!(History)),
996
        ("Conflict", schemars::schema_for!(Conflict)),
997
        ("Push", schemars::schema_for!(Push)),
998
        ("Trust", schemars::schema_for!(Trust)),
999
        ("Policy", schemars::schema_for!(Policy)),
1000
        ("Rule", schemars::schema_for!(Rule)),
1001
        ("Hook", schemars::schema_for!(Hook)),
1002
        ("NewHook", schemars::schema_for!(NewHook)),
1003
        ("Check", schemars::schema_for!(Check)),
1004
        ("CheckStatus", schemars::schema_for!(CheckStatus)),
1005
        ("NewCheck", schemars::schema_for!(NewCheck)),
1006
        ("User", schemars::schema_for!(User)),
1007
        ("Organisation", schemars::schema_for!(Organisation)),
1008
        ("NewRepository", schemars::schema_for!(NewRepository)),
1009
        ("NewIssue", schemars::schema_for!(NewIssue)),
76f262e1 Andy McCall ↶ 1010
        ("IssueEdit", schemars::schema_for!(IssueEdit)),
2291f8cc Andy McCall ↶ 1011
        ("ReleaseEdit", schemars::schema_for!(ReleaseEdit)),
1012
        ("ProposalEdit", schemars::schema_for!(ProposalEdit)),
76f262e1 Andy McCall ↶ 1013
        ("NewLabel", schemars::schema_for!(NewLabel)),
961c10be Andy McCall ↶ 1014
        ("RequiredChecks", schemars::schema_for!(RequiredChecks)),
ef20fdc1 Andy McCall ↶ 1015
        ("Project", schemars::schema_for!(Project)),
1016
        ("ProjectCard", schemars::schema_for!(ProjectCard)),
1017
        ("ProjectColumn", schemars::schema_for!(ProjectColumn)),
1018
        ("Board", schemars::schema_for!(Board)),
1019
        ("NewProject", schemars::schema_for!(NewProject)),
1020
        ("ProjectEdit", schemars::schema_for!(ProjectEdit)),
1021
        ("NewCard", schemars::schema_for!(NewCard)),
1022
        ("CardMove", schemars::schema_for!(CardMove)),
b64e2537 Andy McCall ↶ 1023
        ("NewComment", schemars::schema_for!(NewComment)),
1024
        ("NewProposal", schemars::schema_for!(NewProposal)),
1025
        ("NewReview", schemars::schema_for!(NewReview)),
1026
        ("IssueStateChange", schemars::schema_for!(IssueStateChange)),
1027
        ("WebhookEnvelope", schemars::schema_for!(WebhookEnvelope)),
1028
        ("ProposalEvent", schemars::schema_for!(ProposalEvent)),
3f4b0ea6 Andy McCall ↶ 1029
        ("Release", schemars::schema_for!(Release)),
bf1ab345 Andy McCall ↶ 1030
        ("FlowRun", schemars::schema_for!(FlowRun)),
1031
        ("FlowJob", schemars::schema_for!(FlowJob)),
1032
        ("FlowLogLine", schemars::schema_for!(FlowLogLine)),
1033
        ("AssetBuild", schemars::schema_for!(AssetBuild)),
3f4b0ea6 Andy McCall ↶ 1034
        ("ReleaseAsset", schemars::schema_for!(ReleaseAsset)),
1035
        ("NewRelease", schemars::schema_for!(NewRelease)),
b64e2537 Andy McCall ↶ 1036
    ]
1037
}
b66e70b7 Andy McCall ↶ 1038
1039
/// An OxygenFlow runner (`GET /api/v1/runners`, site administrators).
1040
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1041
pub struct Runner {
1042
    pub id: i64,
1043
    pub name: String,
1044
    /// `online`, `offline`, `draining` or `disabled`.
1045
    pub status: String,
1046
    /// What it serves: empty for the whole site, an owner, or `owner/name`.
1047
    pub serves: String,
1048
    pub arch: String,
1049
    pub os: String,
1050
    pub version: String,
1051
    pub labels: Vec<String>,
1052
    pub max_jobs: i64,
1053
    pub memory_mib: Option<i64>,
1054
    pub cpus: Option<i64>,
1055
    /// The key that signs its receipts (KeyId hex), empty until bound.
1056
    pub key: String,
1057
    /// `registered` or `config` (a hub.toml token).
1058
    pub source: String,
1059
    pub last_seen_ms: Option<i64>,
1060
    /// Jobs it is running now.
1061
    pub running: i64,
1062
}
1063
1064
/// A job a runner ran or is running.
1065
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1066
pub struct RunnerJob {
1067
    pub repo: String,
1068
    pub run: i64,
1069
    pub job: String,
1070
    pub status: String,
1071
    pub started_ms: Option<i64>,
1072
    pub finished_ms: Option<i64>,
1073
}
1074
1075
/// A job in the queue: running ones first, then queued ones in the order
1076
/// runners claim them.
1077
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1078
pub struct QueueItem {
1079
    pub repo: String,
1080
    pub run: i64,
1081
    pub job: String,
1082
    /// `running` or `queued`.
1083
    pub status: String,
1084
    /// The runner holding it, when running.
1085
    pub runner: String,
1086
}
62ceb2ee Andy McCall ↶ 1087
1088
// ------------------------------------------------------------- assistants
1089
1090
/// An AI assistant at a level (hub spec §13.4). The token never leaves the
1091
/// hub: `has_token` says whether one is set.
1092
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1093
pub struct Assistant {
1094
    pub name: String,
1095
    pub endpoint: String,
1096
    pub api: String,
1097
    pub model: String,
1098
    #[serde(default, skip_serializing_if = "String::is_empty")]
1099
    pub headers: String,
1100
    pub enabled: bool,
1101
    pub budget: i64,
1102
    pub has_token: bool,
1103
    /// Where it comes from: empty for the level's own, else `the site` or
1104
    /// `the NAME organisation`.
1105
    #[serde(default, skip_serializing_if = "String::is_empty")]
1106
    pub from: String,
1107
    /// Off because a level above turned a name like it off.
1108
    #[serde(default)]
1109
    pub off_above: bool,
1110
}
1111
1112
/// `POST …/assistants`: add one, or change the one of that name. A
1113
/// `preset` (`anthropic`, `openai`, `gemini`, `deepseek`, `mistral`,
1114
/// `perplexity`, `ollama`) fills what is left out; the model must be one
1115
/// the endpoint lists when it lists any; `token` is write-only.
1116
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1117
pub struct NewAssistant {
1118
    #[serde(default)]
1119
    pub name: String,
1120
    #[serde(default)]
1121
    pub preset: String,
1122
    #[serde(default)]
1123
    pub endpoint: String,
1124
    #[serde(default)]
1125
    pub api: String,
1126
    pub model: String,
1127
    #[serde(default)]
1128
    pub token: String,
1129
    #[serde(default)]
1130
    pub headers: String,
1131
    #[serde(default = "yes")]
1132
    pub enabled: bool,
1133
    #[serde(default)]
1134
    pub budget: Option<i64>,
1135
}
1136
1137
fn yes() -> bool {
1138
    true
1139
}
1140
1141
/// A level's prompt and those it inherits, outermost first.
1142
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1143
pub struct AssistantPrompt {
1144
    pub prompt: String,
1145
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1146
    pub inherited: Vec<(String, String)>,
1147
}
617c2840 Andy McCall ↶ 1148
1149
/// `GET /repos/{o}/{n}/coverage`: a coverage report from a Flow job
1150
/// (oxygenhub#113); `percent` values are of lines, functions and branches,
1151
/// absent when nothing was counted.
1152
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1153
pub struct CoverageReport {
1154
    pub id: i64,
1155
    pub run: i64,
1156
    pub job: String,
1157
    pub bookmark: String,
1158
    /// The run's state, by hash.
1159
    pub state: String,
1160
    /// `lcov` or `cobertura`.
1161
    pub format: String,
1162
    pub lines_found: i64,
1163
    pub lines_hit: i64,
1164
    pub percent: Option<f64>,
1165
    pub functions_found: i64,
1166
    pub functions_hit: i64,
1167
    pub branches_found: i64,
1168
    pub branches_hit: i64,
1169
    pub files: i64,
1170
    /// Files the report named that are not in the run's state.
1171
    pub dropped: i64,
1172
    pub created_ms: i64,
1173
    /// The report on the hub's Coverage tab, absolute.
1174
    pub url: String,
1175
}
1176
1177
/// One file of a coverage report.
1178
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1179
pub struct CoverageFile {
1180
    pub path: String,
1181
    pub lines_found: i64,
1182
    pub lines_hit: i64,
1183
    pub percent: Option<f64>,
1184
    pub functions_found: i64,
1185
    pub functions_hit: i64,
1186
    pub branches_found: i64,
1187
    pub branches_hit: i64,
1188
}
1189
1190
/// `GET /repos/{o}/{n}/coverage/{id}`: a report with its files.
1191
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1192
pub struct CoverageDetail {
1193
    pub report: CoverageReport,
1194
    pub files: Vec<CoverageFile>,
1195
}
1196
1197
/// `GET /repos/{o}/{n}/tests`: a JUnit test report from a Flow job
1198
/// (oxygenhub#114).
1199
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1200
pub struct TestReport {
1201
    pub id: i64,
1202
    pub run: i64,
1203
    pub job: String,
1204
    pub bookmark: String,
1205
    pub state: String,
1206
    pub tests: i64,
1207
    pub passed: i64,
1208
    pub failed: i64,
1209
    pub errors: i64,
1210
    pub skipped: i64,
1211
    /// The cases' times added up.
1212
    pub time_ms: i64,
1213
    pub created_ms: i64,
1214
    pub url: String,
1215
}
1216
1217
/// One test case of a report.
1218
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1219
pub struct TestCase {
1220
    pub suite: String,
1221
    pub classname: String,
1222
    pub name: String,
1223
    /// `passed`, `failed`, `error` or `skipped`.
1224
    pub status: String,
1225
    pub time_ms: i64,
1226
    pub message: String,
1227
    /// A failure's text and output, cut to 16 KiB; empty for a pass.
1228
    pub output: String,
1229
}
1230
1231
/// `GET /repos/{o}/{n}/tests/{id}`: a report with its cases
1232
/// (`?status=failed` for the failed and errored ones).
1233
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1234
pub struct TestReportDetail {
1235
    pub report: TestReport,
1236
    pub cases: Vec<TestCase>,
1237
}