OXYGENHUB

Coverage / crates/hub-api/src/lib.rs 31.0%

49 of 158 lines run, 12 of 25 functions · run #534 on main · run missed

1
//! Types of the OxygenHub JSON API (hub spec §12.1). Everything here is
2
//! `serde` data with no behaviour, so clients in other languages can be
3
//! generated from it and the server can never drift from them.
4
//!
5
//! Shapes reuse `oxy --json`'s where one exists (hashes as lowercase hex,
6
//! times as milliseconds since the epoch), so tools written against the
7
//! command line work against the hub.
8
9
use schemars::JsonSchema;
10
use serde::{Deserialize, Serialize};
11
12
/// A repository as the API lists it.
13
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
14
pub struct Repository {
15
    pub owner: String,
16
    pub name: String,
17
    pub description: String,
18
    pub default_bookmark: String,
19
    pub visibility: Visibility,
20
    /// Milliseconds since the epoch.
21
    pub created_ms: i64,
22
    pub updated_ms: i64,
23
    /// `https://…/{owner}/{name}`, what `oxy clone` takes.
24
    pub clone_url: String,
25
}
26
27
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
28
#[serde(rename_all = "lowercase")]
29
pub enum Visibility {
30
    Public,
31
    Internal,
32
    Private,
33
}
34
35
impl Visibility {
36248×
    pub fn as_str(self) -> &'static str {
37248×
        match self {
38224×
            Visibility::Public => "public",
391×
            Visibility::Internal => "internal",
4023×
            Visibility::Private => "private",
41
        }
42248×
    }
43
441772×
    pub fn parse(s: &str) -> Option<Visibility> {
451772×
        Some(match s {
461772×
            "public" => Visibility::Public,
47159×
            "internal" => Visibility::Internal,
48158×
            "private" => Visibility::Private,
491×
            _ => return None,
50
        })
511772×
    }
52
}
53
54
/// A bookmark: a name for a set of heads (spec §10.1).
55
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
56
pub struct Bookmark {
57
    pub name: String,
58
    pub heads: Vec<String>,
59
    /// Number of changes in the bookmark's state.
60
    pub changes: usize,
61
    pub default: bool,
62
}
63
64
/// A tag: a name for one state, with its attestation when signed.
65
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
66
pub struct Tag {
67
    pub name: String,
68
    pub heads: Vec<String>,
69
    pub message: String,
70
    pub signer: Option<String>,
71
}
72
73
/// One change in a history listing.
74
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
75
pub struct ChangeSummary {
76
    pub hash: String,
77
    pub message: String,
78
    pub author: Author,
79
    pub when_ms: u64,
80
    pub deps: Vec<String>,
81
    pub head: bool,
82
    pub signature: Signature,
83
    /// Signed for the author by a delegate (an agent), when it was.
84
    #[serde(default, skip_serializing_if = "Option::is_none")]
85
    pub via: Option<Via>,
86
}
87
88
/// A delegate that signed a change for its author (Oxygen spec §14.2).
89
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
90
pub struct Via {
91
    pub name: String,
92
    pub key: String,
93
    /// The delegation's scope, `changes` for an agent.
94
    pub scope: String,
95
    pub expires_ms: Option<u64>,
96
    /// The delegation has since been revoked or withdrawn.
97
    pub revoked: bool,
98
}
99
100
/// Who wrote a change: the linked account when the signing key is linked,
101
/// else the key alone.
102
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
103
pub struct Author {
104
    pub name: String,
105
    pub email: String,
106
    pub key: String,
107
    /// The hub account this key is linked to, when any.
108
    pub account: Option<String>,
109
    /// Set when the change is signed by a key no account has linked, and
110
    /// says how its owner links it.
111
    #[serde(default, skip_serializing_if = "Option::is_none")]
112
    pub note: Option<String>,
113
}
114
115
impl Author {
116
    /// What `note` says for a key that no account has linked.
117
    pub const UNLINKED: &'static str =
118
        "signed by a key not linked to any account; its owner links it under Settings → Keys (/settings/keys)";
119
120
    /// The note for an author with this key and account.
12150×
    pub fn note_for(key: &str, account: &Option<String>) -> Option<String> {
12250×
        (!key.is_empty() && account.is_none()).then(|| Self::UNLINKED.to_string())
12350×
    }
124
}
125
126
/// Signature status of a change as `oxy verify` reports it.
127
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
128
#[serde(tag = "status", rename_all = "lowercase")]
129
pub enum Signature {
130
    Unsigned,
131
    Valid { key: String, sealed: bool, revoked: bool },
132
    Invalid { reason: String },
133
}
134
135
/// An RFC 7807 problem response.
136
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
137
pub struct Problem {
138
    pub status: u16,
139
    pub title: String,
140
    pub detail: String,
141
}
142
143
#[cfg(test)]
144
mod tests {
145
    use super::*;
146
147
    #[test]
1481×
    fn visibility_round_trips() {
1493×
        for v in [Visibility::Public, Visibility::Internal, Visibility::Private] {
1503×
            assert_eq!(Visibility::parse(v.as_str()), Some(v));
151
        }
1521×
        assert_eq!(Visibility::parse("secret"), None);
1531×
    }
154
}
155
156
// ---------------------------------------------------------------- proposals
157
158
/// A proposal: a request to add changes to a target bookmark (hub spec §7).
159
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
160
pub struct Proposal {
161
    pub number: i64,
162
    pub title: String,
163
    pub body: String,
164
    pub author: String,
165
    pub state: ProposalState,
166
    pub target: String,
167
    pub source: ProposalSource,
168
    /// The changes the proposal adds, dependency order, newest last.
169
    pub changes: Vec<ChangeSummary>,
170
    /// Heads of the projected state (target plus the changes), when computed.
171
    pub projected_heads: Vec<String>,
172
    pub projected_state: Option<String>,
173
    pub conflicted: bool,
174
    pub approvals: Vec<Approval>,
175
    pub landable: bool,
176
    pub blockers: Vec<String>,
177
    pub created_ms: i64,
178
    pub updated_ms: i64,
179
    /// `https://hub/{owner}/{name}/proposal/{number}`.
180
    pub url: String,
181
    /// Where `oxy` fetches the changes from.
182
    pub repository_url: String,
183
    /// The fork's clone URL when the source is a fork.
184
    pub source_url: Option<String>,
185
    /// Who landed it, how and when, once landed.
186
    #[serde(default)]
187
    pub landed: Option<Landed>,
188
    /// Who set it to land when its checks pass (oxygenhub#261), while set.
189
    #[serde(default)]
190
    pub auto_land: Option<String>,
191
    /// Asked to review and not yet reviewing, in the order asked.
192
    #[serde(default)]
193
    pub requested_reviewers: Vec<String>,
194
    #[serde(default)]
195
    pub labels: Vec<Label>,
196
}
197
198
/// How a proposal was landed.
199
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
200
pub struct Landed {
201
    pub by: String,
202
    /// `web`, or `api (token NAME)`.
203
    pub via: String,
204
    pub when_ms: i64,
205
}
206
207
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
208
#[serde(rename_all = "lowercase")]
209
pub enum ProposalState {
210
    Draft,
211
    Open,
212
    Landed,
213
    Closed,
214
}
215
216
impl ProposalState {
2170×
    pub fn as_str(self) -> &'static str {
2180×
        match self {
2190×
            ProposalState::Draft => "draft",
2200×
            ProposalState::Open => "open",
2210×
            ProposalState::Landed => "landed",
2220×
            ProposalState::Closed => "closed",
223
        }
2240×
    }
225
22640×
    pub fn parse(s: &str) -> Option<ProposalState> {
22740×
        Some(match s {
22840×
            "draft" => ProposalState::Draft,
22938×
            "open" => ProposalState::Open,
23011×
            "landed" => ProposalState::Landed,
2313×
            "closed" => ProposalState::Closed,
2320×
            _ => return None,
233
        })
23440×
    }
