OXYGENHUB
# 439ecd8708a1 oxygenhub / crates / hub-api / src / lib.rs
48.1 KiB · Rust · last changed Board cards can be archived, by hand or by age (refs #293) 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
    /// The repository it is about, `owner/name` (#305).
353
    #[serde(default)]
354
    pub repository: Option<String>,
355
    /// Why the caller is told: `participating` or `watching`.
356
    #[serde(default)]
357
    pub reason: String,
358
    /// The thread it belongs to (its page, without a fragment), absolute:
359
    /// a client groups the inbox by it.
360
    #[serde(default)]
361
    pub thread: String,
362
    /// The kind as the hub's pages label it ("🐛 New Issue"), when it has one.
363
    #[serde(default)]
364
    pub label: Option<String>,
365
}
366
367
/// `GET /notifications`: the unread count and the newest entries, unread first.
368
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
369
pub struct Inbox {
370
    pub unread: i64,
371
    pub items: Vec<Notification>,
372
}
373
374
/// A file a proposal changes, between the target's state and the
375
/// projected state (hub spec §7.2). Fetch either side's bytes from
376
/// `/proposals/{number}/content/{base|head}/{path}`.
377
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
378
pub struct ProposalFile {
379
    pub path: String,
380
    /// For a rename, the path in the target's state.
381
    pub from: Option<String>,
382
    /// `added`, `removed`, `modified`, `renamed`, `mode` or `replaced`.
383
    pub kind: String,
384
    pub added: usize,
385
    pub removed: usize,
386
}
387
388
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
389
pub struct Atom {
390
    pub change: String,
391
    pub index: u32,
392
}
393
394
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
395
pub struct Review {
396
    pub id: i64,
397
    pub author: String,
398
    pub verdict: String,
399
    pub body: String,
400
    pub sealed: bool,
401
    pub created_ms: i64,
402
    /// The AI assistant that answered for `author`, empty for a person's
403
    /// own review (hub spec §13.4).
404
    #[serde(default, skip_serializing_if = "String::is_empty")]
405
    pub via: String,
406
}
407
408
// ------------------------------------------------------------- repository
409
410
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
411
pub struct TreeEntry {
412
    pub name: String,
413
    pub path: String,
414
    pub kind: String,
415
    pub exec: bool,
416
    pub size: Option<u64>,
417
    pub conflicted: bool,
418
}
419
420
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
421
pub struct BlameLine {
422
    pub line: usize,
423
    pub change: String,
424
    pub index: u32,
425
    pub author: String,
426
    pub when_ms: u64,
427
    pub text: String,
428
}
429
430
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
431
pub struct FileChange {
432
    pub path: String,
433
    pub kind: String,
434
    pub from: Option<String>,
435
    pub added: usize,
436
    pub removed: usize,
437
}
438
439
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
440
pub struct ChangeDetail {
441
    pub change: ChangeSummary,
442
    pub body: String,
443
    pub dependents: Vec<String>,
444
    pub in_bookmarks: Vec<String>,
445
    pub in_tags: Vec<String>,
446
    pub files: Vec<FileChange>,
447
}
448
449
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
450
pub struct History {
451
    pub reference: String,
452
    pub heads: Vec<String>,
453
    pub total: usize,
454
    pub offset: usize,
455
    pub changes: Vec<ChangeSummary>,
456
}
457
458
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
459
pub struct Conflict {
460
    pub bookmark: String,
461
    pub path: String,
462
    pub kind: String,
463
    pub contributors: Vec<String>,
464
}
465
466
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
467
pub struct Push {
468
    pub at_ms: i64,
469
    pub pusher: String,
470
    pub reference: String,
471
    pub ok: bool,
472
    pub reason: String,
473
    pub old_state: String,
474
    pub new_state: String,
475
    pub heads: i64,
476
    pub changes: i64,
477
}
478
479
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
480
pub struct Trust {
481
    pub policy: Option<Policy>,
482
    pub signed: usize,
483
    pub sealed: usize,
484
    pub unsigned: usize,
485
    pub invalid: Vec<String>,
486
    pub hub_key: String,
487
}
488
489
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
490
pub struct Policy {
491
    pub serial: u64,
492
    pub expires_ms: u64,
493
    pub roots: Vec<String>,
494
    pub root_threshold: u32,
495
    pub rules: Vec<Rule>,
496
}
497
498
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
499
pub struct Rule {
500
    pub pattern: String,
501
    pub keys: Vec<String>,
502
    pub threshold: u32,
503
    pub require: String,
504
    pub allow_conflicts: bool,
505
}
506
507
// ---------------------------------------------------------- hooks, checks
508
509
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
510
pub struct Hook {
511
    pub id: i64,
512
    pub url: String,
513
    pub events: String,
514
    pub active: bool,
515
    pub created_ms: i64,
516
}
517
518
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
519
pub struct NewHook {
520
    pub url: String,
521
    pub secret: String,
522
    #[serde(default = "star")]
523
    pub events: String,
524
}
525
526
fn star() -> String {
527
    "*".into()
528
}
529
530
/// An OxygenFlow run (hub spec §13.2).
531
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
532
pub struct FlowRun {
533
    /// The run's number within its repository.
534
    pub number: i64,
535
    pub bookmark: String,
536
    /// The state's hash, as checks are keyed.
537
    pub state: String,
538
    /// Its heads, full change hashes.
539
    pub heads: Vec<String>,
540
    /// `queued`, `running`, `passed`, `failed` or `error` (an invalid pipeline).
541
    pub status: String,
542
    /// `push`, `manual` or `rerun:N`.
543
    pub trigger: String,
544
    pub actor: String,
545
    pub pipeline_hash: String,
546
    /// An invalid pipeline's problems.
547
    pub error: String,
548
    pub created_ms: i64,
549
    pub finished_ms: Option<i64>,
550
    pub url: String,
551
    /// For a run waiting for a runner, its first queued job's 1-based
552
    /// place among all queued jobs.
553
    #[serde(default, skip_serializing_if = "Option::is_none")]
554
    pub queue_position: Option<i64>,
555
    /// Filled by the single-run endpoint.
556
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
557
    pub jobs: Vec<FlowJob>,
558
}
559
560
/// A job of a run.
561
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
562
pub struct FlowJob {
563
    pub name: String,
564
    /// `queued`, `running`, `passed`, `failed`, `skipped` or `error`.
565
    pub status: String,
566
    pub depends_on: Vec<String>,
567
    pub runner: String,
568
    pub exit_code: Option<i64>,
569
    pub error: String,
570
    pub started_ms: Option<i64>,
571
    pub finished_ms: Option<i64>,
572
    /// Log lines stored so far.
573
    pub log_lines: i64,
574
    /// Why a queued job no runner can take waits (OxygenFlow spec §11.4);
575
    /// empty when it only waits its turn.
576
    #[serde(default, skip_serializing_if = "String::is_empty")]
577
    pub waiting: String,
578
    /// Why it ran on its runner (oxygenflow#42): "holds the image, idle,
579
    /// speed 100 (class 3)".
580
    #[serde(default, skip_serializing_if = "String::is_empty")]
581
    pub placed: String,
582
}
583
584
/// A line of a job's log.
585
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
586
pub struct FlowLogLine {
587
    /// Increasing within the job; pass the last one as `after` for more.
588
    pub seq: i64,
589
    /// Milliseconds since the job started.
590
    pub t: i64,
591
    /// `stdout`, `stderr` or `flow` (the runner's own notes).
592
    pub stream: String,
593
    pub text: String,
594
}
595
596
/// A check on a state hash (hub spec §13.1).
597
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
598
pub struct Check {
599
    pub state: String,
600
    pub name: String,
601
    pub status: CheckStatus,
602
    pub summary: String,
603
    pub url: String,
604
    pub reporter: String,
605
    /// The seal attestation's reference when the checker sealed the changes.
606
    pub seal: Option<String>,
607
    pub started_ms: i64,
608
    pub finished_ms: Option<i64>,
609
}
610
611
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
612
#[serde(rename_all = "lowercase")]
613
pub enum CheckStatus {
614
    Queued,
615
    Running,
616
    Passed,
617
    Failed,
618
    Cancelled,
619
    Skipped,
620
}
621
622
impl CheckStatus {
623
    pub fn as_str(self) -> &'static str {
624
        match self {
625
            CheckStatus::Queued => "queued",
626
            CheckStatus::Running => "running",
627
            CheckStatus::Passed => "passed",
628
            CheckStatus::Failed => "failed",
629
            CheckStatus::Cancelled => "cancelled",
630
            CheckStatus::Skipped => "skipped",
631
        }
632
    }
