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