OXYGENHUB

Coverage / crates/hub-api/src/lib.rs 34.5%

49 of 142 lines run, 12 of 25 functions · run #476 on main · run missed

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 {
36228×
    pub fn as_str(self) -> &'static str {
37228×
        match self {
38205×
            Visibility::Public => "public",
391×
            Visibility::Internal => "internal",
4022×
            Visibility::Private => "private",
41
        }
42228×
    }
43
441639×
    pub fn parse(s: &str) -> Option<Visibility> {
451639×
        Some(match s {
461639×
            "public" => Visibility::Public,
47156×
            "internal" => Visibility::Internal,
48155×
            "private" => Visibility::Private,
491×
            _ => return None,
50
        })
511639×
    }
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.
12149×
    pub fn note_for(key: &str, account: &Option<String>) -> Option<String> {
12249×
        (!key.is_empty() && account.is_none()).then(|| Self::UNLINKED.to_string())
12349×
    }
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]
1481×
    fn visibility_round_trips() {
1493×
        for v in [Visibility::Public, Visibility::Internal, Visibility::Private] {
1503×
            assert_eq!(Visibility::parse(v.as_str()), Some(v));
151
        }
1521×
        assert_eq!(Visibility::parse("secret"), None);
1531×
    }
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 {
2170×
    pub fn as_str(self) -> &'static str {
2180×
        match self {
2190×
            ProposalState::Draft => "draft",
2200×
            ProposalState::Open => "open",
2210×
            ProposalState::Landed => "landed",
2220×
            ProposalState::Closed => "closed",
223
        }
2240×
    }
225
22639×
    pub fn parse(s: &str) -> Option<ProposalState> {
22739×
        Some(match s {
22839×
            "draft" => ProposalState::Draft,
22937×
            "open" => ProposalState::Open,
23010×
            "landed" => ProposalState::Landed,
2313×
            "closed" => ProposalState::Closed,
2320×
            _ => return None,
233
        })
23439×
    }
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
5470×
fn star() -> String {
5480×
    "*".into()
5490×
}
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 {
6442×
    pub fn as_str(self) -> &'static str {
6452×
        match self {
6460×
            CheckStatus::Queued => "queued",
6470×
            CheckStatus::Running => "running",
6481×
            CheckStatus::Passed => "passed",
6491×
            CheckStatus::Failed => "failed",
6500×
            CheckStatus::Cancelled => "cancelled",
6510×
            CheckStatus::Skipped => "skipped",
652
        }
6532×
    }
654
655709×
    pub fn parse(s: &str) -> Option<CheckStatus> {
656709×
        Some(match s {
657709×
            "queued" => CheckStatus::Queued,
658333×
            "running" => CheckStatus::Running,
659174×
            "passed" => CheckStatus::Passed,
66074×
            "failed" => CheckStatus::Failed,
66150×
            "cancelled" => CheckStatus::Cancelled,
6628×
            "skipped" => CheckStatus::Skipped,
6630×
            _ => return None,
664
        })
665709×
    }
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
7702×
fn public() -> Visibility {
7712×
    Visibility::Public
7722×
}
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
    /// The asset's SLSA provenance, signed by the hub (oxygenhub#239):
1091
    /// `cosign verify-blob-attestation --key …/.well-known/oxyhub-signing.pem
1092
    /// --type slsaprovenance1 --insecure-ignore-tlog=true --signature PROVENANCE ASSET`. `None` when the
1093
    /// receipt was not signed.
1094
    #[serde(default)]
1095
    pub provenance_url: Option<String>,