235
}
236
237
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
238
#[serde(tag = "kind", rename_all = "lowercase")]
239
pub enum ProposalSource {
240
    /// A bookmark of the same repository.
241
    Bookmark { bookmark: String },
242
    /// A bookmark of a fork.
243
    Fork { owner: String, name: String, bookmark: String },
244
    /// An explicit list of change hashes.
245
    Changes { hashes: Vec<String> },
246
}
247
248
/// A reviewer's approval, counted only when backed by a seal over every
249
/// change of the proposal signed with a key linked to the reviewer.
250
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
251
pub struct Approval {
252
    pub account: String,
253
    pub sealed: bool,
254
    pub key: Option<String>,
255
}
256
257
// ------------------------------------------------------------------ issues
258
259
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
260
pub struct Issue {
261
    pub number: i64,
262
    pub title: String,
263
    pub body: String,
264
    pub author: String,
265
    pub state: String,
266
    pub reason: String,
267
    pub labels: Vec<Label>,
268
    pub assignees: Vec<String>,
269
    pub milestone: Option<String>,
270
    pub comments: i64,
271
    pub locked: bool,
272
    pub pinned: bool,
273
    pub created_ms: i64,
274
    pub updated_ms: i64,
275
    pub closed_ms: Option<i64>,
276
    pub url: String,
277
}
278
279
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
280
pub struct Label {
281
    pub name: String,
282
    pub colour: String,
283
    pub description: String,
284
}
285
286
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
287
pub struct Milestone {
288
    pub title: String,
289
    pub description: String,
290
    pub due_ms: Option<i64>,
291
    pub state: String,
292
    pub open: i64,
293
    pub closed: i64,
294
}
295
296
/// `POST /repos/{o}/{n}/milestones`: create a milestone, or change the
297
/// description and due date of the one with that title (triage).
298
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
299
pub struct NewMilestone {
300
    pub title: String,
301
    #[serde(default)]
302
    pub description: String,
303
    /// `YYYY-MM-DD`, UTC; absent for no due date.
304
    #[serde(default)]
305
    pub due: Option<String>,
306
}
307
308
/// `PATCH /repos/{o}/{n}/milestones/{title}`: only the fields given change
309
/// (triage).
310
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
311
#[serde(deny_unknown_fields)]
312
pub struct MilestoneEdit {
313
    #[serde(default)]
314
    pub title: Option<String>,
315
    #[serde(default)]
316
    pub description: Option<String>,
317
    /// `YYYY-MM-DD`; the empty string clears the due date.
318
    #[serde(default)]
319
    pub due: Option<String>,
320
    /// `open` or `closed`.
321
    #[serde(default)]
322
    pub state: Option<String>,
323
}
324
325
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
326
pub struct Comment {
327
    pub id: i64,
328
    pub author: String,
329
    pub body: String,
330
    pub created_ms: i64,
331
    /// For proposal comments: the file and the atom the comment anchors to.
332
    pub path: Option<String>,
333
    pub anchor: Option<Atom>,
334
    /// Where the anchor sits now: its 1-based line in `path` in the
335
    /// projected state, when the atom is still live there.
336
    #[serde(default)]
337
    pub line: Option<usize>,
338
    pub resolved: bool,
339
}
340
341
/// One entry in the caller's inbox (hub spec §10).
342
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
343
pub struct Notification {
344
    pub id: i64,
345
    pub at_ms: i64,
346
    /// `issue.opened`, `proposal.comment`, `mention`, `review`, …
347
    pub kind: String,
348
    pub title: String,
349
    /// The page on the hub, absolute.
350
    pub url: String,
351
    pub actor: String,
352
    pub read: bool,
353
    /// The repository it is about, `owner/name` (#305).
354
    #[serde(default)]
355
    pub repository: Option<String>,
356
    /// Why the caller is told: `participating` or `watching`.
357
    #[serde(default)]
358
    pub reason: String,
359
    /// The thread it belongs to (its page, without a fragment), absolute:
360
    /// a client groups the inbox by it.
361
    #[serde(default)]
362
    pub thread: String,
363
    /// The kind as the hub's pages label it ("🐛 New Issue"), when it has one.
364
    #[serde(default)]
365
    pub label: Option<String>,
366
}
367
368
/// `GET /notifications`: the unread count and the newest entries, unread first.
369
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
370
pub struct Inbox {
371
    pub unread: i64,
372
    pub items: Vec<Notification>,
373
}
374
375
/// A file a proposal changes, between the target's state and the
376
/// projected state (hub spec §7.2). Fetch either side's bytes from
377
/// `/proposals/{number}/content/{base|head}/{path}`.
378
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
379
pub struct ProposalFile {
380
    pub path: String,
381
    /// For a rename, the path in the target's state.
382
    pub from: Option<String>,
383
    /// `added`, `removed`, `modified`, `renamed`, `mode` or `replaced`.
384
    pub kind: String,
385
    pub added: usize,
386
    pub removed: usize,
387
}
388
389
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
390
pub struct Atom {
391
    pub change: String,
392
    pub index: u32,
393
}
394
395
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
396
pub struct Review {
397
    pub id: i64,
398
    pub author: String,
399
    pub verdict: String,
400
    pub body: String,
401
    pub sealed: bool,
402
    pub created_ms: i64,
403
    /// The AI assistant that answered for `author`, empty for a person's
404
    /// own review (hub spec §13.4).
405
    #[serde(default, skip_serializing_if = "String::is_empty")]
406
    pub via: String,
407
}
408
409
// ------------------------------------------------------------- repository
410
411
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
412
pub struct TreeEntry {
413
    pub name: String,
414
    pub path: String,
415
    pub kind: String,
416
    pub exec: bool,
417
    pub size: Option<u64>,
418
    pub conflicted: bool,
419
}
420
421
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
422
pub struct BlameLine {
423
    pub line: usize,
424
    pub change: String,
425
    pub index: u32,
426
    pub author: String,
427
    pub when_ms: u64,
428
    pub text: String,
429
}
430
431
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
432
pub struct FileChange {
433
    pub path: String,
434
    pub kind: String,
435
    pub from: Option<String>,
436
    pub added: usize,
437
    pub removed: usize,
438
    /// The diff with three lines of context, up to `DIFF_LINES` lines.
439
    #[serde(default)]
440
    pub lines: Vec<DiffLine>,
441
    /// Whether `lines` stops short of the whole diff.
442
    #[serde(default)]
443
    pub truncated: bool,
444
}
445
446
/// Lines of one file's diff the API sends at most.
447
pub const DIFF_LINES: usize = 2000;
448
449
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
450
pub struct DiffLine {
451
    /// `context`, `add`, `del`, or `gap` (lines left out between hunks).
452
    pub kind: String,
453
    #[serde(default, skip_serializing_if = "Option::is_none")]
454
    pub old: Option<u32>,
455
    #[serde(default, skip_serializing_if = "Option::is_none")]
456
    pub new: Option<u32>,
457
    #[serde(default)]
458
    pub text: String,
459
}
460
461
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
462
pub struct ChangeDetail {
463
    pub change: ChangeSummary,
464
    pub body: String,
465
    pub dependents: Vec<String>,
466
    pub in_bookmarks: Vec<String>,
467
    pub in_tags: Vec<String>,
468
    pub files: Vec<FileChange>,
469
}
470
471
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
472
pub struct History {
473
    pub reference: String,
474
    pub heads: Vec<String>,
475
    pub total: usize,
476
    pub offset: usize,
477
    pub changes: Vec<ChangeSummary>,
478
}
479
480
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
481
pub struct Conflict {
482
    pub bookmark: String,
483
    pub path: String,
484
    pub kind: String,
485
    pub contributors: Vec<String>,
486
}
487
488
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
489
pub struct Push {
490
    pub at_ms: i64,
491
    pub pusher: String,
492
    pub reference: String,
493
    pub ok: bool,
494
    pub reason: String,
495
    pub old_state: String,
496
    pub new_state: String,
497
    pub heads: i64,
498
    pub changes: i64,
499
}
500
501
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
502
pub struct Trust {
503
    pub policy: Option<Policy>,
504
    pub signed: usize,
505
    pub sealed: usize,
506
    pub unsigned: usize,
507
    pub invalid: Vec<String>,
508
    pub hub_key: String,
509
}
510
511
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
512
pub struct Policy {
513
    pub serial: u64,
514
    pub expires_ms: u64,
515
    pub roots: Vec<String>,
516
    pub root_threshold: u32,
517
    pub rules: Vec<Rule>,
518
}
519
520
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
521
pub struct Rule {
522
    pub pattern: String,
523
    pub keys: Vec<String>,
524
    pub threshold: u32,
525
    pub require: String,
526
    pub allow_conflicts: bool,
527
}
528
529
// ---------------------------------------------------------- hooks, checks
530
531
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
532
pub struct Hook {
533
    pub id: i64,
534
    pub url: String,
535
    pub events: String,
536
    pub active: bool,
537
    pub created_ms: i64,
538
}
539
540
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
541
pub struct NewHook {
542
    pub url: String,
543
    pub secret: String,
544
    #[serde(default = "star")]
545
    pub events: String,
546
}
547
5480×
fn star() -> String {
5490×
    "*".into()
5500×
}
551
552
/// An OxygenFlow run (hub spec §13.2).
553
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
554
pub struct FlowRun {
555
    /// The run's number within its repository.
556
    pub number: i64,
557
    pub bookmark: String,
558
    /// The state's hash, as checks are keyed.
559
    pub state: String,
560
    /// Its heads, full change hashes.
561
    pub heads: Vec<String>,
562
    /// `queued`, `running`, `passed`, `failed` or `error` (an invalid pipeline).
563
    pub status: String,
564
    /// `push`, `manual` or `rerun:N`.
565
    pub trigger: String,
566
    pub actor: String,
567
    pub pipeline_hash: String,
568
    /// An invalid pipeline's problems.
569
    pub error: String,
570
    pub created_ms: i64,
571
    pub finished_ms: Option<i64>,
572
    pub url: String,
573
    /// For a run waiting for a runner, its first queued job's 1-based
574
    /// place among all queued jobs.
575
    #[serde(default, skip_serializing_if = "Option::is_none")]
576
    pub queue_position: Option<i64>,
577
    /// Filled by the single-run endpoint.
578
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
579
    pub jobs: Vec<FlowJob>,
580
}
581
582
/// A job of a run.
583
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
584
pub struct FlowJob {
585
    pub name: String,
586
    /// `queued`, `running`, `passed`, `failed`, `skipped` or `error`.
587
    pub status: String,
588
    pub depends_on: Vec<String>,
589
    pub runner: String,
590
    pub exit_code: Option<i64>,
591
    pub error: String,
592
    pub started_ms: Option<i64>,
593
    pub finished_ms: Option<i64>,
594
    /// Log lines stored so far.
595
    pub log_lines: i64,
596
    /// Why a queued job no runner can take waits (OxygenFlow spec §11.4);
597
    /// empty when it only waits its turn.
598
    #[serde(default, skip_serializing_if = "String::is_empty")]
599
    pub waiting: String,
600
    /// Why it ran on its runner (oxygenflow#42): "holds the image, idle,
601
    /// speed 100 (class 3)".
602
    #[serde(default, skip_serializing_if = "String::is_empty")]
603
    pub placed: String,
604
    /// Its approval gate (oxygenflow#57): `waiting` while it waits for a
605
    /// person to approve or reject it, `approved` or `rejected` after;
606
    /// empty for a job with no gate.
607
    #[serde(default, skip_serializing_if = "String::is_empty")]
608
    pub approval: String,
609
    /// When it entered the queue (made, or run again), and when a runner
610
    /// claimed it: its wait is `started_ms - queued_ms` (oxygenhub#348).
611
    #[serde(default, skip_serializing_if = "Option::is_none")]
612
    pub queued_ms: Option<i64>,
613
    #[serde(default, skip_serializing_if = "Option::is_none")]
614
    pub ready_ms: Option<i64>,
615
    /// Where its time went, as its runner reported (oxygenflow#35):
616
    /// `image`, `prepare`, `run` and `finish`, in that order.
617
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
618
    pub phases: Vec<FlowPhase>,
619
    /// The most disk and memory it took, as its runner reported, in MiB.
620
    #[serde(default, skip_serializing_if = "Option::is_none")]
621
    pub peak_disk_mib: Option<i64>,
622
    #[serde(default, skip_serializing_if = "Option::is_none")]
623
    pub peak_memory_mib: Option<i64>,
624
}
625
626
/// A phase of a job and its milliseconds.
627
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
628
pub struct FlowPhase {
629
    pub name: String,
630
    pub ms: u64,
631
}
632
633
/// A report: what a Flow job published (OxygenFlow `output { report … }`)
634
/// or an upload, as docs/reports.md describes (oxygenhub#348).
635
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
636
pub struct Report {
637
    /// Its id, as the web page's `?id=` carries it.
638
    pub id: i64,
639
    /// The name the pipeline gave it (`report "frame-timing"`).
640
    pub name: String,
641
    /// `coverage`, `tests`, `performance` or `custom`.
642
    pub kind: String,
643
    pub title: String,
644
    pub summary: String,
645
    pub metrics: Vec<ReportMetric>,
646
    /// Its `[context]` table.
647
    pub context: serde_json::Value,
648
    /// The run and job that published it; none for an upload.
649
    pub run: Option<i64>,
650
    pub job: String,
651
    pub bookmark: String,
652
    /// The state it measured.
653
    pub state: String,
654
    /// How many files it has and their size together.
655
    pub files: i64,
656
    pub bytes: i64,
657
    pub created_ms: i64,
658
    /// When its files expired under retention (docs/reports.md §3.3): its
659
    /// metrics stay, its files are gone.
660
    pub files_expired_ms: Option<i64>,
661
    /// Its page on the hub.
662
    pub url: String,
663
    /// Its files, filled when one report is asked for.
664
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
665
    pub manifest: Vec<ReportFile>,
666
}
667
668
/// A metric of a report.
669
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
670
pub struct ReportMetric {
671
    pub key: String,
672
    pub value: f64,
673
    pub unit: String,
674
    /// `lower`, `higher`, or empty.
675
    pub better: String,
676
    pub fail_above: Option<f64>,
677
    pub fail_below: Option<f64>,
678
}
679
680
/// A file of a report.
681
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
682
pub struct ReportFile {
683
    pub path: String,
684
    pub size: i64,
685
}
686
687
/// A line of a job's log.
688
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
689
pub struct FlowLogLine {
690
    /// Increasing within the job; pass the last one as `after` for more.
691
    pub seq: i64,
692
    /// Milliseconds since the job started.
693
    pub t: i64,
694
    /// `stdout`, `stderr` or `flow` (the runner's own notes).
695
    pub stream: String,
696
    pub text: String,
697
}
698
699
/// A check on a state hash (hub spec §13.1).
700
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
701
pub struct Check {
702
    pub state: String,
703
    pub name: String,
704
    pub status: CheckStatus,
705
    pub summary: String,
706
    pub url: String,
707
    pub reporter: String,
708
    /// The seal attestation's reference when the checker sealed the changes.
709
    pub seal: Option<String>,
710
    pub started_ms: i64,
711
    pub finished_ms: Option<i64>,
712
}
713
714
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
715
#[serde(rename_all = "lowercase")]
716
pub enum CheckStatus {
717
    Queued,
718
    Running,
719
    Passed,
720
    Failed,
721
    Cancelled,
722
    Skipped,
723
}
724
725
impl CheckStatus {
7262×
    pub fn as_str(self) -> &'static str {
7272×
        match self {
7280×
            CheckStatus::Queued => "queued",
7290×
            CheckStatus::Running => "running",
7301×
            CheckStatus::Passed => "passed",
7311×
            CheckStatus::Failed => "failed",
7320×
            CheckStatus::Cancelled => "cancelled",
7330×
            CheckStatus::Skipped => "skipped",
734
        }
7352×
    }
