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