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