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