OXYGENHUB

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

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