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