736
737732×
    pub fn parse(s: &str) -> Option<CheckStatus> {
738732×
        Some(match s {
739732×
            "queued" => CheckStatus::Queued,
740346×
            "running" => CheckStatus::Running,
741184×
            "passed" => CheckStatus::Passed,
74273×
            "failed" => CheckStatus::Failed,
74350×
            "cancelled" => CheckStatus::Cancelled,
7448×
            "skipped" => CheckStatus::Skipped,
7450×
            _ => return None,
746
        })
747732×
    }
748
}
749
750
/// What a checker posts.
751
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
752
pub struct NewCheck {
753
    pub state: String,
754
    pub name: String,
755
    pub status: CheckStatus,
756
    #[serde(default)]
757
    pub summary: String,
758
    #[serde(default)]
759
    pub url: String,
760
    /// Hex of a seal attestation reference the checker pushed, if any.
761
    #[serde(default)]
762
    pub seal: Option<String>,
763
}
764
765
// ------------------------------------------------------------- accounts
766
767
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
768
pub struct User {
769
    pub username: String,
770
    pub display_name: String,
771
    pub is_admin: bool,
772
    pub keys: Vec<String>,
773
    pub created_ms: i64,
774
}
775
776
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
777
pub struct Organisation {
778
    pub name: String,
779
    pub display_name: String,
780
    pub description: String,
781
    pub members: Vec<String>,
782
}
783
784
/// `POST /user/runner-token`: a one-time token that registers a runner for
785
/// the caller's own repositories, as a phone does when its owner offers it
786
/// as a runner (oxygenhub-android#8). Spent by `flow runner register` (or
787
/// the app), within 24 hours.
788
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
789
pub struct RunnerToken {
790
    pub token: String,
791
    /// Whose repositories the runner will serve.
792
    pub owner: String,
793
}
794
795
/// `GET /user/proposals`: the caller's proposals to act on, as the web
796
/// dashboard lists them: open ones by others in repositories they belong
797
/// to that they have not reviewed yet, and their own open and draft ones.
798
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
799
pub struct UserProposals {
800
    pub review: Vec<ProposalBrief>,
801
    pub authored: Vec<ProposalBrief>,
802
    /// With `?landable=true` (#311): the open proposals the caller could
803
    /// land now, in repositories they can write to, with no blockers.
804
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
805
    pub landable: Vec<ProposalBrief>,
806
}
807
808
/// `GET /user/sky` (oxygenhub-android#23): Your sky's data, as the web
809
/// dashboard's backdrop reads it (docs/backgrounds.md §5): the caller's
810
/// repositories, newest-updated first, and their events of the last 30
811
/// days, newest first.
812
/// `GET /repos/{owner}/{name}/sky` gives one repository's in the same shape.
813
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
814
pub struct UserSky {
815
    /// The hub's clock (milliseconds), to age the events by.
816
    pub now: i64,
817
    /// `owner/name` of each repository.
818
    pub repos: Vec<String>,
819
    /// `[repo, kind, at_ms, n]`: an index into `repos`; kind 0 a push of
820
    /// `n` changes, 1 a proposal event, 2 an issue event, 3 a release, 4 a
821
    /// Flow run.
822
    pub events: Vec<[i64; 4]>,
823
}
824
825
/// `GET /user/flow/runs` (oxygenhub-android#26): a run of one of the
826
/// caller's repositories, with its jobs, for a monitor across them all.
827
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
828
pub struct UserFlowRun {
829
    /// `owner/name`.
830
    pub repository: String,
831
    #[serde(flatten)]
832
    pub run: FlowRun,
833
}
834
835
/// `GET /user/flow/runs` query: `before` (created before, ms) pages back.
836
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
837
pub struct UserFlowRunsQuery {
838
    #[serde(default)]
839
    pub limit: Option<i64>,
840
    #[serde(default)]
841
    pub before: Option<i64>,
842
}
843
844
/// `GET /user/starter?owner=X` (#347): the assistants a new repository
845
/// under `owner` may ask for its starting files; empty when none is set up
846
/// or the caller cannot create there.
847
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
848
pub struct StarterAssistants {
849
    pub assistants: Vec<StarterAssistant>,
850
}
851
852
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
853
pub struct StarterAssistant {
854
    pub name: String,
855
    pub model: String,
856
    /// `the site` or `the acme organisation`.
857
    pub from: String,
858
}
859
860
/// `POST /repos/{owner}/{name}/starter`: what to make, and which assistant
861
/// (the first available when not given).
862
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
863
pub struct StarterRequest {
864
    pub description: String,
865
    #[serde(default)]
866
    pub assistant: Option<String>,
867
}
868
869
/// Where a repository's starter stands: `running`, `done` (with the
870
/// change and its files), `failed` (with why), or `none`.
871
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
872
pub struct StarterStatus {
873
    pub status: String,
874
    #[serde(default, skip_serializing_if = "String::is_empty")]
875
    pub assistant: String,
876
    #[serde(default, skip_serializing_if = "String::is_empty")]
877
    pub change: String,
878
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
879
    pub files: Vec<String>,
880
    #[serde(default, skip_serializing_if = "String::is_empty")]
881
    pub error: String,
882
}
883
884
/// An issue in a list across repositories: `GET /user/issues` (#359),
885
/// the open issues assigned to the caller, newest-updated first.
886
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
887
pub struct IssueBrief {
888
    /// `owner/name`.
889
    pub repository: String,
890
    pub number: i64,
891
    pub title: String,
892
    pub updated_ms: i64,
893
    /// `https://hub/{owner}/{name}/issue/{number}`.
894
    pub url: String,
895
}
896
897
/// `GET /user/proposals` query.
898
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
899
pub struct UserProposalsQuery {
900
    /// Also list what the caller can land now (slower: each proposal's
901
    /// projected state is worked out).
902
    #[serde(default)]
903
    pub landable: bool,
904
}
905
906
/// A proposal in a list across repositories.
907
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
908
pub struct ProposalBrief {
909
    /// `owner/name`.
910
    pub repository: String,
911
    pub number: i64,
912
    pub title: String,
913
    pub author: String,
914
    pub state: ProposalState,
915
    pub conflicted: bool,
916
    pub updated_ms: i64,
917
    /// `https://hub/{owner}/{name}/proposal/{number}`.
918
    pub url: String,
919
}
920
921
/// `GET /user/orgs` (#302): an organisation the caller belongs to, and
922
/// their role there.
923
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
924
pub struct UserOrg {
925
    pub name: String,
926
    pub display_name: String,
927
    pub role: String,
928
}
929
930
/// Forms accepted by the write endpoints.
931
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
932
pub struct NewRepository {
933
    pub owner: String,
934
    pub name: String,
935
    #[serde(default)]
936
    pub description: String,
937
    #[serde(default = "public")]
938
    pub visibility: Visibility,
939
}
940
9415×
fn public() -> Visibility {
9425×
    Visibility::Public
9435×
}
944
945
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
946
pub struct NewIssue {
947
    pub title: String,
948
    #[serde(default)]
949
    pub body: String,
950
    /// Label names; each must exist. Needs triage.
951
    #[serde(default)]
952
    pub labels: Vec<String>,
953
    /// Usernames. Needs triage.
954
    #[serde(default)]
955
    pub assignees: Vec<String>,
956
    /// A milestone's title. Needs triage.
957
    #[serde(default)]
958
    pub milestone: Option<String>,
959
}
960
961
/// `PATCH /repos/{o}/{n}/issues/{number}`: only the fields given change.
962
/// Title and body: the author or triage. The rest: triage.
963
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
964
#[serde(deny_unknown_fields)]
965
pub struct IssueEdit {
966
    #[serde(default)]
967
    pub title: Option<String>,
968
    #[serde(default)]
969
    pub body: Option<String>,
970
    /// The whole set of labels.
971
    #[serde(default)]
972
    pub labels: Option<Vec<String>>,
973
    /// The whole set of assignees.
974
    #[serde(default)]
975
    pub assignees: Option<Vec<String>>,
976
    /// A milestone's title; the empty string clears it.
977
    #[serde(default)]
978
    pub milestone: Option<String>,
979
}
980
981
/// The checks a proposal needs, passed, to land on the repository's
982
/// default bookmark (hub spec §13.1). `GET` and `PUT
983
/// /repos/{o}/{n}/checks/required`.
984
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
985
pub struct RequiredChecks {
986
    pub names: Vec<String>,
987
}
988
989
/// A project (hub spec §8.2).
990
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
991
pub struct Project {
992
    pub owner: String,
993
    pub number: i64,
994
    pub title: String,
995
    pub description: String,
996
    pub public: bool,
997
    pub closed: bool,
998
    pub updated_ms: i64,
999
    /// The board on the hub, absolute.
1000
    pub url: String,
1001
}
1002
1003
/// A card as the caller may see it.
1004
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1005
pub struct ProjectCard {
1006
    pub id: i64,
1007
    /// `issue`, `proposal` or `note`.
1008
    pub kind: String,
1009
    /// `owner/name#N`; empty for a note.
1010
    pub reference: String,
1011
    /// The issue's or proposal's title, or the note.
1012
    pub title: String,
1013
    /// The issue's or proposal's state; empty for a note.
1014
    pub state: String,
1015
    /// The issue's or proposal's label names (oxygenhub#293).
1016
    #[serde(default)]
1017
    pub labels: Vec<String>,
1018
    /// An issue's assignees' usernames.
1019
    #[serde(default)]
1020
    pub assignees: Vec<String>,
1021
    /// When it was archived (ms), for an archived card (oxygenhub#293).
1022
    #[serde(default, skip_serializing_if = "Option::is_none")]
1023
    pub archived_ms: Option<i64>,
1024
}
1025
1026
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1027
pub struct ProjectColumn {
1028
    pub id: i64,
1029
    pub name: String,
1030
    pub cards: Vec<ProjectCard>,
1031
}
1032
1033
/// `GET /projects/{owner}/{n}`.
1034
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1035
pub struct Board {
1036
    pub project: Project,
1037
    pub columns: Vec<ProjectColumn>,
1038
}
1039
1040
/// `POST /projects/{owner}`.
1041
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1042
pub struct NewProject {
1043
    pub title: String,
1044
    #[serde(default)]
1045
    pub description: String,
1046
    #[serde(default)]
1047
    pub private: bool,
1048
}
1049
1050
/// `PATCH /projects/{owner}/{n}`: only the fields given change.
1051
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1052
#[serde(deny_unknown_fields)]
1053
pub struct ProjectEdit {
1054
    /// Transfer the board to this owner (#125): one the caller may make
1055
    /// boards under. It takes the next number there.
1056
    #[serde(default, skip_serializing_if = "Option::is_none")]
1057
    pub owner: Option<String>,
1058
    #[serde(default)]
1059
    pub title: Option<String>,
1060
    #[serde(default)]
1061
    pub description: Option<String>,
1062
    #[serde(default)]
1063
    pub private: Option<bool>,
1064
    #[serde(default)]
1065
    pub closed: Option<bool>,
1066
}
1067
1068
/// `POST /projects/{owner}/{n}/cards`: a reference (`repo#12`) or a note,
1069
/// into the column named (by id or name; the first column when absent).
1070
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1071
pub struct NewCard {
1072
    #[serde(default)]
1073
    pub column: Option<String>,
1074
    #[serde(default)]
1075
    pub reference: String,
1076
    #[serde(default)]
1077
    pub note: String,
1078
}
1079
1080
/// `PATCH /projects/{owner}/{n}/cards/{id}`: move to a column (id or name).
1081
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1082
pub struct CardMove {
1083
    pub column: String,
1084
}
1085
1086
/// `POST /projects/{owner}/{n}/cards/move` (#289): every card of column
1087
/// `from` to `column` at once, but those `except` names (card ids, or issue
1088
/// and proposal numbers as `12`, `#12`, `name#12` or `owner/name#12`) and,
1089
/// given `state`, only cards whose issue or proposal is in one of them
1090
/// (`closed`, `landed`…). With `dry_run`, nothing moves.
1091
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1092
pub struct CardsMove {
1093
    pub from: String,
1094
    pub column: String,
1095
    #[serde(default)]
1096
    pub except: Vec<String>,
1097
    #[serde(default)]
1098
    pub state: Vec<String>,
1099
    #[serde(default)]
1100
    pub dry_run: bool,
1101
}
1102
1103
/// What a bulk move moved, and what it left in the column.
1104
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1105
pub struct CardsMoved {
1106
    pub moved: Vec<ProjectCard>,
1107
    pub kept: Vec<ProjectCard>,
1108
    pub dry_run: bool,
1109
}
1110
1111
/// `POST /projects/{owner}/{n}/cards/archive` (oxygenhub#293): take the
1112
/// cards of column `from` off the board, kept and restorable, but those
1113
/// `except` names and, given `state`, only cards whose issue or proposal is
1114
/// in one of them; given `older_days`, only cards that joined the column
1115
/// more than that many days ago. With `dry_run`, nothing is archived.
1116
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1117
pub struct CardsArchive {
1118
    pub from: String,
1119
    #[serde(default)]
1120
    pub older_days: Option<i64>,
1121
    #[serde(default)]
1122
    pub except: Vec<String>,
1123
    #[serde(default)]
1124
    pub state: Vec<String>,
1125
    #[serde(default)]
1126
    pub dry_run: bool,
1127
}
1128
1129
/// What an archive took off the board, and what it left in the column.
1130
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1131
pub struct CardsArchived {
1132
    pub archived: Vec<ProjectCard>,
1133
    pub kept: Vec<ProjectCard>,
1134
    pub dry_run: bool,
1135
}
1136
1137
/// `POST /repos/{o}/{n}/labels`: create a label, or change one of that name.
1138
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1139
pub struct NewLabel {
1140
    pub name: String,
1141
    /// `#rrggbb`; a default when absent.
1142
    #[serde(default)]
1143
    pub colour: Option<String>,
1144
    #[serde(default)]
1145
    pub description: String,
1146
}
1147
1148
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1149
pub struct NewComment {
1150
    pub body: String,
1151
    /// For a proposal: anchor the comment to this file's line (1-based) of
1152
    /// the projected state; the hub records the line's atom.
1153
    #[serde(default)]
1154
    pub path: Option<String>,
1155
    #[serde(default)]
1156
    pub line: Option<usize>,
1157
}
1158
1159
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1160
pub struct NewProposal {
1161
    pub title: String,
1162
    #[serde(default)]
1163
    pub body: String,
1164
    pub target: String,
1165
    /// A bookmark here, or `owner/name:bookmark` of a fork.
1166
    pub source: String,
1167
    #[serde(default)]
1168
    pub draft: bool,
1169
}
1170
1171
/// `POST .../proposals/{number}/reviewers`: accounts to ask for a review.
1172
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1173
pub struct ReviewRequest {
1174
    pub reviewers: Vec<String>,
1175
}
1176
1177
/// `POST .../proposals/{number}/review-requests`: ask an AI assistant the
1178
/// repository may use (hub spec §13.4) to review; it answers as a `comment`
1179
/// review via the assistant.
1180
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1181
pub struct AssistantRequest {
1182
    pub assistant: String,
1183
}
1184
1185
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1186
pub struct NewReview {
1187
    pub verdict: String,
1188
    #[serde(default)]
1189
    pub body: String,
1190
}
1191
1192
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1193
pub struct IssueStateChange {
1194
    /// `open` or `closed`.
1195
    pub state: String,
1196
    #[serde(default)]
1197
    pub reason: String,
1198
}
1199
1200
/// A webhook payload's envelope (hub spec §12.2).
1201
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1202
pub struct WebhookEnvelope {
1203
    pub event: String,
1204
    pub delivery: String,
1205
    pub repository: Option<Repository>,
1206
    pub actor: String,
1207
    pub at_ms: i64,
1208
    pub data: serde_json::Value,
1209
}
1210
1211
/// A server-sent event on a proposal's stream.
1212
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1213
pub struct ProposalEvent {
1214
    pub number: i64,
1215
    pub kind: String,
1216
    pub check: Option<Check>,
1217
}
1218
1219
// --------------------------------------------------------------- releases
1220
1221
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1222
pub struct Release {
1223
    pub tag: String,
1224
    pub title: String,
1225
    pub notes: String,
1226
    pub prerelease: bool,
1227
    pub latest: bool,
1228
    pub author: String,
1229
    pub heads: Vec<String>,
1230
    pub signer: Option<String>,
1231
    pub assets: Vec<ReleaseAsset>,
1232
    pub archives: Vec<String>,
1233
    pub created_ms: i64,
1234
    pub url: String,
1235
}
1236
1237
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1238
pub struct ReleaseAsset {
1239
    pub name: String,
1240
    pub size: i64,
1241
    /// BLAKE3 of the content, hex.
1242
    pub hash: String,
1243
    pub content_type: String,
1244
    pub downloads: i64,
1245
    pub url: String,
1246
    /// The OxygenFlow run and job whose artifact has this content, if any.
1247
    #[serde(default, skip_serializing_if = "Option::is_none")]
1248
    pub built_by: Option<AssetBuild>,
1249
}
1250
1251
/// Where a release asset was built (hub spec §9): a job's artifact with the
1252
/// same BLAKE3, and that job's signed receipt when one was kept.
1253
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1254
pub struct AssetBuild {
1255
    pub run: i64,
1256
    pub job: String,
1257
    pub artifact: String,
1258
    pub run_url: String,
1259
    /// The receipt attestation, hex; `None` when the receipt was not signed.
1260
    pub receipt: Option<String>,
1261
    pub receipt_url: Option<String>,
1262
    pub signer: Option<String>,
1263
    /// The asset's SLSA provenance, signed by the hub (oxygenhub#239):
1264
    /// `cosign verify-blob-attestation --key …/.well-known/oxyhub-signing.pem
1265
    /// --type slsaprovenance1 --insecure-ignore-tlog=true --signature PROVENANCE ASSET`. `None` when the
1266
    /// receipt was not signed.
1267
    #[serde(default)]
1268
    pub provenance_url: Option<String>,
1269
}
1270
1271
/// `PATCH /repos/{o}/{n}/proposals/{number}`: what is given changes,
1272
/// the rest stays (oxygenhub#76).
1273
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1274
#[serde(deny_unknown_fields)]
1275
pub struct ProposalEdit {
1276
    #[serde(default, skip_serializing_if = "Option::is_none")]
1277
    pub title: Option<String>,
1278
    #[serde(default, skip_serializing_if = "Option::is_none")]
1279
    pub body: Option<String>,
1280
    /// The whole set of labels, by name (triage); oxygenhub#80.
1281
    #[serde(default, skip_serializing_if = "Option::is_none")]
1282
    pub labels: Option<Vec<String>>,
1283
    /// `closed`, `open` (reopen a closed one, or make a draft ready for
1284
    /// review) or `draft` (turn an open one back into a draft), by its
1285
    /// author or with triage access, as the page's buttons do
1286
    /// (oxygenhub#140, #313).
1287
    #[serde(default, skip_serializing_if = "Option::is_none")]
1288
    pub state: Option<String>,
1289
    /// `false` makes a draft ready for review, `true` turns an open
1290
    /// proposal back into a draft: the same as `state`, in the words a
1291
    /// proposal is created with (#313).
1292
    #[serde(default, skip_serializing_if = "Option::is_none")]
1293
    pub draft: Option<bool>,
1294
}
1295
1296
/// `PATCH /repos/{owner}/{name}/releases/{tag}`: what to change; fields
1297
/// left out stay as they are.
1298
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1299
#[serde(deny_unknown_fields)]
1300
pub struct ReleaseEdit {
1301
    #[serde(default, skip_serializing_if = "Option::is_none")]
1302
    pub title: Option<String>,
1303
    #[serde(default, skip_serializing_if = "Option::is_none")]
1304
    pub notes: Option<String>,
1305
    #[serde(default, skip_serializing_if = "Option::is_none")]
1306
    pub prerelease: Option<bool>,
1307
}
1308
1309
/// A drop (oxygenhub#279): a small snippet of one or more files, its own
1310
/// Oxygen repository, never listed among repositories. `GET /drops` lists
1311
/// yours, `GET /users/{name}/drops` someone's public ones, and
1312
/// `GET /drops/{id}` one with its files' content.
1313
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1314
pub struct Drop {
1315
    /// 24 hex digits, unique on the hub.
1316
    pub id: String,
1317
    pub owner: String,
1318
    pub title: String,
1319
    pub description: String,
1320
    /// `public` (listed on its owner's Drops page) or `secret` (unlisted:
1321
    /// readable by anyone with its address).
1322
    pub visibility: String,
1323
    /// The drop's page.
1324
    pub url: String,
1325
    /// What `oxy clone` takes.
1326
    pub clone_url: String,
1327
    pub created_ms: i64,
1328
    pub updated_ms: i64,
1329
    pub files: Vec<DropFile>,
1330
    /// How many have starred it, and whether the caller has (oxygenhub#349).
1331
    #[serde(default)]
1332
    pub stars: i64,
1333
    #[serde(default)]
1334
    pub starred: bool,
1335
    /// The drop it was forked from, its page, while that drop exists.
1336
    #[serde(default, skip_serializing_if = "Option::is_none")]
1337
    pub forked_from: Option<String>,
1338
    /// Its files without the site around them, for an `<iframe>` (#280).
1339
    #[serde(default)]
1340
    pub embed_url: String,
1341
}
1342
1343
/// A comment on a drop (oxygenhub#349).
1344
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1345
pub struct DropComment {
1346
    /// Its number on the drop.
1347
    pub id: i64,
1348
    pub author: String,
1349
    /// Markdown.
1350
    pub body: String,
1351
    pub created_ms: i64,
1352
}
1353
1354
/// `POST /drops/{id}/comments`.
1355
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1356
pub struct NewDropComment {
1357
    pub body: String,
1358
}
1359
1360
/// `POST /repos/{owner}/{name}/attachments?name=FILE` (oxygenhub#350): a
1361
/// file attached for an issue, comment or proposal to show; the body is the
1362
/// file's bytes.
1363
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1364
pub struct Attachment {
1365
    pub id: i64,
1366
    pub name: String,
1367
    pub size: i64,
1368
    /// Checked from the bytes: an image the page may show, or
1369
    /// `application/octet-stream`.
1370
    pub content_type: String,
1371
    /// An image shown in place; anything else is a download.
1372
    pub inline: bool,
1373
    pub url: String,
1374
    /// What to put in an issue or comment: `![name](url)` for an image,
1375
    /// `[name](url)` otherwise.
1376
    pub markdown: String,
1377
}
1378
1379
/// A drop's stars after `PUT` or `DELETE /drops/{id}/star`.
1380
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1381
pub struct DropStars {
1382
    pub stars: i64,
1383
    pub starred: bool,
1384
}
1385
1386
/// One of a drop's files. Lists carry no content; one drop's view carries
1387
/// the content of each text file up to 512 KiB.
1388
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1389
pub struct DropFile {
1390
    pub name: String,
1391
    pub size: u64,
1392
    #[serde(default, skip_serializing_if = "Option::is_none")]
1393
    pub content: Option<String>,
1394
    /// The file's bytes on the default bookmark.
1395
    pub raw_url: String,
1396
}
1397
1398
/// `POST /drops`: a new drop with at least one file.
1399
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1400
pub struct NewDrop {
1401
    #[serde(default)]
1402
    pub title: String,
1403
    #[serde(default)]
1404
    pub description: String,
1405
    /// Unlisted, readable by anyone with its address.
1406
    #[serde(default)]
1407
    pub secret: bool,
1408
    pub files: Vec<NewDropFile>,
1409
}
1410
1411
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1412
pub struct NewDropFile {
1413
    pub name: String,
1414
    pub content: String,
1415
}
1416
1417
/// `PATCH /drops/{id}`: what to change; what is left out stays.
1418
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1419
#[serde(deny_unknown_fields)]
1420
pub struct DropEdit {
1421
    #[serde(default, skip_serializing_if = "Option::is_none")]
1422
    pub title: Option<String>,
1423
    #[serde(default, skip_serializing_if = "Option::is_none")]
1424
    pub description: Option<String>,
1425
    #[serde(default, skip_serializing_if = "Option::is_none")]
1426
    pub secret: Option<bool>,
1427
    /// Files to write, or to remove (`content` null); others are kept.
1428
    #[serde(default)]
1429
    pub files: Vec<DropFileEdit>,
1430
    /// The change's message (default "Edit TITLE").
1431
    #[serde(default, skip_serializing_if = "Option::is_none")]
1432
    pub message: Option<String>,
1433
}
1434
1435
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1436
#[serde(deny_unknown_fields)]
1437
pub struct DropFileEdit {
1438
    pub name: String,
1439
    #[serde(default)]
1440
    pub content: Option<String>,
1441
}
1442
1443
/// `POST …/tags` (#295): tag the state of `target` (a bookmark, tag or
1444
/// change; the default bookmark when absent).
1445
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1446
pub struct NewTag {
1447
    pub name: String,
1448
    #[serde(default)]
1449
    pub target: Option<String>,
1450
    #[serde(default)]
1451
    pub message: Option<String>,
1452
}
1453
1454
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1455
pub struct NewRelease {
1456
    pub tag: String,
1457
    pub title: String,
1458
    #[serde(default)]
1459
    pub notes: Option<String>,
1460
    #[serde(default)]
1461
    pub prerelease: bool,
1462
}
1463
1464
/// `GET /repos/{o}/{n}/diffusion` (oxygenhub#153): what a repository
1465
/// takes from (the subrepos it pins) and what it diffuses to (the
1466
/// repositories that pin it), each as the Diffusion pages show it.
1467
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1468
pub struct Diffusion {
1469
    pub takes_from: Vec<DiffusionPin>,
1470
    pub diffuses_to: Vec<DiffusionPin>,
1471
}
1472
1473
/// One pin of an upstream by a consumer, both named `owner/name`.
1474
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1475
pub struct DiffusionPin {
1476
    pub upstream: String,
1477
    pub consumer: String,
1478
    /// Where the consumer pins it.
1479
    pub path: String,
1480
    /// The consumer's bookmark its bumps land on.
1481
    pub bookmark: String,
1482
    /// Upstream changes the pin lacks; absent when the hub cannot tell.
1483
    #[serde(default)]
1484
    pub behind: Option<u64>,
1485
    /// `off`, `green` or `any`.
1486
    pub follow: String,
1487
    /// The open bump proposal's number, on the consumer.
1488
    #[serde(default)]
1489
    pub bump: Option<i64>,
1490
    /// The newest run of the bump: number and status.
1491
    #[serde(default)]
1492
    pub run: Option<i64>,
1493
    #[serde(default)]
1494
    pub run_status: Option<String>,
1495
    /// The pill: the upstream's half, then the consumer's.
1496
    pub upstream_state: DiffusionHalf,
1497
    pub consumer_state: DiffusionHalf,
1498
}
1499
1500
/// One half of the Diffusion pill.
1501
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1502
pub struct DiffusionHalf {
1503
    /// `green`, `amber`, `red`, `grey` or `off`.
1504
    pub tone: String,
1505
    /// What the pill says: `checked`, `untested`, `passes`, `up to date`…
1506
    pub word: String,
1507
    /// The sentence behind it.
1508
    pub title: String,
1509
}
1510
1511
/// Every type of the API, for schema generation.
15120×
pub fn schemas() -> Vec<(&'static str, schemars::Schema)> {
15130×
    vec![
15140×
        ("Repository", schemars::schema_for!(Repository)),
15150×
        ("Diffusion", schemars::schema_for!(Diffusion)),
15160×
        ("DiffusionPin", schemars::schema_for!(DiffusionPin)),
15170×
        ("DiffusionHalf", schemars::schema_for!(DiffusionHalf)),
15180×
        ("Visibility", schemars::schema_for!(Visibility)),
15190×
        ("Bookmark", schemars::schema_for!(Bookmark)),
15200×
        ("Tag", schemars::schema_for!(Tag)),
15210×
        ("ChangeSummary", schemars::schema_for!(ChangeSummary)),
15220×
        ("Author", schemars::schema_for!(Author)),
15230×
        ("Signature", schemars::schema_for!(Signature)),
15240×
        ("Problem", schemars::schema_for!(Problem)),
15250×
        ("Proposal", schemars::schema_for!(Proposal)),
15260×
        ("ProposalState", schemars::schema_for!(ProposalState)),
15270×
        ("ProposalSource", schemars::schema_for!(ProposalSource)),
15280×
        ("Approval", schemars::schema_for!(Approval)),
15290×
        ("Issue", schemars::schema_for!(Issue)),
15300×
        ("Label", schemars::schema_for!(Label)),
15310×
        ("Milestone", schemars::schema_for!(Milestone)),
15320×
        ("NewMilestone", schemars::schema_for!(NewMilestone)),
15330×
        ("MilestoneEdit", schemars::schema_for!(MilestoneEdit)),
15340×
        ("Comment", schemars::schema_for!(Comment)),
15350×
        ("ProposalFile", schemars::schema_for!(ProposalFile)),
15360×
        ("Notification", schemars::schema_for!(Notification)),
15370×
        ("Inbox", schemars::schema_for!(Inbox)),
15380×
        ("Atom", schemars::schema_for!(Atom)),
15390×
        ("Review", schemars::schema_for!(Review)),
15400×
        ("TreeEntry", schemars::schema_for!(TreeEntry)),
15410×
        ("BlameLine", schemars::schema_for!(BlameLine)),
15420×
        ("FileChange", schemars::schema_for!(FileChange)),
15430×
        ("ChangeDetail", schemars::schema_for!(ChangeDetail)),
15440×
        ("History", schemars::schema_for!(History)),
15450×
        ("Conflict", schemars::schema_for!(Conflict)),
15460×
        ("Push", schemars::schema_for!(Push)),
15470×
        ("Trust", schemars::schema_for!(Trust)),
15480×
        ("Policy", schemars::schema_for!(Policy)),
15490×
        ("Rule", schemars::schema_for!(Rule)),
15500×
        ("Hook", schemars::schema_for!(Hook)),
15510×
        ("NewHook", schemars::schema_for!(NewHook)),
15520×
        ("Check", schemars::schema_for!(Check)),
15530×
        ("CheckStatus", schemars::schema_for!(CheckStatus)),
15540×
        ("NewCheck", schemars::schema_for!(NewCheck)),
15550×
        ("User", schemars::schema_for!(User)),
15560×
        ("Organisation", schemars::schema_for!(Organisation)),
15570×
        ("NewRepository", schemars::schema_for!(NewRepository)),
15580×
        ("NewIssue", schemars::schema_for!(NewIssue)),
15590×
        ("IssueEdit", schemars::schema_for!(IssueEdit)),
15600×
        ("ReleaseEdit", schemars::schema_for!(ReleaseEdit)),
15610×
        ("ProposalEdit", schemars::schema_for!(ProposalEdit)),
15620×
        ("NewLabel", schemars::schema_for!(NewLabel)),
15630×
        ("RequiredChecks", schemars::schema_for!(RequiredChecks)),
15640×
        ("Project", schemars::schema_for!(Project)),
15650×
        ("ProjectCard", schemars::schema_for!(ProjectCard)),
15660×
        ("ProjectColumn", schemars::schema_for!(ProjectColumn)),
15670×
        ("Board", schemars::schema_for!(Board)),
15680×
        ("NewProject", schemars::schema_for!(NewProject)),
15690×
        ("ProjectEdit", schemars::schema_for!(ProjectEdit)),
15700×
        ("NewCard", schemars::schema_for!(NewCard)),
15710×
        ("CardMove", schemars::schema_for!(CardMove)),
15720×
        ("NewComment", schemars::schema_for!(NewComment)),
15730×
        ("NewProposal", schemars::schema_for!(NewProposal)),
15740×
        ("NewReview", schemars::schema_for!(NewReview)),
15750×
        ("IssueStateChange", schemars::schema_for!(IssueStateChange)),
15760×
        ("WebhookEnvelope", schemars::schema_for!(WebhookEnvelope)),
15770×
        ("ProposalEvent", schemars::schema_for!(ProposalEvent)),
15780×
        ("Release", schemars::schema_for!(Release)),
15790×
        ("FlowRun", schemars::schema_for!(FlowRun)),
15800×
        ("FlowJob", schemars::schema_for!(FlowJob)),
15810×
        ("FlowLogLine", schemars::schema_for!(FlowLogLine)),
15820×
        ("FlowPhase", schemars::schema_for!(FlowPhase)),
15830×
        ("Report", schemars::schema_for!(Report)),
15840×
        ("ReportMetric", schemars::schema_for!(ReportMetric)),
15850×
        ("ReportFile", schemars::schema_for!(ReportFile)),
15860×
        ("AssetBuild", schemars::schema_for!(AssetBuild)),
15870×
        ("ReleaseAsset", schemars::schema_for!(ReleaseAsset)),
15880×
        ("NewRelease", schemars::schema_for!(NewRelease)),
15890×
        ("Drop", schemars::schema_for!(Drop)),
15900×
        ("DropComment", schemars::schema_for!(DropComment)),
15910×
        ("NewDropComment", schemars::schema_for!(NewDropComment)),
15920×
        ("DropStars", schemars::schema_for!(DropStars)),
15930×
        ("Attachment", schemars::schema_for!(Attachment)),
15940×
        ("NewDrop", schemars::schema_for!(NewDrop)),
15950×
        ("DropEdit", schemars::schema_for!(DropEdit)),
15960×
        ("UserProposals", schemars::schema_for!(UserProposals)),
15970×
        ("ProposalBrief", schemars::schema_for!(ProposalBrief)),
15980×
        ("IssueBrief", schemars::schema_for!(IssueBrief)),
15990×
        ("StarterAssistants", schemars::schema_for!(StarterAssistants)),
16000×
        ("StarterStatus", schemars::schema_for!(StarterStatus)),
16010×
        ("StarterRequest", schemars::schema_for!(StarterRequest)),
16020×
        ("TestReport", schemars::schema_for!(TestReport)),
16030×
        ("TestReportDetail", schemars::schema_for!(TestReportDetail)),
1604
    ]
16050×
}
1606
1607
/// An OxygenFlow runner (`GET /api/v1/runners`, site administrators).
1608
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1609
pub struct Runner {
1610
    pub id: i64,
1611
    pub name: String,
1612
    /// `online`, `offline`, `draining` or `disabled`.
1613
    pub status: String,
1614
    /// What it serves: empty for the whole site, an owner, or `owner/name`.
1615
    pub serves: String,
1616
    pub arch: String,
1617
    pub os: String,
1618
    pub version: String,
1619
    pub labels: Vec<String>,
1620
    pub max_jobs: i64,
1621
    pub memory_mib: Option<i64>,
1622
    pub cpus: Option<i64>,
1623
    /// The key that signs its receipts (KeyId hex), empty until bound.
1624
    pub key: String,
1625
    /// `registered` or `config` (a hub.toml token).
1626
    pub source: String,
1627
    pub last_seen_ms: Option<i64>,
1628
    /// Jobs it is running now.
1629
    pub running: i64,
1630
    /// What it measured at its last claim (oxygenflow#40): free disk in
1631
    /// MiB, the 1-minute load ×100, its speed score (100 on the reference
1632
    /// machine) and class 1–5, its kernel.
1633
    #[serde(default, skip_serializing_if = "Option::is_none")]
1634
    pub free_disk_mib: Option<i64>,
1635
    #[serde(default, skip_serializing_if = "Option::is_none")]
1636
    pub load_x100: Option<i64>,
1637
    #[serde(default, skip_serializing_if = "Option::is_none")]
1638
    pub speed: Option<i64>,
1639
    #[serde(default, skip_serializing_if = "Option::is_none")]
1640
    pub speed_class: Option<i64>,
1641
    #[serde(default, skip_serializing_if = "String::is_empty")]
1642
    pub kernel: String,
1643
}
1644
1645
/// A job a runner ran or is running.
1646
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1647
pub struct RunnerJob {
1648
    pub repo: String,
1649
    pub run: i64,
1650
    pub job: String,
1651
    pub status: String,
1652
    pub started_ms: Option<i64>,
1653
    pub finished_ms: Option<i64>,
1654
}
1655
1656
/// A job in the queue: running ones first, then queued ones in the order
1657
/// runners claim them.
1658
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1659
pub struct QueueItem {
1660
    pub repo: String,
1661
    pub run: i64,
1662
    pub job: String,
1663
    /// `running` or `queued`.
1664
    pub status: String,
1665
    /// The runner holding it, when running.
1666
    pub runner: String,
1667
}
1668
1669
// ------------------------------------------------------------- assistants
1670
1671
/// An AI assistant at a level (hub spec §13.4). The token never leaves the
1672
/// hub: `has_token` says whether one is set.
1673
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1674
pub struct Assistant {
1675
    pub name: String,
1676
    pub endpoint: String,
1677
    pub api: String,
1678
    pub model: String,
1679
    #[serde(default, skip_serializing_if = "String::is_empty")]
1680
    pub headers: String,
1681
    pub enabled: bool,
1682
    pub budget: i64,
1683
    pub has_token: bool,
1684
    /// Where it comes from: empty for the level's own, else `the site` or
1685
    /// `the NAME organisation`.
1686
    #[serde(default, skip_serializing_if = "String::is_empty")]
1687
    pub from: String,
1688
    /// Off because a level above turned a name like it off.
1689
    #[serde(default)]
1690
    pub off_above: bool,
1691
}
1692
1693
/// `POST …/assistants`: add one, or change the one of that name. A
1694
/// `preset` (`anthropic`, `openai`, `gemini`, `deepseek`, `mistral`,
1695
/// `perplexity`, `ollama`) fills what is left out; the model must be one
1696
/// the endpoint lists when it lists any; `token` is write-only.
1697
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1698
pub struct NewAssistant {
1699
    #[serde(default)]
1700
    pub name: String,
1701
    #[serde(default)]
1702
    pub preset: String,
1703
    #[serde(default)]
1704
    pub endpoint: String,
1705
    #[serde(default)]
1706
    pub api: String,
1707
    pub model: String,
1708
    #[serde(default)]
1709
    pub token: String,
1710
    #[serde(default)]
1711
    pub headers: String,
1712
    #[serde(default = "yes")]
1713
    pub enabled: bool,
1714
    #[serde(default)]
1715
    pub budget: Option<i64>,
1716
}
1717
17185×
fn yes() -> bool {
17195×
    true
17205×
}
1721
1722
/// A level's prompt and those it inherits, outermost first.
1723
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1724
pub struct AssistantPrompt {
1725
    pub prompt: String,
1726
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1727
    pub inherited: Vec<(String, String)>,
1728
}
1729
1730
/// `GET /repos/{o}/{n}/coverage`: a coverage report from a Flow job
1731
/// (oxygenhub#113); `percent` values are of lines, functions and branches,
1732
/// absent when nothing was counted.
1733
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1734
pub struct CoverageReport {
1735
    pub id: i64,
1736
    pub run: i64,
1737
    pub job: String,
1738
    pub bookmark: String,
1739
    /// The run's state, by hash.
1740
    pub state: String,
1741
    /// `lcov` or `cobertura`.
1742
    pub format: String,
1743
    pub lines_found: i64,
1744
    pub lines_hit: i64,
1745
    pub percent: Option<f64>,
1746
    pub functions_found: i64,
1747
    pub functions_hit: i64,
1748
    pub branches_found: i64,
1749
    pub branches_hit: i64,
1750
    pub files: i64,
1751
    /// Files the report named that are not in the run's state.
1752
    pub dropped: i64,
1753
    pub created_ms: i64,
1754
    /// The report on the hub's Coverage tab, absolute.
1755
    pub url: String,
1756
    /// Who uploaded it from a workstation (#136), when no Flow job made it;
1757
    /// `run` and `job` are then 0 and "upload".
1758
    #[serde(default, skip_serializing_if = "Option::is_none")]
1759
    pub uploaded_by: Option<String>,
1760
}
1761
1762
/// One file of a coverage report.
1763
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1764
pub struct CoverageFile {
1765
    pub path: String,
1766
    pub lines_found: i64,
1767
    pub lines_hit: i64,
1768
    pub percent: Option<f64>,
1769
    pub functions_found: i64,
1770
    pub functions_hit: i64,
1771
    pub branches_found: i64,
1772
    pub branches_hit: i64,
1773
}
1774
1775
/// `GET /repos/{o}/{n}/coverage/{id}`: a report with its files.
1776
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1777
pub struct CoverageDetail {
1778
    pub report: CoverageReport,
1779
    pub files: Vec<CoverageFile>,
1780
}
1781
1782
/// `GET /repos/{o}/{n}/tests`: a JUnit test report from a Flow job
1783
/// (oxygenhub#114).
1784
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1785
pub struct TestReport {
1786
    pub id: i64,
1787
    pub run: i64,
1788
    pub job: String,
1789
    pub bookmark: String,
1790
    pub state: String,
1791
    pub tests: i64,
1792
    pub passed: i64,
1793
    pub failed: i64,
1794
    pub errors: i64,
1795
    pub skipped: i64,
1796
    /// The cases' times added up.
1797
    pub time_ms: i64,
1798
    pub created_ms: i64,
1799
    pub url: String,
1800
}
1801
1802
/// One test case of a report.
1803
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1804
pub struct TestCase {
1805
    pub suite: String,
1806
    pub classname: String,
1807
    pub name: String,
1808
    /// `passed`, `failed`, `error` or `skipped`.
1809
    pub status: String,
1810
    pub time_ms: i64,
1811
    pub message: String,
1812
    /// A failure's text and output, cut to 16 KiB; empty for a pass.
1813
    pub output: String,
1814
}
1815
1816
/// `GET /repos/{o}/{n}/tests/{id}`: a report with its cases
1817
/// (`?status=failed` for the failed and errored ones).
1818
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1819
pub struct TestReportDetail {
1820
    pub report: TestReport,
1821
    pub cases: Vec<TestCase>,
1822
}
1823
1824
/// `GET /api/v1/admin/runner-updates` (oxygenhub#322): where runner builds
1825
/// come from, every level's settings, the test groups, each runner's policy
1826
/// and what it is offered, and the builds held back (#326). Site
1827
/// administrators only.
1828
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1829
pub struct RunnerUpdates {
1830
    /// The repository whose releases carry runner builds (`owner/name`).
1831
    pub repo: String,
1832
    pub settings: Vec<UpdateSetting>,
1833
    pub groups: Vec<RunnerGroup>,
1834
    pub runners: Vec<RunnerUpdate>,
1835
    pub holds: Vec<HeldBuild>,
1836
}
1837
1838
/// One level's update settings; `None` inherits from the next level out.
1839
/// `PUT /api/v1/admin/runner-updates/settings` takes one.
1840
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1841
pub struct UpdateSetting {
1842
    /// `site`, `owner`, `group` or `runner`.
1843
    pub scope: String,
1844
    /// Empty for the site; the owner's name, the group's id, the runner's id.
1845
    #[serde(default)]
1846
    pub key: String,
1847
    #[serde(default)]
1848
    pub updates: Option<bool>,
1849
    /// `stable`, `canary` or a version.
1850
    #[serde(default)]
1851
    pub channel: Option<String>,
1852
    /// Hours (UTC) in which updates may start, `02-05`.
1853
    #[serde(default)]
1854
    pub window: Option<String>,
1855
    #[serde(default)]
1856
    pub dry_run: Option<bool>,
1857
}
1858
1859
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1860
pub struct RunnerGroup {
1861
    pub id: i64,
1862
    /// Empty for a group of the site's runners.
1863
    pub owner: String,
1864
    pub name: String,
1865
    /// A share of the runners in reach; `None`: chosen ones.
1866
    pub percent: Option<i64>,
1867
    /// Its runners now, by name.
1868
    pub members: Vec<String>,
1869
    /// The wave it takes a version in (oxygenflow#84); `None`: after every wave.
1870
    #[serde(default, skip_serializing_if = "Option::is_none")]
1871
    pub wave: Option<i64>,
1872
}
1873
1874
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1875
pub struct RunnerUpdate {
1876
    pub id: i64,
1877
    pub name: String,
1878
    /// The owner it serves; empty for the site's.
1879
    pub owner: String,
1880
    pub version: String,
1881
    pub groups: Vec<String>,
1882
    pub updates: bool,
1883
    pub channel: String,
1884
    #[serde(default)]
1885
    pub window: Option<String>,
1886
    pub dry_run: bool,
1887
    /// Where each setting came from, in the order updates, channel, window, dry run.
1888
    pub from: Vec<String>,
1889
    /// What the hub would offer it now, in words.
1890
    pub now: String,
1891
    /// What it last said about its update.
1892
    pub said: String,
1893
}
1894
1895
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1896
pub struct HeldBuild {
1897
    pub version: String,
1898
    pub runner: String,
1899
    pub why: String,
1900
    pub at_ms: i64,
1901
}