633
634
    pub fn parse(s: &str) -> Option<CheckStatus> {
635
        Some(match s {
636
            "queued" => CheckStatus::Queued,
637
            "running" => CheckStatus::Running,
638
            "passed" => CheckStatus::Passed,
639
            "failed" => CheckStatus::Failed,
640
            "cancelled" => CheckStatus::Cancelled,
641
            "skipped" => CheckStatus::Skipped,
642
            _ => return None,
643
        })
644
    }
645
}
646
647
/// What a checker posts.
648
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
649
pub struct NewCheck {
650
    pub state: String,
651
    pub name: String,
652
    pub status: CheckStatus,
653
    #[serde(default)]
654
    pub summary: String,
655
    #[serde(default)]
656
    pub url: String,
657
    /// Hex of a seal attestation reference the checker pushed, if any.
658
    #[serde(default)]
659
    pub seal: Option<String>,
660
}
661
662
// ------------------------------------------------------------- accounts
663
664
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
665
pub struct User {
666
    pub username: String,
667
    pub display_name: String,
668
    pub is_admin: bool,
669
    pub keys: Vec<String>,
670
    pub created_ms: i64,
671
}
672
673
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
674
pub struct Organisation {
675
    pub name: String,
676
    pub display_name: String,
677
    pub description: String,
678
    pub members: Vec<String>,
679
}
680
681
/// `GET /user/orgs` (#302): an organisation the caller belongs to, and
682
/// their role there.
683
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
684
pub struct UserOrg {
685
    pub name: String,
686
    pub display_name: String,
687
    pub role: String,
688
}
689
690
/// Forms accepted by the write endpoints.
691
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
692
pub struct NewRepository {
693
    pub owner: String,
694
    pub name: String,
695
    #[serde(default)]
696
    pub description: String,
697
    #[serde(default = "public")]
698
    pub visibility: Visibility,
699
}
700
701
fn public() -> Visibility {
702
    Visibility::Public
703
}
704
705
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
706
pub struct NewIssue {
707
    pub title: String,
708
    #[serde(default)]
709
    pub body: String,
710
    /// Label names; each must exist. Needs triage.
711
    #[serde(default)]
712
    pub labels: Vec<String>,
713
    /// Usernames. Needs triage.
714
    #[serde(default)]
715
    pub assignees: Vec<String>,
716
    /// A milestone's title. Needs triage.
717
    #[serde(default)]
718
    pub milestone: Option<String>,
719
}
720
721
/// `PATCH /repos/{o}/{n}/issues/{number}`: only the fields given change.
722
/// Title and body: the author or triage. The rest: triage.
723
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
724
pub struct IssueEdit {
725
    #[serde(default)]
726
    pub title: Option<String>,
727
    #[serde(default)]
728
    pub body: Option<String>,
729
    /// The whole set of labels.
730
    #[serde(default)]
731
    pub labels: Option<Vec<String>>,
732
    /// The whole set of assignees.
733
    #[serde(default)]
734
    pub assignees: Option<Vec<String>>,
735
    /// A milestone's title; the empty string clears it.
736
    #[serde(default)]
737
    pub milestone: Option<String>,
738
}
739
740
/// The checks a proposal needs, passed, to land on the repository's
741
/// default bookmark (hub spec §13.1). `GET` and `PUT
742
/// /repos/{o}/{n}/checks/required`.
743
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
744
pub struct RequiredChecks {
745
    pub names: Vec<String>,
746
}
747
748
/// A project (hub spec §8.2).
749
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
750
pub struct Project {
751
    pub owner: String,
752
    pub number: i64,
753
    pub title: String,
754
    pub description: String,
755
    pub public: bool,
756
    pub closed: bool,
757
    pub updated_ms: i64,
758
    /// The board on the hub, absolute.
759
    pub url: String,
760
}
761
762
/// A card as the caller may see it.
763
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
764
pub struct ProjectCard {
765
    pub id: i64,
766
    /// `issue`, `proposal` or `note`.
767
    pub kind: String,
768
    /// `owner/name#N`; empty for a note.
769
    pub reference: String,
770
    /// The issue's or proposal's title, or the note.
771
    pub title: String,
772
    /// The issue's or proposal's state; empty for a note.
773
    pub state: String,
774
    /// The issue's or proposal's label names (oxygenhub#293).
775
    #[serde(default)]
776
    pub labels: Vec<String>,
777
    /// An issue's assignees' usernames.
778
    #[serde(default)]
779
    pub assignees: Vec<String>,
780
    /// When it was archived (ms), for an archived card (oxygenhub#293).
781
    #[serde(default, skip_serializing_if = "Option::is_none")]
782
    pub archived_ms: Option<i64>,
783
}
784
785
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
786
pub struct ProjectColumn {
787
    pub id: i64,
788
    pub name: String,
789
    pub cards: Vec<ProjectCard>,
790
}
791
792
/// `GET /projects/{owner}/{n}`.
793
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
794
pub struct Board {
795
    pub project: Project,
796
    pub columns: Vec<ProjectColumn>,
797
}
798
799
/// `POST /projects/{owner}`.
800
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
801
pub struct NewProject {
802
    pub title: String,
803
    #[serde(default)]
804
    pub description: String,
805
    #[serde(default)]
806
    pub private: bool,
807
}
808
809
/// `PATCH /projects/{owner}/{n}`: only the fields given change.
810
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
811
pub struct ProjectEdit {
812
    /// Transfer the board to this owner (#125): one the caller may make
813
    /// boards under. It takes the next number there.
814
    #[serde(default, skip_serializing_if = "Option::is_none")]
815
    pub owner: Option<String>,
816
    #[serde(default)]
817
    pub title: Option<String>,
818
    #[serde(default)]
819
    pub description: Option<String>,
820
    #[serde(default)]
821
    pub private: Option<bool>,
822
    #[serde(default)]
823
    pub closed: Option<bool>,
824
}
825
826
/// `POST /projects/{owner}/{n}/cards`: a reference (`repo#12`) or a note,
827
/// into the column named (by id or name; the first column when absent).
828
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
829
pub struct NewCard {
830
    #[serde(default)]
831
    pub column: Option<String>,
832
    #[serde(default)]
833
    pub reference: String,
834
    #[serde(default)]
835
    pub note: String,
836
}
837
838
/// `PATCH /projects/{owner}/{n}/cards/{id}`: move to a column (id or name).
839
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
840
pub struct CardMove {
841
    pub column: String,
842
}
843
844
/// `POST /projects/{owner}/{n}/cards/move` (#289): every card of column
845
/// `from` to `column` at once, but those `except` names (card ids, or issue
846
/// and proposal numbers as `12`, `#12`, `name#12` or `owner/name#12`) and,
847
/// given `state`, only cards whose issue or proposal is in one of them
848
/// (`closed`, `landed`…). With `dry_run`, nothing moves.
849
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
850
pub struct CardsMove {
851
    pub from: String,
852
    pub column: String,
853
    #[serde(default)]
854
    pub except: Vec<String>,
855
    #[serde(default)]
856
    pub state: Vec<String>,
857
    #[serde(default)]
858
    pub dry_run: bool,
859
}
860
861
/// What a bulk move moved, and what it left in the column.
862
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
863
pub struct CardsMoved {
864
    pub moved: Vec<ProjectCard>,
865
    pub kept: Vec<ProjectCard>,
866
    pub dry_run: bool,
867
}
868
869
/// `POST /projects/{owner}/{n}/cards/archive` (oxygenhub#293): take the
870
/// cards of column `from` off the board, kept and restorable, but those
871
/// `except` names and, given `state`, only cards whose issue or proposal is
872
/// in one of them; given `older_days`, only cards that joined the column
873
/// more than that many days ago. With `dry_run`, nothing is archived.
874
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
875
pub struct CardsArchive {
876
    pub from: String,
877
    #[serde(default)]
878
    pub older_days: Option<i64>,
879
    #[serde(default)]
880
    pub except: Vec<String>,
881
    #[serde(default)]
882
    pub state: Vec<String>,
883
    #[serde(default)]
884
    pub dry_run: bool,
885
}
886
887
/// What an archive took off the board, and what it left in the column.
888
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
889
pub struct CardsArchived {
890
    pub archived: Vec<ProjectCard>,
891
    pub kept: Vec<ProjectCard>,
892
    pub dry_run: bool,
893
}
894
895
/// `POST /repos/{o}/{n}/labels`: create a label, or change one of that name.
896
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
897
pub struct NewLabel {
898
    pub name: String,
899
    /// `#rrggbb`; a default when absent.
900
    #[serde(default)]
901
    pub colour: Option<String>,
902
    #[serde(default)]
903
    pub description: String,
904
}
905
906
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
907
pub struct NewComment {
908
    pub body: String,
909
    /// For a proposal: anchor the comment to this file's line (1-based) of
910
    /// the projected state; the hub records the line's atom.
911
    #[serde(default)]
912
    pub path: Option<String>,
913
    #[serde(default)]
914
    pub line: Option<usize>,
915
}
916
917
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
918
pub struct NewProposal {
919
    pub title: String,
920
    #[serde(default)]
921
    pub body: String,
922
    pub target: String,
923
    /// A bookmark here, or `owner/name:bookmark` of a fork.
924
    pub source: String,
925
    #[serde(default)]
926
    pub draft: bool,
927
}
928
929
/// `POST .../proposals/{number}/reviewers`: accounts to ask for a review.
930
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
931
pub struct ReviewRequest {
932
    pub reviewers: Vec<String>,
933
}
934
935
/// `POST .../proposals/{number}/review-requests`: ask an AI assistant the
936
/// repository may use (hub spec §13.4) to review; it answers as a `comment`
937
/// review via the assistant.
938
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
939
pub struct AssistantRequest {
940
    pub assistant: String,
941
}
942
943
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
944
pub struct NewReview {
945
    pub verdict: String,
946
    #[serde(default)]
947
    pub body: String,
948
}
949
950
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
951
pub struct IssueStateChange {
952
    /// `open` or `closed`.
953
    pub state: String,
954
    #[serde(default)]
955
    pub reason: String,
956
}
957
958
/// A webhook payload's envelope (hub spec §12.2).
959
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
960
pub struct WebhookEnvelope {
961
    pub event: String,
962
    pub delivery: String,
963
    pub repository: Option<Repository>,
964
    pub actor: String,
965
    pub at_ms: i64,
966
    pub data: serde_json::Value,
967
}
968
969
/// A server-sent event on a proposal's stream.
970
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
971
pub struct ProposalEvent {
972
    pub number: i64,
973
    pub kind: String,
974
    pub check: Option<Check>,
975
}
976
977
// --------------------------------------------------------------- releases
978
979
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
980
pub struct Release {
981
    pub tag: String,
982
    pub title: String,
983
    pub notes: String,
984
    pub prerelease: bool,
985
    pub latest: bool,
986
    pub author: String,
987
    pub heads: Vec<String>,
988
    pub signer: Option<String>,
989
    pub assets: Vec<ReleaseAsset>,
990
    pub archives: Vec<String>,
991
    pub created_ms: i64,
992
    pub url: String,
993
}
994
995
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
996
pub struct ReleaseAsset {
997
    pub name: String,
998
    pub size: i64,
999
    /// BLAKE3 of the content, hex.
1000
    pub hash: String,
1001
    pub content_type: String,
1002
    pub downloads: i64,
1003
    pub url: String,
1004
    /// The OxygenFlow run and job whose artifact has this content, if any.
1005
    #[serde(default, skip_serializing_if = "Option::is_none")]
1006
    pub built_by: Option<AssetBuild>,
1007
}
1008
1009
/// Where a release asset was built (hub spec §9): a job's artifact with the
1010
/// same BLAKE3, and that job's signed receipt when one was kept.
1011
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1012
pub struct AssetBuild {
1013
    pub run: i64,
1014
    pub job: String,
1015
    pub artifact: String,
1016
    pub run_url: String,
1017
    /// The receipt attestation, hex; `None` when the receipt was not signed.
1018
    pub receipt: Option<String>,
1019
    pub receipt_url: Option<String>,
1020
    pub signer: Option<String>,
1021
}
1022
1023
/// `PATCH /repos/{o}/{n}/proposals/{number}`: what is given changes,
1024
/// the rest stays (oxygenhub#76).
1025
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1026
pub struct ProposalEdit {
1027
    #[serde(default, skip_serializing_if = "Option::is_none")]
1028
    pub title: Option<String>,
1029
    #[serde(default, skip_serializing_if = "Option::is_none")]
1030
    pub body: Option<String>,
1031
    /// The whole set of labels, by name (triage); oxygenhub#80.
1032
    #[serde(default, skip_serializing_if = "Option::is_none")]
1033
    pub labels: Option<Vec<String>>,
1034
    /// `closed` or `open` (reopen), by its author or with triage access,
1035
    /// as the page's Close and Reopen do (oxygenhub#140).
1036
    #[serde(default, skip_serializing_if = "Option::is_none")]
1037
    pub state: Option<String>,
1038
}
1039
1040
/// `PATCH /repos/{owner}/{name}/releases/{tag}`: what to change; fields
1041
/// left out stay as they are.
1042
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1043
pub struct ReleaseEdit {
1044
    #[serde(default, skip_serializing_if = "Option::is_none")]
1045
    pub title: Option<String>,
1046
    #[serde(default, skip_serializing_if = "Option::is_none")]
1047
    pub notes: Option<String>,
1048
    #[serde(default, skip_serializing_if = "Option::is_none")]
1049
    pub prerelease: Option<bool>,
1050
}
1051
1052
/// A drop (oxygenhub#279): a small snippet of one or more files, its own
1053
/// Oxygen repository, never listed among repositories. `GET /drops` lists
1054
/// yours, `GET /users/{name}/drops` someone's public ones, and
1055
/// `GET /drops/{id}` one with its files' content.
1056
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1057
pub struct Drop {
1058
    /// 24 hex digits, unique on the hub.
1059
    pub id: String,
1060
    pub owner: String,
1061
    pub title: String,
1062
    pub description: String,
1063
    /// `public` (listed on its owner's Drops page) or `secret` (unlisted:
1064
    /// readable by anyone with its address).
1065
    pub visibility: String,
1066
    /// The drop's page.
1067
    pub url: String,
1068
    /// What `oxy clone` takes.
1069
    pub clone_url: String,
1070
    pub created_ms: i64,
1071
    pub updated_ms: i64,
1072
    pub files: Vec<DropFile>,
1073
}
1074
1075
/// One of a drop's files. Lists carry no content; one drop's view carries
1076
/// the content of each text file up to 512 KiB.
1077
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1078
pub struct DropFile {
1079
    pub name: String,
1080
    pub size: u64,
1081
    #[serde(default, skip_serializing_if = "Option::is_none")]
1082
    pub content: Option<String>,
1083
    /// The file's bytes on the default bookmark.
1084
    pub raw_url: String,
1085
}
1086
1087
/// `POST /drops`: a new drop with at least one file.
1088
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1089
pub struct NewDrop {
1090
    #[serde(default)]
1091
    pub title: String,
1092
    #[serde(default)]
1093
    pub description: String,
1094
    /// Unlisted, readable by anyone with its address.
1095
    #[serde(default)]
1096
    pub secret: bool,
1097
    pub files: Vec<NewDropFile>,
1098
}
1099
1100
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1101
pub struct NewDropFile {
1102
    pub name: String,
1103
    pub content: String,
1104
}
1105
1106
/// `PATCH /drops/{id}`: what to change; what is left out stays.
1107
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1108
pub struct DropEdit {
1109
    #[serde(default, skip_serializing_if = "Option::is_none")]
1110
    pub title: Option<String>,
1111
    #[serde(default, skip_serializing_if = "Option::is_none")]
1112
    pub description: Option<String>,
1113
    #[serde(default, skip_serializing_if = "Option::is_none")]
1114
    pub secret: Option<bool>,
1115
    /// Files to write, or to remove (`content` null); others are kept.
1116
    #[serde(default)]
1117
    pub files: Vec<DropFileEdit>,
1118
    /// The change's message (default "Edit TITLE").
1119
    #[serde(default, skip_serializing_if = "Option::is_none")]
1120
    pub message: Option<String>,
1121
}
1122
1123
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1124
pub struct DropFileEdit {
1125
    pub name: String,
1126
    #[serde(default)]
1127
    pub content: Option<String>,
1128
}
1129
1130
/// `POST …/tags` (#295): tag the state of `target` (a bookmark, tag or
1131
/// change; the default bookmark when absent).
1132
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1133
pub struct NewTag {
1134
    pub name: String,
1135
    #[serde(default)]
1136
    pub target: Option<String>,
1137
    #[serde(default)]
1138
    pub message: Option<String>,
1139
}
1140
1141
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1142
pub struct NewRelease {
1143
    pub tag: String,
1144
    pub title: String,
1145
    #[serde(default)]
1146
    pub notes: Option<String>,
1147
    #[serde(default)]
1148
    pub prerelease: bool,
1149
}
1150
1151
/// `GET /repos/{o}/{n}/diffusion` (oxygenhub#153): what a repository
1152
/// takes from (the subrepos it pins) and what it diffuses to (the
1153
/// repositories that pin it), each as the Diffusion pages show it.
1154
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1155
pub struct Diffusion {
1156
    pub takes_from: Vec<DiffusionPin>,
1157
    pub diffuses_to: Vec<DiffusionPin>,
1158
}
1159
1160
/// One pin of an upstream by a consumer, both named `owner/name`.
1161
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1162
pub struct DiffusionPin {
1163
    pub upstream: String,
1164
    pub consumer: String,
1165
    /// Where the consumer pins it.
1166
    pub path: String,
1167
    /// The consumer's bookmark its bumps land on.
1168
    pub bookmark: String,
1169
    /// Upstream changes the pin lacks; absent when the hub cannot tell.
1170
    #[serde(default)]
1171
    pub behind: Option<u64>,
1172
    /// `off`, `green` or `any`.
1173
    pub follow: String,
1174
    /// The open bump proposal's number, on the consumer.
1175
    #[serde(default)]
1176
    pub bump: Option<i64>,
1177
    /// The newest run of the bump: number and status.
1178
    #[serde(default)]
1179
    pub run: Option<i64>,
1180
    #[serde(default)]
1181
    pub run_status: Option<String>,
1182
    /// The pill: the upstream's half, then the consumer's.
1183
    pub upstream_state: DiffusionHalf,
1184
    pub consumer_state: DiffusionHalf,
1185
}
1186
1187
/// One half of the Diffusion pill.
1188
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1189
pub struct DiffusionHalf {
1190
    /// `green`, `amber`, `red`, `grey` or `off`.
1191
    pub tone: String,
1192
    /// What the pill says: `checked`, `untested`, `passes`, `up to date`…
1193
    pub word: String,
1194
    /// The sentence behind it.
1195
    pub title: String,
1196
}
1197
1198
/// Every type of the API, for schema generation.
1199
pub fn schemas() -> Vec<(&'static str, schemars::Schema)> {
1200
    vec![
1201
        ("Repository", schemars::schema_for!(Repository)),
1202
        ("Diffusion", schemars::schema_for!(Diffusion)),
1203
        ("DiffusionPin", schemars::schema_for!(DiffusionPin)),
1204
        ("DiffusionHalf", schemars::schema_for!(DiffusionHalf)),
1205
        ("Visibility", schemars::schema_for!(Visibility)),
1206
        ("Bookmark", schemars::schema_for!(Bookmark)),
1207
        ("Tag", schemars::schema_for!(Tag)),
1208
        ("ChangeSummary", schemars::schema_for!(ChangeSummary)),
1209
        ("Author", schemars::schema_for!(Author)),
1210
        ("Signature", schemars::schema_for!(Signature)),
1211
        ("Problem", schemars::schema_for!(Problem)),
1212
        ("Proposal", schemars::schema_for!(Proposal)),
1213
        ("ProposalState", schemars::schema_for!(ProposalState)),
1214
        ("ProposalSource", schemars::schema_for!(ProposalSource)),
1215
        ("Approval", schemars::schema_for!(Approval)),
1216
        ("Issue", schemars::schema_for!(Issue)),
1217
        ("Label", schemars::schema_for!(Label)),
1218
        ("Milestone", schemars::schema_for!(Milestone)),
1219
        ("NewMilestone", schemars::schema_for!(NewMilestone)),
1220
        ("MilestoneEdit", schemars::schema_for!(MilestoneEdit)),
1221
        ("Comment", schemars::schema_for!(Comment)),
1222
        ("ProposalFile", schemars::schema_for!(ProposalFile)),
1223
        ("Notification", schemars::schema_for!(Notification)),
1224
        ("Inbox", schemars::schema_for!(Inbox)),
1225
        ("Atom", schemars::schema_for!(Atom)),
1226
        ("Review", schemars::schema_for!(Review)),
1227
        ("TreeEntry", schemars::schema_for!(TreeEntry)),
1228
        ("BlameLine", schemars::schema_for!(BlameLine)),
1229
        ("FileChange", schemars::schema_for!(FileChange)),
1230
        ("ChangeDetail", schemars::schema_for!(ChangeDetail)),
1231
        ("History", schemars::schema_for!(History)),
1232
        ("Conflict", schemars::schema_for!(Conflict)),
1233
        ("Push", schemars::schema_for!(Push)),
1234
        ("Trust", schemars::schema_for!(Trust)),
1235
        ("Policy", schemars::schema_for!(Policy)),
1236
        ("Rule", schemars::schema_for!(Rule)),
1237
        ("Hook", schemars::schema_for!(Hook)),
1238
        ("NewHook", schemars::schema_for!(NewHook)),
1239
        ("Check", schemars::schema_for!(Check)),
1240
        ("CheckStatus", schemars::schema_for!(CheckStatus)),
1241
        ("NewCheck", schemars::schema_for!(NewCheck)),
1242
        ("User", schemars::schema_for!(User)),
1243
        ("Organisation", schemars::schema_for!(Organisation)),
1244
        ("NewRepository", schemars::schema_for!(NewRepository)),
1245
        ("NewIssue", schemars::schema_for!(NewIssue)),
1246
        ("IssueEdit", schemars::schema_for!(IssueEdit)),
1247
        ("ReleaseEdit", schemars::schema_for!(ReleaseEdit)),
1248
        ("ProposalEdit", schemars::schema_for!(ProposalEdit)),
1249
        ("NewLabel", schemars::schema_for!(NewLabel)),
1250
        ("RequiredChecks", schemars::schema_for!(RequiredChecks)),
1251
        ("Project", schemars::schema_for!(Project)),
1252
        ("ProjectCard", schemars::schema_for!(ProjectCard)),
1253
        ("ProjectColumn", schemars::schema_for!(ProjectColumn)),
1254
        ("Board", schemars::schema_for!(Board)),
1255
        ("NewProject", schemars::schema_for!(NewProject)),
1256
        ("ProjectEdit", schemars::schema_for!(ProjectEdit)),
1257
        ("NewCard", schemars::schema_for!(NewCard)),
1258
        ("CardMove", schemars::schema_for!(CardMove)),
1259
        ("NewComment", schemars::schema_for!(NewComment)),
1260
        ("NewProposal", schemars::schema_for!(NewProposal)),
1261
        ("NewReview", schemars::schema_for!(NewReview)),
1262
        ("IssueStateChange", schemars::schema_for!(IssueStateChange)),
1263
        ("WebhookEnvelope", schemars::schema_for!(WebhookEnvelope)),
1264
        ("ProposalEvent", schemars::schema_for!(ProposalEvent)),
1265
        ("Release", schemars::schema_for!(Release)),
1266
        ("FlowRun", schemars::schema_for!(FlowRun)),
1267
        ("FlowJob", schemars::schema_for!(FlowJob)),
1268
        ("FlowLogLine", schemars::schema_for!(FlowLogLine)),
1269
        ("AssetBuild", schemars::schema_for!(AssetBuild)),
1270
        ("ReleaseAsset", schemars::schema_for!(ReleaseAsset)),
1271
        ("NewRelease", schemars::schema_for!(NewRelease)),
1272
        ("Drop", schemars::schema_for!(Drop)),
1273
        ("NewDrop", schemars::schema_for!(NewDrop)),
1274
        ("DropEdit", schemars::schema_for!(DropEdit)),
1275
    ]
1276
}
1277
1278
/// An OxygenFlow runner (`GET /api/v1/runners`, site administrators).
1279
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1280
pub struct Runner {
1281
    pub id: i64,
1282
    pub name: String,
1283
    /// `online`, `offline`, `draining` or `disabled`.
1284
    pub status: String,
1285
    /// What it serves: empty for the whole site, an owner, or `owner/name`.
1286
    pub serves: String,
1287
    pub arch: String,
1288
    pub os: String,
1289
    pub version: String,
1290
    pub labels: Vec<String>,
1291
    pub max_jobs: i64,
1292
    pub memory_mib: Option<i64>,
1293
    pub cpus: Option<i64>,
1294
    /// The key that signs its receipts (KeyId hex), empty until bound.
1295
    pub key: String,
1296
    /// `registered` or `config` (a hub.toml token).
1297
    pub source: String,
1298
    pub last_seen_ms: Option<i64>,
1299
    /// Jobs it is running now.
1300
    pub running: i64,
1301
    /// What it measured at its last claim (oxygenflow#40): free disk in
1302
    /// MiB, the 1-minute load ×100, its speed score (100 on the reference
1303
    /// machine) and class 1–5, its kernel.
1304
    #[serde(default, skip_serializing_if = "Option::is_none")]
1305
    pub free_disk_mib: Option<i64>,
1306
    #[serde(default, skip_serializing_if = "Option::is_none")]
1307
    pub load_x100: Option<i64>,
1308
    #[serde(default, skip_serializing_if = "Option::is_none")]
1309
    pub speed: Option<i64>,
1310
    #[serde(default, skip_serializing_if = "Option::is_none")]
1311
    pub speed_class: Option<i64>,
1312
    #[serde(default, skip_serializing_if = "String::is_empty")]
1313
    pub kernel: String,
1314
}
1315
1316
/// A job a runner ran or is running.
1317
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1318
pub struct RunnerJob {
1319
    pub repo: String,
1320
    pub run: i64,
1321
    pub job: String,
1322
    pub status: String,
1323
    pub started_ms: Option<i64>,
1324
    pub finished_ms: Option<i64>,
1325
}
1326
1327
/// A job in the queue: running ones first, then queued ones in the order
1328
/// runners claim them.
1329
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1330
pub struct QueueItem {
1331
    pub repo: String,
1332
    pub run: i64,
1333
    pub job: String,
1334
    /// `running` or `queued`.
1335
    pub status: String,
1336
    /// The runner holding it, when running.
1337
    pub runner: String,
1338
}
1339
1340
// ------------------------------------------------------------- assistants
1341
1342
/// An AI assistant at a level (hub spec §13.4). The token never leaves the
1343
/// hub: `has_token` says whether one is set.
1344
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1345
pub struct Assistant {
1346
    pub name: String,
1347
    pub endpoint: String,
1348
    pub api: String,
1349
    pub model: String,
1350
    #[serde(default, skip_serializing_if = "String::is_empty")]
1351
    pub headers: String,
1352
    pub enabled: bool,
1353
    pub budget: i64,
1354
    pub has_token: bool,
1355
    /// Where it comes from: empty for the level's own, else `the site` or
1356
    /// `the NAME organisation`.
1357
    #[serde(default, skip_serializing_if = "String::is_empty")]
1358
    pub from: String,
1359
    /// Off because a level above turned a name like it off.
1360
    #[serde(default)]
1361
    pub off_above: bool,
1362
}
1363
1364
/// `POST …/assistants`: add one, or change the one of that name. A
1365
/// `preset` (`anthropic`, `openai`, `gemini`, `deepseek`, `mistral`,
1366
/// `perplexity`, `ollama`) fills what is left out; the model must be one
1367
/// the endpoint lists when it lists any; `token` is write-only.
1368
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1369
pub struct NewAssistant {
1370
    #[serde(default)]
1371
    pub name: String,
1372
    #[serde(default)]
1373
    pub preset: String,
1374
    #[serde(default)]
1375
    pub endpoint: String,
1376
    #[serde(default)]
1377
    pub api: String,
1378
    pub model: String,
1379
    #[serde(default)]
1380
    pub token: String,
1381
    #[serde(default)]
1382
    pub headers: String,
1383
    #[serde(default = "yes")]
1384
    pub enabled: bool,
1385
    #[serde(default)]
1386
    pub budget: Option<i64>,
1387
}
1388
1389
fn yes() -> bool {
1390
    true
1391
}
1392
1393
/// A level's prompt and those it inherits, outermost first.
1394
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1395
pub struct AssistantPrompt {
1396
    pub prompt: String,
1397
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1398
    pub inherited: Vec<(String, String)>,
1399
}
1400
1401
/// `GET /repos/{o}/{n}/coverage`: a coverage report from a Flow job
1402
/// (oxygenhub#113); `percent` values are of lines, functions and branches,
1403
/// absent when nothing was counted.
1404
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1405
pub struct CoverageReport {
1406
    pub id: i64,
1407
    pub run: i64,
1408
    pub job: String,
1409
    pub bookmark: String,
1410
    /// The run's state, by hash.
1411
    pub state: String,
1412
    /// `lcov` or `cobertura`.
1413
    pub format: String,
1414
    pub lines_found: i64,
1415
    pub lines_hit: i64,
1416
    pub percent: Option<f64>,
1417
    pub functions_found: i64,
1418
    pub functions_hit: i64,
1419
    pub branches_found: i64,
1420
    pub branches_hit: i64,
1421
    pub files: i64,
1422
    /// Files the report named that are not in the run's state.
1423
    pub dropped: i64,
1424
    pub created_ms: i64,
1425
    /// The report on the hub's Coverage tab, absolute.
1426
    pub url: String,
1427
    /// Who uploaded it from a workstation (#136), when no Flow job made it;
1428
    /// `run` and `job` are then 0 and "upload".
1429
    #[serde(default, skip_serializing_if = "Option::is_none")]
1430
    pub uploaded_by: Option<String>,
1431
}
1432
1433
/// One file of a coverage report.
1434
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1435
pub struct CoverageFile {
1436
    pub path: String,
1437
    pub lines_found: i64,
1438
    pub lines_hit: i64,
1439
    pub percent: Option<f64>,
1440
    pub functions_found: i64,
1441
    pub functions_hit: i64,
1442
    pub branches_found: i64,
1443
    pub branches_hit: i64,
1444
}
1445
1446
/// `GET /repos/{o}/{n}/coverage/{id}`: a report with its files.
1447
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1448
pub struct CoverageDetail {
1449
    pub report: CoverageReport,
1450
    pub files: Vec<CoverageFile>,
1451
}
1452
1453
/// `GET /repos/{o}/{n}/tests`: a JUnit test report from a Flow job
1454
/// (oxygenhub#114).
1455
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1456
pub struct TestReport {
1457
    pub id: i64,
1458
    pub run: i64,
1459
    pub job: String,
1460
    pub bookmark: String,
1461
    pub state: String,
1462
    pub tests: i64,
1463
    pub passed: i64,
1464
    pub failed: i64,
1465
    pub errors: i64,
1466
    pub skipped: i64,
1467
    /// The cases' times added up.
1468
    pub time_ms: i64,
1469
    pub created_ms: i64,
1470
    pub url: String,
1471
}
1472
1473
/// One test case of a report.
1474
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1475
pub struct TestCase {
1476
    pub suite: String,
1477
    pub classname: String,
1478
    pub name: String,
1479
    /// `passed`, `failed`, `error` or `skipped`.
1480
    pub status: String,
1481
    pub time_ms: i64,
1482
    pub message: String,
1483
    /// A failure's text and output, cut to 16 KiB; empty for a pass.
1484
    pub output: String,
1485
}
1486
1487
/// `GET /repos/{o}/{n}/tests/{id}`: a report with its cases
1488
/// (`?status=failed` for the failed and errored ones).
1489
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1490
pub struct TestReportDetail {
1491
    pub report: TestReport,
1492
    pub cases: Vec<TestCase>,
1493
}