1096
}
1097
1098
/// `PATCH /repos/{o}/{n}/proposals/{number}`: what is given changes,
1099
/// the rest stays (oxygenhub#76).
1100
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1101
pub struct ProposalEdit {
1102
    #[serde(default, skip_serializing_if = "Option::is_none")]
1103
    pub title: Option<String>,
1104
    #[serde(default, skip_serializing_if = "Option::is_none")]
1105
    pub body: Option<String>,
1106
    /// The whole set of labels, by name (triage); oxygenhub#80.
1107
    #[serde(default, skip_serializing_if = "Option::is_none")]
1108
    pub labels: Option<Vec<String>>,
1109
    /// `closed`, `open` (reopen a closed one, or make a draft ready for
1110
    /// review) or `draft` (turn an open one back into a draft), by its
1111
    /// author or with triage access, as the page's buttons do
1112
    /// (oxygenhub#140, #313).
1113
    #[serde(default, skip_serializing_if = "Option::is_none")]
1114
    pub state: Option<String>,
1115
    /// `false` makes a draft ready for review, `true` turns an open
1116
    /// proposal back into a draft: the same as `state`, in the words a
1117
    /// proposal is created with (#313).
1118
    #[serde(default, skip_serializing_if = "Option::is_none")]
1119
    pub draft: Option<bool>,
1120
}
1121
1122
/// `PATCH /repos/{owner}/{name}/releases/{tag}`: what to change; fields
1123
/// left out stay as they are.
1124
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1125
pub struct ReleaseEdit {
1126
    #[serde(default, skip_serializing_if = "Option::is_none")]
1127
    pub title: Option<String>,
1128
    #[serde(default, skip_serializing_if = "Option::is_none")]
1129
    pub notes: Option<String>,
1130
    #[serde(default, skip_serializing_if = "Option::is_none")]
1131
    pub prerelease: Option<bool>,
1132
}
1133
1134
/// A drop (oxygenhub#279): a small snippet of one or more files, its own
1135
/// Oxygen repository, never listed among repositories. `GET /drops` lists
1136
/// yours, `GET /users/{name}/drops` someone's public ones, and
1137
/// `GET /drops/{id}` one with its files' content.
1138
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1139
pub struct Drop {
1140
    /// 24 hex digits, unique on the hub.
1141
    pub id: String,
1142
    pub owner: String,
1143
    pub title: String,
1144
    pub description: String,
1145
    /// `public` (listed on its owner's Drops page) or `secret` (unlisted:
1146
    /// readable by anyone with its address).
1147
    pub visibility: String,
1148
    /// The drop's page.
1149
    pub url: String,
1150
    /// What `oxy clone` takes.
1151
    pub clone_url: String,
1152
    pub created_ms: i64,
1153
    pub updated_ms: i64,
1154
    pub files: Vec<DropFile>,
1155
}
1156
1157
/// One of a drop's files. Lists carry no content; one drop's view carries
1158
/// the content of each text file up to 512 KiB.
1159
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1160
pub struct DropFile {
1161
    pub name: String,
1162
    pub size: u64,
1163
    #[serde(default, skip_serializing_if = "Option::is_none")]
1164
    pub content: Option<String>,
1165
    /// The file's bytes on the default bookmark.
1166
    pub raw_url: String,
1167
}
1168
1169
/// `POST /drops`: a new drop with at least one file.
1170
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1171
pub struct NewDrop {
1172
    #[serde(default)]
1173
    pub title: String,
1174
    #[serde(default)]
1175
    pub description: String,
1176
    /// Unlisted, readable by anyone with its address.
1177
    #[serde(default)]
1178
    pub secret: bool,
1179
    pub files: Vec<NewDropFile>,
1180
}
1181
1182
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1183
pub struct NewDropFile {
1184
    pub name: String,
1185
    pub content: String,
1186
}
1187
1188
/// `PATCH /drops/{id}`: what to change; what is left out stays.
1189
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1190
pub struct DropEdit {
1191
    #[serde(default, skip_serializing_if = "Option::is_none")]
1192
    pub title: Option<String>,
1193
    #[serde(default, skip_serializing_if = "Option::is_none")]
1194
    pub description: Option<String>,
1195
    #[serde(default, skip_serializing_if = "Option::is_none")]
1196
    pub secret: Option<bool>,
1197
    /// Files to write, or to remove (`content` null); others are kept.
1198
    #[serde(default)]
1199
    pub files: Vec<DropFileEdit>,
1200
    /// The change's message (default "Edit TITLE").
1201
    #[serde(default, skip_serializing_if = "Option::is_none")]
1202
    pub message: Option<String>,
1203
}
1204
1205
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1206
pub struct DropFileEdit {
1207
    pub name: String,
1208
    #[serde(default)]
1209
    pub content: Option<String>,
1210
}
1211
1212
/// `POST …/tags` (#295): tag the state of `target` (a bookmark, tag or
1213
/// change; the default bookmark when absent).
1214
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1215
pub struct NewTag {
1216
    pub name: String,
1217
    #[serde(default)]
1218
    pub target: Option<String>,
1219
    #[serde(default)]
1220
    pub message: Option<String>,
1221
}
1222
1223
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1224
pub struct NewRelease {
1225
    pub tag: String,
1226
    pub title: String,
1227
    #[serde(default)]
1228
    pub notes: Option<String>,
1229
    #[serde(default)]
1230
    pub prerelease: bool,
1231
}
1232
1233
/// `GET /repos/{o}/{n}/diffusion` (oxygenhub#153): what a repository
1234
/// takes from (the subrepos it pins) and what it diffuses to (the
1235
/// repositories that pin it), each as the Diffusion pages show it.
1236
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1237
pub struct Diffusion {
1238
    pub takes_from: Vec<DiffusionPin>,
1239
    pub diffuses_to: Vec<DiffusionPin>,
1240
}
1241
1242
/// One pin of an upstream by a consumer, both named `owner/name`.
1243
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1244
pub struct DiffusionPin {
1245
    pub upstream: String,
1246
    pub consumer: String,
1247
    /// Where the consumer pins it.
1248
    pub path: String,
1249
    /// The consumer's bookmark its bumps land on.
1250
    pub bookmark: String,
1251
    /// Upstream changes the pin lacks; absent when the hub cannot tell.
1252
    #[serde(default)]
1253
    pub behind: Option<u64>,
1254
    /// `off`, `green` or `any`.
1255
    pub follow: String,
1256
    /// The open bump proposal's number, on the consumer.
1257
    #[serde(default)]
1258
    pub bump: Option<i64>,
1259
    /// The newest run of the bump: number and status.
1260
    #[serde(default)]
1261
    pub run: Option<i64>,
1262
    #[serde(default)]
1263
    pub run_status: Option<String>,
1264
    /// The pill: the upstream's half, then the consumer's.
1265
    pub upstream_state: DiffusionHalf,
1266
    pub consumer_state: DiffusionHalf,
1267
}
1268
1269
/// One half of the Diffusion pill.
1270
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1271
pub struct DiffusionHalf {
1272
    /// `green`, `amber`, `red`, `grey` or `off`.
1273
    pub tone: String,
1274
    /// What the pill says: `checked`, `untested`, `passes`, `up to date`…
1275
    pub word: String,
1276
    /// The sentence behind it.
1277
    pub title: String,
1278
}
1279
1280
/// Every type of the API, for schema generation.
12810×
pub fn schemas() -> Vec<(&'static str, schemars::Schema)> {
12820×
    vec![
12830×
        ("Repository", schemars::schema_for!(Repository)),
12840×
        ("Diffusion", schemars::schema_for!(Diffusion)),
12850×
        ("DiffusionPin", schemars::schema_for!(DiffusionPin)),
12860×
        ("DiffusionHalf", schemars::schema_for!(DiffusionHalf)),
12870×
        ("Visibility", schemars::schema_for!(Visibility)),
12880×
        ("Bookmark", schemars::schema_for!(Bookmark)),
12890×
        ("Tag", schemars::schema_for!(Tag)),
12900×
        ("ChangeSummary", schemars::schema_for!(ChangeSummary)),
12910×
        ("Author", schemars::schema_for!(Author)),
12920×
        ("Signature", schemars::schema_for!(Signature)),
12930×
        ("Problem", schemars::schema_for!(Problem)),
12940×
        ("Proposal", schemars::schema_for!(Proposal)),
12950×
        ("ProposalState", schemars::schema_for!(ProposalState)),
12960×
        ("ProposalSource", schemars::schema_for!(ProposalSource)),
12970×
        ("Approval", schemars::schema_for!(Approval)),
12980×
        ("Issue", schemars::schema_for!(Issue)),
12990×
        ("Label", schemars::schema_for!(Label)),
13000×
        ("Milestone", schemars::schema_for!(Milestone)),
13010×
        ("NewMilestone", schemars::schema_for!(NewMilestone)),
13020×
        ("MilestoneEdit", schemars::schema_for!(MilestoneEdit)),
13030×
        ("Comment", schemars::schema_for!(Comment)),
13040×
        ("ProposalFile", schemars::schema_for!(ProposalFile)),
13050×
        ("Notification", schemars::schema_for!(Notification)),
13060×
        ("Inbox", schemars::schema_for!(Inbox)),
13070×
        ("Atom", schemars::schema_for!(Atom)),
13080×
        ("Review", schemars::schema_for!(Review)),
13090×
        ("TreeEntry", schemars::schema_for!(TreeEntry)),
13100×
        ("BlameLine", schemars::schema_for!(BlameLine)),
13110×
        ("FileChange", schemars::schema_for!(FileChange)),
13120×
        ("ChangeDetail", schemars::schema_for!(ChangeDetail)),
13130×
        ("History", schemars::schema_for!(History)),
13140×
        ("Conflict", schemars::schema_for!(Conflict)),
13150×
        ("Push", schemars::schema_for!(Push)),
13160×
        ("Trust", schemars::schema_for!(Trust)),
13170×
        ("Policy", schemars::schema_for!(Policy)),
13180×
        ("Rule", schemars::schema_for!(Rule)),
13190×
        ("Hook", schemars::schema_for!(Hook)),
13200×
        ("NewHook", schemars::schema_for!(NewHook)),
13210×
        ("Check", schemars::schema_for!(Check)),
13220×
        ("CheckStatus", schemars::schema_for!(CheckStatus)),
13230×
        ("NewCheck", schemars::schema_for!(NewCheck)),
13240×
        ("User", schemars::schema_for!(User)),
13250×
        ("Organisation", schemars::schema_for!(Organisation)),
13260×
        ("NewRepository", schemars::schema_for!(NewRepository)),
13270×
        ("NewIssue", schemars::schema_for!(NewIssue)),
13280×
        ("IssueEdit", schemars::schema_for!(IssueEdit)),
13290×
        ("ReleaseEdit", schemars::schema_for!(ReleaseEdit)),
13300×
        ("ProposalEdit", schemars::schema_for!(ProposalEdit)),
13310×
        ("NewLabel", schemars::schema_for!(NewLabel)),
13320×
        ("RequiredChecks", schemars::schema_for!(RequiredChecks)),
13330×
        ("Project", schemars::schema_for!(Project)),
13340×
        ("ProjectCard", schemars::schema_for!(ProjectCard)),
13350×
        ("ProjectColumn", schemars::schema_for!(ProjectColumn)),
13360×
        ("Board", schemars::schema_for!(Board)),
13370×
        ("NewProject", schemars::schema_for!(NewProject)),
13380×
        ("ProjectEdit", schemars::schema_for!(ProjectEdit)),
13390×
        ("NewCard", schemars::schema_for!(NewCard)),
13400×
        ("CardMove", schemars::schema_for!(CardMove)),
13410×
        ("NewComment", schemars::schema_for!(NewComment)),
13420×
        ("NewProposal", schemars::schema_for!(NewProposal)),
13430×
        ("NewReview", schemars::schema_for!(NewReview)),
13440×
        ("IssueStateChange", schemars::schema_for!(IssueStateChange)),
13450×
        ("WebhookEnvelope", schemars::schema_for!(WebhookEnvelope)),
13460×
        ("ProposalEvent", schemars::schema_for!(ProposalEvent)),
13470×
        ("Release", schemars::schema_for!(Release)),
13480×
        ("FlowRun", schemars::schema_for!(FlowRun)),
13490×
        ("FlowJob", schemars::schema_for!(FlowJob)),
13500×
        ("FlowLogLine", schemars::schema_for!(FlowLogLine)),
13510×
        ("AssetBuild", schemars::schema_for!(AssetBuild)),
13520×
        ("ReleaseAsset", schemars::schema_for!(ReleaseAsset)),
13530×
        ("NewRelease", schemars::schema_for!(NewRelease)),
13540×
        ("Drop", schemars::schema_for!(Drop)),
13550×
        ("NewDrop", schemars::schema_for!(NewDrop)),
13560×
        ("DropEdit", schemars::schema_for!(DropEdit)),
1357
    ]
13580×
}
1359
1360
/// An OxygenFlow runner (`GET /api/v1/runners`, site administrators).
1361
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1362
pub struct Runner {
1363
    pub id: i64,
1364
    pub name: String,
1365
    /// `online`, `offline`, `draining` or `disabled`.
1366
    pub status: String,
1367
    /// What it serves: empty for the whole site, an owner, or `owner/name`.
1368
    pub serves: String,
1369
    pub arch: String,
1370
    pub os: String,
1371
    pub version: String,
1372
    pub labels: Vec<String>,
1373
    pub max_jobs: i64,
1374
    pub memory_mib: Option<i64>,
1375
    pub cpus: Option<i64>,
1376
    /// The key that signs its receipts (KeyId hex), empty until bound.
1377
    pub key: String,
1378
    /// `registered` or `config` (a hub.toml token).
1379
    pub source: String,
1380
    pub last_seen_ms: Option<i64>,
1381
    /// Jobs it is running now.
1382
    pub running: i64,
1383
    /// What it measured at its last claim (oxygenflow#40): free disk in
1384
    /// MiB, the 1-minute load ×100, its speed score (100 on the reference
1385
    /// machine) and class 1–5, its kernel.
1386
    #[serde(default, skip_serializing_if = "Option::is_none")]
1387
    pub free_disk_mib: Option<i64>,
1388
    #[serde(default, skip_serializing_if = "Option::is_none")]
1389
    pub load_x100: Option<i64>,
1390
    #[serde(default, skip_serializing_if = "Option::is_none")]
1391
    pub speed: Option<i64>,
1392
    #[serde(default, skip_serializing_if = "Option::is_none")]
1393
    pub speed_class: Option<i64>,
1394
    #[serde(default, skip_serializing_if = "String::is_empty")]
1395
    pub kernel: String,
1396
}
1397
1398
/// A job a runner ran or is running.
1399
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1400
pub struct RunnerJob {
1401
    pub repo: String,
1402
    pub run: i64,
1403
    pub job: String,
1404
    pub status: String,
1405
    pub started_ms: Option<i64>,
1406
    pub finished_ms: Option<i64>,
1407
}
1408
1409
/// A job in the queue: running ones first, then queued ones in the order
1410
/// runners claim them.
1411
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1412
pub struct QueueItem {
1413
    pub repo: String,
1414
    pub run: i64,
1415
    pub job: String,
1416
    /// `running` or `queued`.
1417
    pub status: String,
1418
    /// The runner holding it, when running.
1419
    pub runner: String,
1420
}
1421
1422
// ------------------------------------------------------------- assistants
1423
1424
/// An AI assistant at a level (hub spec §13.4). The token never leaves the
1425
/// hub: `has_token` says whether one is set.
1426
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1427
pub struct Assistant {
1428
    pub name: String,
1429
    pub endpoint: String,
1430
    pub api: String,
1431
    pub model: String,
1432
    #[serde(default, skip_serializing_if = "String::is_empty")]
1433
    pub headers: String,
1434
    pub enabled: bool,
1435
    pub budget: i64,
1436
    pub has_token: bool,
1437
    /// Where it comes from: empty for the level's own, else `the site` or
1438
    /// `the NAME organisation`.
1439
    #[serde(default, skip_serializing_if = "String::is_empty")]
1440
    pub from: String,
1441
    /// Off because a level above turned a name like it off.
1442
    #[serde(default)]
1443
    pub off_above: bool,
1444
}
1445
1446
/// `POST …/assistants`: add one, or change the one of that name. A
1447
/// `preset` (`anthropic`, `openai`, `gemini`, `deepseek`, `mistral`,
1448
/// `perplexity`, `ollama`) fills what is left out; the model must be one
1449
/// the endpoint lists when it lists any; `token` is write-only.
1450
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1451
pub struct NewAssistant {
1452
    #[serde(default)]
1453
    pub name: String,
1454
    #[serde(default)]
1455
    pub preset: String,
1456
    #[serde(default)]
1457
    pub endpoint: String,
1458
    #[serde(default)]
1459
    pub api: String,
1460
    pub model: String,
1461
    #[serde(default)]
1462
    pub token: String,
1463
    #[serde(default)]
1464
    pub headers: String,
1465
    #[serde(default = "yes")]
1466
    pub enabled: bool,
1467
    #[serde(default)]
1468
    pub budget: Option<i64>,
1469
}
1470
14714×
fn yes() -> bool {
14724×
    true
14734×
}
1474
1475
/// A level's prompt and those it inherits, outermost first.
1476
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1477
pub struct AssistantPrompt {
1478
    pub prompt: String,
1479
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1480
    pub inherited: Vec<(String, String)>,
1481
}
1482
1483
/// `GET /repos/{o}/{n}/coverage`: a coverage report from a Flow job
1484
/// (oxygenhub#113); `percent` values are of lines, functions and branches,
1485
/// absent when nothing was counted.
1486
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1487
pub struct CoverageReport {
1488
    pub id: i64,
1489
    pub run: i64,
1490
    pub job: String,
1491
    pub bookmark: String,
1492
    /// The run's state, by hash.
1493
    pub state: String,
1494
    /// `lcov` or `cobertura`.
1495
    pub format: String,
1496
    pub lines_found: i64,
1497
    pub lines_hit: i64,
1498
    pub percent: Option<f64>,
1499
    pub functions_found: i64,
1500
    pub functions_hit: i64,
1501
    pub branches_found: i64,
1502
    pub branches_hit: i64,
1503
    pub files: i64,
1504
    /// Files the report named that are not in the run's state.
1505
    pub dropped: i64,
1506
    pub created_ms: i64,
1507
    /// The report on the hub's Coverage tab, absolute.
1508
    pub url: String,
1509
    /// Who uploaded it from a workstation (#136), when no Flow job made it;
1510
    /// `run` and `job` are then 0 and "upload".
1511
    #[serde(default, skip_serializing_if = "Option::is_none")]
1512
    pub uploaded_by: Option<String>,
1513
}
1514
1515
/// One file of a coverage report.
1516
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1517
pub struct CoverageFile {
1518
    pub path: String,
1519
    pub lines_found: i64,
1520
    pub lines_hit: i64,
1521
    pub percent: Option<f64>,
1522
    pub functions_found: i64,
1523
    pub functions_hit: i64,
1524
    pub branches_found: i64,
1525
    pub branches_hit: i64,
1526
}
1527
1528
/// `GET /repos/{o}/{n}/coverage/{id}`: a report with its files.
1529
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1530
pub struct CoverageDetail {
1531
    pub report: CoverageReport,
1532
    pub files: Vec<CoverageFile>,
1533
}
1534
1535
/// `GET /repos/{o}/{n}/tests`: a JUnit test report from a Flow job
1536
/// (oxygenhub#114).
1537
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1538
pub struct TestReport {
1539
    pub id: i64,
1540
    pub run: i64,
1541
    pub job: String,
1542
    pub bookmark: String,
1543
    pub state: String,
1544
    pub tests: i64,
1545
    pub passed: i64,
1546
    pub failed: i64,
1547
    pub errors: i64,
1548
    pub skipped: i64,
1549
    /// The cases' times added up.
1550
    pub time_ms: i64,
1551
    pub created_ms: i64,
1552
    pub url: String,
1553
}
1554
1555
/// One test case of a report.
1556
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1557
pub struct TestCase {
1558
    pub suite: String,
1559
    pub classname: String,
1560
    pub name: String,
1561
    /// `passed`, `failed`, `error` or `skipped`.
1562
    pub status: String,
1563
    pub time_ms: i64,
1564
    pub message: String,
1565
    /// A failure's text and output, cut to 16 KiB; empty for a pass.
1566
    pub output: String,
1567
}
1568
1569
/// `GET /repos/{o}/{n}/tests/{id}`: a report with its cases
1570
/// (`?status=failed` for the failed and errored ones).
1571
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1572
pub struct TestReportDetail {
1573
    pub report: TestReport,
1574
    pub cases: Vec<TestCase>,
1575
}
1576
1577
/// `GET /api/v1/admin/runner-updates` (oxygenhub#322): where runner builds
1578
/// come from, every level's settings, the test groups, each runner's policy
1579
/// and what it is offered, and the builds held back (#326). Site
1580
/// administrators only.
1581
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1582
pub struct RunnerUpdates {
1583
    /// The repository whose releases carry runner builds (`owner/name`).
1584
    pub repo: String,
1585
    pub settings: Vec<UpdateSetting>,
1586
    pub groups: Vec<RunnerGroup>,
1587
    pub runners: Vec<RunnerUpdate>,
1588
    pub holds: Vec<HeldBuild>,
1589
}
1590
1591
/// One level's update settings; `None` inherits from the next level out.
1592
/// `PUT /api/v1/admin/runner-updates/settings` takes one.
1593
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1594
pub struct UpdateSetting {
1595
    /// `site`, `owner`, `group` or `runner`.
1596
    pub scope: String,
1597
    /// Empty for the site; the owner's name, the group's id, the runner's id.
1598
    #[serde(default)]
1599
    pub key: String,
1600
    #[serde(default)]
1601
    pub updates: Option<bool>,
1602
    /// `stable`, `canary` or a version.
1603
    #[serde(default)]
1604
    pub channel: Option<String>,
1605
    /// Hours (UTC) in which updates may start, `02-05`.
1606
    #[serde(default)]
1607
    pub window: Option<String>,
1608
    #[serde(default)]
1609
    pub dry_run: Option<bool>,
1610
}
1611
1612
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1613
pub struct RunnerGroup {
1614
    pub id: i64,
1615
    /// Empty for a group of the site's runners.
1616
    pub owner: String,
1617
    pub name: String,
1618
    /// A share of the runners in reach; `None`: chosen ones.
1619
    pub percent: Option<i64>,
1620
    /// Its runners now, by name.
1621
    pub members: Vec<String>,
1622
}
1623
1624
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1625
pub struct RunnerUpdate {
1626
    pub id: i64,
1627
    pub name: String,
1628
    /// The owner it serves; empty for the site's.
1629
    pub owner: String,
1630
    pub version: String,
1631
    pub groups: Vec<String>,
1632
    pub updates: bool,
1633
    pub channel: String,
1634
    #[serde(default)]
1635
    pub window: Option<String>,
1636
    pub dry_run: bool,
1637
    /// Where each setting came from, in the order updates, channel, window, dry run.
1638
    pub from: Vec<String>,
1639
    /// What the hub would offer it now, in words.
1640
    pub now: String,
1641
    /// What it last said about its update.
1642
    pub said: String,
1643
}
1644
1645
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1646
pub struct HeldBuild {
1647
    pub version: String,
1648
    pub runner: String,
1649
    pub why: String,
1650
    pub at_ms: i64,
1651
}