OXYGENHUB
◆ v0.7.0 oxygenhub / crates / hub-api / src / lib.rs
45.1 KiB · Rust · last changed Drops: per-user gists, each a small hidden Oxygen repository (#279) 15 days ago source blame history raw
8d2caf12 Andy McCall ↶ 1
//! Types of the OxygenHub JSON API (hub spec §12.1). Everything here is
d23464c0 Andy McCall ↶ 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
b64e2537 Andy McCall ↶ 9
use schemars::JsonSchema;
d23464c0 Andy McCall ↶ 10
use serde::{Deserialize, Serialize};
11
12
/// A repository as the API lists it.
b64e2537 Andy McCall ↶ 13
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 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
b64e2537 Andy McCall ↶ 27
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 28
#[serde(rename_all = "lowercase")]
29
pub enum Visibility {
30
    Public,
31
    Internal,
32
    Private,
33
}
34
35
impl Visibility {
36
    pub fn as_str(self) -> &'static str {
37
        match self {
38
            Visibility::Public => "public",
39
            Visibility::Internal => "internal",
40
            Visibility::Private => "private",
41
        }
42
    }
43
44
    pub fn parse(s: &str) -> Option<Visibility> {
45
        Some(match s {
46
            "public" => Visibility::Public,
47
            "internal" => Visibility::Internal,
48
            "private" => Visibility::Private,
49
            _ => return None,
50
        })
51
    }
52
}
53
54
/// A bookmark: a name for a set of heads (spec §10.1).
b64e2537 Andy McCall ↶ 55
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 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.
b64e2537 Andy McCall ↶ 65
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 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.
b64e2537 Andy McCall ↶ 74
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 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,
8933faff Andy McCall ↶ 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,
d23464c0 Andy McCall ↶ 98
}
99
100
/// Who wrote a change: the linked account when the signing key is linked,
101
/// else the key alone.
b64e2537 Andy McCall ↶ 102
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 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>,
760a7dd3 Andy McCall ↶ 109
    /// Set when the change is signed by a key no account has linked, and
110
    /// says how its owner links it.
111
    #[serde(default, skip_serializing_if = "Option::is_none")]
112
    pub note: Option<String>,
113
}
114
115
impl Author {
116
    /// What `note` says for a key that no account has linked.
117
    pub const UNLINKED: &'static str =
118
        "signed by a key not linked to any account; its owner links it under Settings → Keys (/settings/keys)";
119
120
    /// The note for an author with this key and account.
121
    pub fn note_for(key: &str, account: &Option<String>) -> Option<String> {
122
        (!key.is_empty() && account.is_none()).then(|| Self::UNLINKED.to_string())
123
    }
d23464c0 Andy McCall ↶ 124
}
125
126
/// Signature status of a change as `oxy verify` reports it.
b64e2537 Andy McCall ↶ 127
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 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.
b64e2537 Andy McCall ↶ 136
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
d23464c0 Andy McCall ↶ 137
pub struct Problem {
138
    pub status: u16,
139
    pub title: String,
140
    pub detail: String,
141
}
142
143
#[cfg(test)]
144
mod tests {
145
    use super::*;
146
147
    #[test]
148
    fn visibility_round_trips() {
149
        for v in [Visibility::Public, Visibility::Internal, Visibility::Private] {
150
            assert_eq!(Visibility::parse(v.as_str()), Some(v));
151
        }
152
        assert_eq!(Visibility::parse("secret"), None);
153
    }
154
}
de505df5 Andy McCall ↶ 155
156
// ---------------------------------------------------------------- proposals
157
158
/// A proposal: a request to add changes to a target bookmark (hub spec §7).
b64e2537 Andy McCall ↶ 159
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
de505df5 Andy McCall ↶ 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>,
0b20f1ec Andy McCall ↶ 185
    /// Who landed it, how and when, once landed.
186
    #[serde(default)]
187
    pub landed: Option<Landed>,
86a69b53 Andy McCall ↶ 188
    /// Who set it to land when its checks pass (oxygenhub#261), while set.
189
    #[serde(default)]
190
    pub auto_land: Option<String>,
cc1cd197 Andy McCall ↶ 191
    /// Asked to review and not yet reviewing, in the order asked.
192
    #[serde(default)]
193
    pub requested_reviewers: Vec<String>,
2291f8cc Andy McCall ↶ 194
    #[serde(default)]
195
    pub labels: Vec<Label>,
0b20f1ec Andy McCall ↶ 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,
de505df5 Andy McCall ↶ 205
}
206
b64e2537 Andy McCall ↶ 207
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
de505df5 Andy McCall ↶ 208
#[serde(rename_all = "lowercase")]
209
pub enum ProposalState {
210
    Draft,
211
    Open,
212
    Landed,
213
    Closed,
214
}
215
216
impl ProposalState {
217
    pub fn as_str(self) -> &'static str {
218
        match self {
219
            ProposalState::Draft => "draft",
220
            ProposalState::Open => "open",
221
            ProposalState::Landed => "landed",
222
            ProposalState::Closed => "closed",
223
        }
224
    }
225
226
    pub fn parse(s: &str) -> Option<ProposalState> {
227
        Some(match s {
228
            "draft" => ProposalState::Draft,
229
            "open" => ProposalState::Open,
230
            "landed" => ProposalState::Landed,
231
            "closed" => ProposalState::Closed,
232
            _ => return None,
233
        })
234
    }
235
}
236
b64e2537 Andy McCall ↶ 237
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
de505df5 Andy McCall ↶ 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.
b64e2537 Andy McCall ↶ 250
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
de505df5 Andy McCall ↶ 251
pub struct Approval {
252
    pub account: String,
253
    pub sealed: bool,
254
    pub key: Option<String>,
255
}
b64e2537 Andy McCall ↶ 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
5ea4872f Andy McCall ↶ 296
/// `POST /repos/{o}/{n}/milestones`: create a milestone, or change the
297
/// description and due date of the one with that title (triage).
b64e2537 Andy McCall ↶ 298
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
5ea4872f Andy McCall ↶ 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)]
b64e2537 Andy McCall ↶ 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>,
c0fac31d Andy McCall ↶ 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>,
b64e2537 Andy McCall ↶ 337
    pub resolved: bool,
338
}
339
42a0ba4b Andy McCall ↶ 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
}
353
354
/// `GET /notifications`: the unread count and the newest entries, unread first.
355
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
356
pub struct Inbox {
357
    pub unread: i64,
358
    pub items: Vec<Notification>,
359
}
360
3f02e5ea Andy McCall ↶ 361
/// A file a proposal changes, between the target's state and the
362
/// projected state (hub spec §7.2). Fetch either side's bytes from
363
/// `/proposals/{number}/content/{base|head}/{path}`.
b64e2537 Andy McCall ↶ 364
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
3f02e5ea Andy McCall ↶ 365
pub struct ProposalFile {
366
    pub path: String,
367
    /// For a rename, the path in the target's state.
368
    pub from: Option<String>,
369
    /// `added`, `removed`, `modified`, `renamed`, `mode` or `replaced`.
370
    pub kind: String,
371
    pub added: usize,
372
    pub removed: usize,
373
}
374
375
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
b64e2537 Andy McCall ↶ 376
pub struct Atom {
377
    pub change: String,
378
    pub index: u32,
379
}
380
381
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
382
pub struct Review {
383
    pub id: i64,
384
    pub author: String,
385
    pub verdict: String,
386
    pub body: String,
387
    pub sealed: bool,
388
    pub created_ms: i64,
7d2eb590 Andy McCall ↶ 389
    /// The AI assistant that answered for `author`, empty for a person's
390
    /// own review (hub spec §13.4).
391
    #[serde(default, skip_serializing_if = "String::is_empty")]
392
    pub via: String,
b64e2537 Andy McCall ↶ 393
}
394
395
// ------------------------------------------------------------- repository
396
397
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
398
pub struct TreeEntry {
399
    pub name: String,
400
    pub path: String,
401
    pub kind: String,
402
    pub exec: bool,
403
    pub size: Option<u64>,
404
    pub conflicted: bool,
405
}
406
407
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
408
pub struct BlameLine {
409
    pub line: usize,
410
    pub change: String,
411
    pub index: u32,
412
    pub author: String,
413
    pub when_ms: u64,
414
    pub text: String,
415
}
416
417
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
418
pub struct FileChange {
419
    pub path: String,
420
    pub kind: String,
421
    pub from: Option<String>,
422
    pub added: usize,
423
    pub removed: usize,
424
}
425
426
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
427
pub struct ChangeDetail {
428
    pub change: ChangeSummary,
429
    pub body: String,
430
    pub dependents: Vec<String>,
431
    pub in_bookmarks: Vec<String>,
432
    pub in_tags: Vec<String>,
433
    pub files: Vec<FileChange>,
434
}
435
436
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
437
pub struct History {
438
    pub reference: String,
439
    pub heads: Vec<String>,
440
    pub total: usize,
441
    pub offset: usize,
442
    pub changes: Vec<ChangeSummary>,
443
}
444
445
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
446
pub struct Conflict {
447
    pub bookmark: String,
448
    pub path: String,
449
    pub kind: String,
450
    pub contributors: Vec<String>,
451
}
452
453
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
454
pub struct Push {
455
    pub at_ms: i64,
456
    pub pusher: String,
457
    pub reference: String,
458
    pub ok: bool,
459
    pub reason: String,
460
    pub old_state: String,
461
    pub new_state: String,
462
    pub heads: i64,
463
    pub changes: i64,
464
}
465
466
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
467
pub struct Trust {
468
    pub policy: Option<Policy>,
469
    pub signed: usize,
470
    pub sealed: usize,
471
    pub unsigned: usize,
472
    pub invalid: Vec<String>,
473
    pub hub_key: String,
474
}
475
476
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
477
pub struct Policy {
478
    pub serial: u64,
479
    pub expires_ms: u64,
480
    pub roots: Vec<String>,
481
    pub root_threshold: u32,
482
    pub rules: Vec<Rule>,
483
}
484
485
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
486
pub struct Rule {
487
    pub pattern: String,
488
    pub keys: Vec<String>,
489
    pub threshold: u32,
490
    pub require: String,
491
    pub allow_conflicts: bool,
492
}
493
494
// ---------------------------------------------------------- hooks, checks
495
496
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
497
pub struct Hook {
498
    pub id: i64,
499
    pub url: String,
500
    pub events: String,
501
    pub active: bool,
502
    pub created_ms: i64,
503
}
504
505
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
506
pub struct NewHook {
507
    pub url: String,
508
    pub secret: String,
509
    #[serde(default = "star")]
510
    pub events: String,
511
}
512
513
fn star() -> String {
514
    "*".into()
515
}
516
90326c96 Andy McCall ↶ 517
/// An OxygenFlow run (hub spec §13.2).
518
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
519
pub struct FlowRun {
520
    /// The run's number within its repository.
521
    pub number: i64,
522
    pub bookmark: String,
523
    /// The state's hash, as checks are keyed.
524
    pub state: String,
525
    /// Its heads, full change hashes.
526
    pub heads: Vec<String>,
527
    /// `queued`, `running`, `passed`, `failed` or `error` (an invalid pipeline).
528
    pub status: String,
529
    /// `push`, `manual` or `rerun:N`.
530
    pub trigger: String,
531
    pub actor: String,
532
    pub pipeline_hash: String,
533
    /// An invalid pipeline's problems.
534
    pub error: String,
535
    pub created_ms: i64,
536
    pub finished_ms: Option<i64>,
537
    pub url: String,
bf3d0754 Andy McCall ↶ 538
    /// For a run waiting for a runner, its first queued job's 1-based
539
    /// place among all queued jobs.
540
    #[serde(default, skip_serializing_if = "Option::is_none")]
541
    pub queue_position: Option<i64>,
90326c96 Andy McCall ↶ 542
    /// Filled by the single-run endpoint.
543
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
544
    pub jobs: Vec<FlowJob>,
545
}
546
547
/// A job of a run.
548
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
549
pub struct FlowJob {
550
    pub name: String,
551
    /// `queued`, `running`, `passed`, `failed`, `skipped` or `error`.
552
    pub status: String,
553
    pub depends_on: Vec<String>,
554
    pub runner: String,
555
    pub exit_code: Option<i64>,
556
    pub error: String,
557
    pub started_ms: Option<i64>,
558
    pub finished_ms: Option<i64>,
559
    /// Log lines stored so far.
560
    pub log_lines: i64,
4d2e44d7 Andy McCall ↶ 561
    /// Why a queued job no runner can take waits (OxygenFlow spec §11.4);
562
    /// empty when it only waits its turn.
563
    #[serde(default, skip_serializing_if = "String::is_empty")]
564
    pub waiting: String,
501d8b26 Andy McCall ↶ 565
    /// Why it ran on its runner (oxygenflow#42): "holds the image, idle,
566
    /// speed 100 (class 3)".
567
    #[serde(default, skip_serializing_if = "String::is_empty")]
568
    pub placed: String,
90326c96 Andy McCall ↶ 569
}
570
571
/// A line of a job's log.
572
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
573
pub struct FlowLogLine {
574
    /// Increasing within the job; pass the last one as `after` for more.
575
    pub seq: i64,
576
    /// Milliseconds since the job started.
577
    pub t: i64,
578
    /// `stdout`, `stderr` or `flow` (the runner's own notes).
579
    pub stream: String,
580
    pub text: String,
581
}
582
b64e2537 Andy McCall ↶ 583
/// A check on a state hash (hub spec §13.1).
584
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
585
pub struct Check {
586
    pub state: String,
587
    pub name: String,
588
    pub status: CheckStatus,
589
    pub summary: String,
590
    pub url: String,
591
    pub reporter: String,
592
    /// The seal attestation's reference when the checker sealed the changes.
593
    pub seal: Option<String>,
594
    pub started_ms: i64,
595
    pub finished_ms: Option<i64>,
596
}
597
598
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
599
#[serde(rename_all = "lowercase")]
600
pub enum CheckStatus {
601
    Queued,
602
    Running,
603
    Passed,
604
    Failed,
605
    Cancelled,
606
    Skipped,
607
}
608
609
impl CheckStatus {
610
    pub fn as_str(self) -> &'static str {
611
        match self {
612
            CheckStatus::Queued => "queued",
613
            CheckStatus::Running => "running",
614
            CheckStatus::Passed => "passed",
615
            CheckStatus::Failed => "failed",
616
            CheckStatus::Cancelled => "cancelled",
617
            CheckStatus::Skipped => "skipped",
618
        }
619
    }
620
621
    pub fn parse(s: &str) -> Option<CheckStatus> {
622
        Some(match s {
623
            "queued" => CheckStatus::Queued,
624
            "running" => CheckStatus::Running,
625
            "passed" => CheckStatus::Passed,
626
            "failed" => CheckStatus::Failed,
627
            "cancelled" => CheckStatus::Cancelled,
628
            "skipped" => CheckStatus::Skipped,
629
            _ => return None,
630
        })
631
    }
632
}
633
634
/// What a checker posts.
635
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
636
pub struct NewCheck {
637
    pub state: String,
638
    pub name: String,
639
    pub status: CheckStatus,
640
    #[serde(default)]
641
    pub summary: String,
642
    #[serde(default)]
643
    pub url: String,
644
    /// Hex of a seal attestation reference the checker pushed, if any.
645
    #[serde(default)]
646
    pub seal: Option<String>,
647
}
648
649
// ------------------------------------------------------------- accounts
650
651
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
652
pub struct User {
653
    pub username: String,
654
    pub display_name: String,
655
    pub is_admin: bool,
656
    pub keys: Vec<String>,
657
    pub created_ms: i64,
658
}
659
660
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
661
pub struct Organisation {
662
    pub name: String,
663
    pub display_name: String,
664
    pub description: String,
665
    pub members: Vec<String>,
666
}
667
668
/// Forms accepted by the write endpoints.
669
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
670
pub struct NewRepository {
671
    pub owner: String,
672
    pub name: String,
673
    #[serde(default)]
674
    pub description: String,
675
    #[serde(default = "public")]
676
    pub visibility: Visibility,
677
}
678
679
fn public() -> Visibility {
680
    Visibility::Public
681
}
682
683
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
684
pub struct NewIssue {
685
    pub title: String,
686
    #[serde(default)]
687
    pub body: String,
76f262e1 Andy McCall ↶ 688
    /// Label names; each must exist. Needs triage.
689
    #[serde(default)]
690
    pub labels: Vec<String>,
691
    /// Usernames. Needs triage.
692
    #[serde(default)]
693
    pub assignees: Vec<String>,
694
    /// A milestone's title. Needs triage.
695
    #[serde(default)]
696
    pub milestone: Option<String>,
b64e2537 Andy McCall ↶ 697
}
698
76f262e1 Andy McCall ↶ 699
/// `PATCH /repos/{o}/{n}/issues/{number}`: only the fields given change.
700
/// Title and body: the author or triage. The rest: triage.
701
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
702
pub struct IssueEdit {
703
    #[serde(default)]
704
    pub title: Option<String>,
705
    #[serde(default)]
706
    pub body: Option<String>,
707
    /// The whole set of labels.
708
    #[serde(default)]
709
    pub labels: Option<Vec<String>>,
710
    /// The whole set of assignees.
711
    #[serde(default)]
712
    pub assignees: Option<Vec<String>>,
713
    /// A milestone's title; the empty string clears it.
714
    #[serde(default)]
715
    pub milestone: Option<String>,
716
}
717
961c10be Andy McCall ↶ 718
/// The checks a proposal needs, passed, to land on the repository's
719
/// default bookmark (hub spec §13.1). `GET` and `PUT
720
/// /repos/{o}/{n}/checks/required`.
721
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
722
pub struct RequiredChecks {
723
    pub names: Vec<String>,
724
}
725
ef20fdc1 Andy McCall ↶ 726
/// A project (hub spec §8.2).
727
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
728
pub struct Project {
729
    pub owner: String,
730
    pub number: i64,
731
    pub title: String,
732
    pub description: String,
733
    pub public: bool,
734
    pub closed: bool,
735
    pub updated_ms: i64,
736
    /// The board on the hub, absolute.
737
    pub url: String,
738
}
739
740
/// A card as the caller may see it.
741
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
742
pub struct ProjectCard {
743
    pub id: i64,
744
    /// `issue`, `proposal` or `note`.
745
    pub kind: String,
746
    /// `owner/name#N`; empty for a note.
747
    pub reference: String,
748
    /// The issue's or proposal's title, or the note.
749
    pub title: String,
750
    /// The issue's or proposal's state; empty for a note.
751
    pub state: String,
752
}
753
754
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
755
pub struct ProjectColumn {
756
    pub id: i64,
757
    pub name: String,
758
    pub cards: Vec<ProjectCard>,
759
}
760
761
/// `GET /projects/{owner}/{n}`.
762
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
763
pub struct Board {
764
    pub project: Project,
765
    pub columns: Vec<ProjectColumn>,
766
}
767
768
/// `POST /projects/{owner}`.
769
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
770
pub struct NewProject {
771
    pub title: String,
772
    #[serde(default)]
773
    pub description: String,
774
    #[serde(default)]
775
    pub private: bool,
776
}
777
778
/// `PATCH /projects/{owner}/{n}`: only the fields given change.
779
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
780
pub struct ProjectEdit {
b1e92a62 Andy McCall ↶ 781
    /// Transfer the board to this owner (#125): one the caller may make
782
    /// boards under. It takes the next number there.
783
    #[serde(default, skip_serializing_if = "Option::is_none")]
784
    pub owner: Option<String>,
ef20fdc1 Andy McCall ↶ 785
    #[serde(default)]
786
    pub title: Option<String>,
787
    #[serde(default)]
788
    pub description: Option<String>,
789
    #[serde(default)]
790
    pub private: Option<bool>,
791
    #[serde(default)]
792
    pub closed: Option<bool>,
793
}
794
795
/// `POST /projects/{owner}/{n}/cards`: a reference (`repo#12`) or a note,
796
/// into the column named (by id or name; the first column when absent).
797
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
798
pub struct NewCard {
799
    #[serde(default)]
800
    pub column: Option<String>,
801
    #[serde(default)]
802
    pub reference: String,
803
    #[serde(default)]
804
    pub note: String,
805
}
806
807
/// `PATCH /projects/{owner}/{n}/cards/{id}`: move to a column (id or name).
808
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
809
pub struct CardMove {
810
    pub column: String,
811
}
812
76f262e1 Andy McCall ↶ 813
/// `POST /repos/{o}/{n}/labels`: create a label, or change one of that name.
814
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
815
pub struct NewLabel {
816
    pub name: String,
817
    /// `#rrggbb`; a default when absent.
818
    #[serde(default)]
819
    pub colour: Option<String>,
820
    #[serde(default)]
821
    pub description: String,
822
}
823
b64e2537 Andy McCall ↶ 824
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
825
pub struct NewComment {
826
    pub body: String,
3f4b0ea6 Andy McCall ↶ 827
    /// For a proposal: anchor the comment to this file's line (1-based) of
828
    /// the projected state; the hub records the line's atom.
829
    #[serde(default)]
830
    pub path: Option<String>,
831
    #[serde(default)]
832
    pub line: Option<usize>,
b64e2537 Andy McCall ↶ 833
}
834
835
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
836
pub struct NewProposal {
837
    pub title: String,
838
    #[serde(default)]
839
    pub body: String,
840
    pub target: String,
841
    /// A bookmark here, or `owner/name:bookmark` of a fork.
842
    pub source: String,
843
    #[serde(default)]
844
    pub draft: bool,
cc1cd197 Andy McCall ↶ 845
}
846
847
/// `POST .../proposals/{number}/reviewers`: accounts to ask for a review.
848
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
849
pub struct ReviewRequest {
850
    pub reviewers: Vec<String>,
7d2eb590 Andy McCall ↶ 851
}
852
853
/// `POST .../proposals/{number}/review-requests`: ask an AI assistant the
854
/// repository may use (hub spec §13.4) to review; it answers as a `comment`
855
/// review via the assistant.
856
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
857
pub struct AssistantRequest {
858
    pub assistant: String,
b64e2537 Andy McCall ↶ 859
}
860
861
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
862
pub struct NewReview {
863
    pub verdict: String,
864
    #[serde(default)]
865
    pub body: String,
866
}
867
868
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
869
pub struct IssueStateChange {
870
    /// `open` or `closed`.
871
    pub state: String,
872
    #[serde(default)]
873
    pub reason: String,
874
}
875
876
/// A webhook payload's envelope (hub spec §12.2).
877
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
878
pub struct WebhookEnvelope {
879
    pub event: String,
880
    pub delivery: String,
881
    pub repository: Option<Repository>,
882
    pub actor: String,
883
    pub at_ms: i64,
884
    pub data: serde_json::Value,
885
}
886
887
/// A server-sent event on a proposal's stream.
888
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
889
pub struct ProposalEvent {
890
    pub number: i64,
891
    pub kind: String,
892
    pub check: Option<Check>,
893
}
894
3f4b0ea6 Andy McCall ↶ 895
// --------------------------------------------------------------- releases
896
897
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
898
pub struct Release {
899
    pub tag: String,
900
    pub title: String,
901
    pub notes: String,
902
    pub prerelease: bool,
903
    pub latest: bool,
904
    pub author: String,
905
    pub heads: Vec<String>,
906
    pub signer: Option<String>,
907
    pub assets: Vec<ReleaseAsset>,
908
    pub archives: Vec<String>,
909
    pub created_ms: i64,
910
    pub url: String,
911
}
912
913
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
914
pub struct ReleaseAsset {
915
    pub name: String,
916
    pub size: i64,
917
    /// BLAKE3 of the content, hex.
918
    pub hash: String,
919
    pub content_type: String,
920
    pub downloads: i64,
921
    pub url: String,
10708ab8 Andy McCall ↶ 922
    /// The OxygenFlow run and job whose artifact has this content, if any.
923
    #[serde(default, skip_serializing_if = "Option::is_none")]
924
    pub built_by: Option<AssetBuild>,
925
}
926
927
/// Where a release asset was built (hub spec §9): a job's artifact with the
928
/// same BLAKE3, and that job's signed receipt when one was kept.
929
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
930
pub struct AssetBuild {
931
    pub run: i64,
932
    pub job: String,
933
    pub artifact: String,
934
    pub run_url: String,
935
    /// The receipt attestation, hex; `None` when the receipt was not signed.
936
    pub receipt: Option<String>,
937
    pub receipt_url: Option<String>,
938
    pub signer: Option<String>,
97fc47fe Andy McCall ↶ 939
    /// The asset's SLSA provenance, signed by the hub (oxygenhub#239):
940
    /// `cosign verify-blob-attestation --key …/.well-known/oxyhub-signing.pem
d2c1d6a7 Andy McCall ↶ 941
    /// --type slsaprovenance1 --insecure-ignore-tlog=true --signature PROVENANCE ASSET`. `None` when the
97fc47fe Andy McCall ↶ 942
    /// receipt was not signed.
943
    #[serde(default)]
944
    pub provenance_url: Option<String>,
3f4b0ea6 Andy McCall ↶ 945
}
946
739a763a Andy McCall ↶ 947
/// `PATCH /repos/{o}/{n}/proposals/{number}`: what is given changes,
948
/// the rest stays (oxygenhub#76).
949
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
950
pub struct ProposalEdit {
951
    #[serde(default, skip_serializing_if = "Option::is_none")]
952
    pub title: Option<String>,
953
    #[serde(default, skip_serializing_if = "Option::is_none")]
954
    pub body: Option<String>,
2291f8cc Andy McCall ↶ 955
    /// The whole set of labels, by name (triage); oxygenhub#80.
956
    #[serde(default, skip_serializing_if = "Option::is_none")]
957
    pub labels: Option<Vec<String>>,
71e65fcf Andy McCall ↶ 958
    /// `closed` or `open` (reopen), by its author or with triage access,
959
    /// as the page's Close and Reopen do (oxygenhub#140).
960
    #[serde(default, skip_serializing_if = "Option::is_none")]
961
    pub state: Option<String>,
739a763a Andy McCall ↶ 962
}
963
ced6d3af Andy McCall ↶ 964
/// `PATCH /repos/{owner}/{name}/releases/{tag}`: what to change; fields
965
/// left out stay as they are.
966
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
967
pub struct ReleaseEdit {
968
    #[serde(default, skip_serializing_if = "Option::is_none")]
969
    pub title: Option<String>,
970
    #[serde(default, skip_serializing_if = "Option::is_none")]
971
    pub notes: Option<String>,
972
    #[serde(default, skip_serializing_if = "Option::is_none")]
973
    pub prerelease: Option<bool>,
974
}
975
166f6e9b Andy McCall 976
/// A drop (oxygenhub#279): a small snippet of one or more files, its own
977
/// Oxygen repository, never listed among repositories. `GET /drops` lists
978
/// yours, `GET /users/{name}/drops` someone's public ones, and
979
/// `GET /drops/{id}` one with its files' content.
3f4b0ea6 Andy McCall ↶ 980
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
166f6e9b Andy McCall 981
pub struct Drop {
982
    /// 24 hex digits, unique on the hub.
983
    pub id: String,
984
    pub owner: String,
985
    pub title: String,
986
    pub description: String,
987
    /// `public` (listed on its owner's Drops page) or `secret` (unlisted:
988
    /// readable by anyone with its address).
989
    pub visibility: String,
990
    /// The drop's page.
991
    pub url: String,
992
    /// What `oxy clone` takes.
993
    pub clone_url: String,
994
    pub created_ms: i64,
995
    pub updated_ms: i64,
996
    pub files: Vec<DropFile>,
997
}
998
999
/// One of a drop's files. Lists carry no content; one drop's view carries
1000
/// the content of each text file up to 512 KiB.
1001
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1002
pub struct DropFile {
1003
    pub name: String,
1004
    pub size: u64,
1005
    #[serde(default, skip_serializing_if = "Option::is_none")]
1006
    pub content: Option<String>,
1007
    /// The file's bytes on the default bookmark.
1008
    pub raw_url: String,
1009
}
1010
1011
/// `POST /drops`: a new drop with at least one file.
1012
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1013
pub struct NewDrop {
1014
    #[serde(default)]
1015
    pub title: String,
1016
    #[serde(default)]
1017
    pub description: String,
1018
    /// Unlisted, readable by anyone with its address.
1019
    #[serde(default)]
1020
    pub secret: bool,
1021
    pub files: Vec<NewDropFile>,
1022
}
1023
1024
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1025
pub struct NewDropFile {
1026
    pub name: String,
1027
    pub content: String,
1028
}
1029
1030
/// `PATCH /drops/{id}`: what to change; what is left out stays.
1031
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1032
pub struct DropEdit {
1033
    #[serde(default, skip_serializing_if = "Option::is_none")]
1034
    pub title: Option<String>,
1035
    #[serde(default, skip_serializing_if = "Option::is_none")]
1036
    pub description: Option<String>,
1037
    #[serde(default, skip_serializing_if = "Option::is_none")]
1038
    pub secret: Option<bool>,
1039
    /// Files to write, or to remove (`content` null); others are kept.
1040
    #[serde(default)]
1041
    pub files: Vec<DropFileEdit>,
1042
    /// The change's message (default "Edit TITLE").
1043
    #[serde(default, skip_serializing_if = "Option::is_none")]
1044
    pub message: Option<String>,
1045
}
1046
1047
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1048
pub struct DropFileEdit {
1049
    pub name: String,
1050
    #[serde(default)]
1051
    pub content: Option<String>,
1052
}
1053
1054
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
3f4b0ea6 Andy McCall ↶ 1055
pub struct NewRelease {
1056
    pub tag: String,
1057
    pub title: String,
1058
    #[serde(default)]
1059
    pub notes: Option<String>,
1060
    #[serde(default)]
1061
    pub prerelease: bool,
1062
}
1063
eb2a3502 Andy McCall ↶ 1064
/// `GET /repos/{o}/{n}/diffusion` (oxygenhub#153): what a repository
1065
/// takes from (the subrepos it pins) and what it diffuses to (the
1066
/// repositories that pin it), each as the Diffusion pages show it.
1067
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1068
pub struct Diffusion {
1069
    pub takes_from: Vec<DiffusionPin>,
1070
    pub diffuses_to: Vec<DiffusionPin>,
1071
}
1072
1073
/// One pin of an upstream by a consumer, both named `owner/name`.
1074
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1075
pub struct DiffusionPin {
1076
    pub upstream: String,
1077
    pub consumer: String,
1078
    /// Where the consumer pins it.
1079
    pub path: String,
1080
    /// The consumer's bookmark its bumps land on.
1081
    pub bookmark: String,
1082
    /// Upstream changes the pin lacks; absent when the hub cannot tell.
1083
    #[serde(default)]
1084
    pub behind: Option<u64>,
1085
    /// `off`, `green` or `any`.
1086
    pub follow: String,
1087
    /// The open bump proposal's number, on the consumer.
1088
    #[serde(default)]
1089
    pub bump: Option<i64>,
1090
    /// The newest run of the bump: number and status.
1091
    #[serde(default)]
1092
    pub run: Option<i64>,
1093
    #[serde(default)]
1094
    pub run_status: Option<String>,
1095
    /// The pill: the upstream's half, then the consumer's.
1096
    pub upstream_state: DiffusionHalf,
1097
    pub consumer_state: DiffusionHalf,
1098
}
1099
1100
/// One half of the Diffusion pill.
1101
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1102
pub struct DiffusionHalf {
1103
    /// `green`, `amber`, `red`, `grey` or `off`.
1104
    pub tone: String,
1105
    /// What the pill says: `checked`, `untested`, `passes`, `up to date`…
1106
    pub word: String,
1107
    /// The sentence behind it.
1108
    pub title: String,
1109
}
1110
b64e2537 Andy McCall ↶ 1111
/// Every type of the API, for schema generation.
1112
pub fn schemas() -> Vec<(&'static str, schemars::Schema)> {
1113
    vec![
1114
        ("Repository", schemars::schema_for!(Repository)),
eb2a3502 Andy McCall ↶ 1115
        ("Diffusion", schemars::schema_for!(Diffusion)),
1116
        ("DiffusionPin", schemars::schema_for!(DiffusionPin)),
1117
        ("DiffusionHalf", schemars::schema_for!(DiffusionHalf)),
b64e2537 Andy McCall ↶ 1118
        ("Visibility", schemars::schema_for!(Visibility)),
1119
        ("Bookmark", schemars::schema_for!(Bookmark)),
1120
        ("Tag", schemars::schema_for!(Tag)),
1121
        ("ChangeSummary", schemars::schema_for!(ChangeSummary)),
1122
        ("Author", schemars::schema_for!(Author)),
1123
        ("Signature", schemars::schema_for!(Signature)),
1124
        ("Problem", schemars::schema_for!(Problem)),
1125
        ("Proposal", schemars::schema_for!(Proposal)),
1126
        ("ProposalState", schemars::schema_for!(ProposalState)),
1127
        ("ProposalSource", schemars::schema_for!(ProposalSource)),
1128
        ("Approval", schemars::schema_for!(Approval)),
1129
        ("Issue", schemars::schema_for!(Issue)),
1130
        ("Label", schemars::schema_for!(Label)),
1131
        ("Milestone", schemars::schema_for!(Milestone)),
5ea4872f Andy McCall ↶ 1132
        ("NewMilestone", schemars::schema_for!(NewMilestone)),
1133
        ("MilestoneEdit", schemars::schema_for!(MilestoneEdit)),
b64e2537 Andy McCall ↶ 1134
        ("Comment", schemars::schema_for!(Comment)),
3f02e5ea Andy McCall ↶ 1135
        ("ProposalFile", schemars::schema_for!(ProposalFile)),
42a0ba4b Andy McCall ↶ 1136
        ("Notification", schemars::schema_for!(Notification)),
1137
        ("Inbox", schemars::schema_for!(Inbox)),
b64e2537 Andy McCall ↶ 1138
        ("Atom", schemars::schema_for!(Atom)),
1139
        ("Review", schemars::schema_for!(Review)),
1140
        ("TreeEntry", schemars::schema_for!(TreeEntry)),
1141
        ("BlameLine", schemars::schema_for!(BlameLine)),
1142
        ("FileChange", schemars::schema_for!(FileChange)),
1143
        ("ChangeDetail", schemars::schema_for!(ChangeDetail)),
1144
        ("History", schemars::schema_for!(History)),
1145
        ("Conflict", schemars::schema_for!(Conflict)),
1146
        ("Push", schemars::schema_for!(Push)),
1147
        ("Trust", schemars::schema_for!(Trust)),
1148
        ("Policy", schemars::schema_for!(Policy)),
1149
        ("Rule", schemars::schema_for!(Rule)),
1150
        ("Hook", schemars::schema_for!(Hook)),
1151
        ("NewHook", schemars::schema_for!(NewHook)),
1152
        ("Check", schemars::schema_for!(Check)),
1153
        ("CheckStatus", schemars::schema_for!(CheckStatus)),
1154
        ("NewCheck", schemars::schema_for!(NewCheck)),
1155
        ("User", schemars::schema_for!(User)),
1156
        ("Organisation", schemars::schema_for!(Organisation)),
1157
        ("NewRepository", schemars::schema_for!(NewRepository)),
1158
        ("NewIssue", schemars::schema_for!(NewIssue)),
76f262e1 Andy McCall ↶ 1159
        ("IssueEdit", schemars::schema_for!(IssueEdit)),
2291f8cc Andy McCall ↶ 1160
        ("ReleaseEdit", schemars::schema_for!(ReleaseEdit)),
1161
        ("ProposalEdit", schemars::schema_for!(ProposalEdit)),
76f262e1 Andy McCall ↶ 1162
        ("NewLabel", schemars::schema_for!(NewLabel)),
961c10be Andy McCall ↶ 1163
        ("RequiredChecks", schemars::schema_for!(RequiredChecks)),
ef20fdc1 Andy McCall ↶ 1164
        ("Project", schemars::schema_for!(Project)),
1165
        ("ProjectCard", schemars::schema_for!(ProjectCard)),
1166
        ("ProjectColumn", schemars::schema_for!(ProjectColumn)),
1167
        ("Board", schemars::schema_for!(Board)),
1168
        ("NewProject", schemars::schema_for!(NewProject)),
1169
        ("ProjectEdit", schemars::schema_for!(ProjectEdit)),
1170
        ("NewCard", schemars::schema_for!(NewCard)),
1171
        ("CardMove", schemars::schema_for!(CardMove)),
b64e2537 Andy McCall ↶ 1172
        ("NewComment", schemars::schema_for!(NewComment)),
1173
        ("NewProposal", schemars::schema_for!(NewProposal)),
1174
        ("NewReview", schemars::schema_for!(NewReview)),
1175
        ("IssueStateChange", schemars::schema_for!(IssueStateChange)),
1176
        ("WebhookEnvelope", schemars::schema_for!(WebhookEnvelope)),
1177
        ("ProposalEvent", schemars::schema_for!(ProposalEvent)),
3f4b0ea6 Andy McCall ↶ 1178
        ("Release", schemars::schema_for!(Release)),
bf1ab345 Andy McCall ↶ 1179
        ("FlowRun", schemars::schema_for!(FlowRun)),
1180
        ("FlowJob", schemars::schema_for!(FlowJob)),
1181
        ("FlowLogLine", schemars::schema_for!(FlowLogLine)),
1182
        ("AssetBuild", schemars::schema_for!(AssetBuild)),
3f4b0ea6 Andy McCall ↶ 1183
        ("ReleaseAsset", schemars::schema_for!(ReleaseAsset)),
1184
        ("NewRelease", schemars::schema_for!(NewRelease)),
166f6e9b Andy McCall 1185
        ("Drop", schemars::schema_for!(Drop)),
1186
        ("NewDrop", schemars::schema_for!(NewDrop)),
1187
        ("DropEdit", schemars::schema_for!(DropEdit)),
b64e2537 Andy McCall ↶ 1188
    ]
1189
}
b66e70b7 Andy McCall ↶ 1190
1191
/// An OxygenFlow runner (`GET /api/v1/runners`, site administrators).
1192
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1193
pub struct Runner {
1194
    pub id: i64,
1195
    pub name: String,
1196
    /// `online`, `offline`, `draining` or `disabled`.
1197
    pub status: String,
1198
    /// What it serves: empty for the whole site, an owner, or `owner/name`.
1199
    pub serves: String,
1200
    pub arch: String,
1201
    pub os: String,
1202
    pub version: String,
1203
    pub labels: Vec<String>,
1204
    pub max_jobs: i64,
1205
    pub memory_mib: Option<i64>,
1206
    pub cpus: Option<i64>,
1207
    /// The key that signs its receipts (KeyId hex), empty until bound.
1208
    pub key: String,
1209
    /// `registered` or `config` (a hub.toml token).
1210
    pub source: String,
1211
    pub last_seen_ms: Option<i64>,
1212
    /// Jobs it is running now.
1213
    pub running: i64,
2fb70d01 Andy McCall ↶ 1214
    /// What it measured at its last claim (oxygenflow#40): free disk in
1215
    /// MiB, the 1-minute load ×100, its speed score (100 on the reference
1216
    /// machine) and class 1–5, its kernel.
1217
    #[serde(default, skip_serializing_if = "Option::is_none")]
1218
    pub free_disk_mib: Option<i64>,
1219
    #[serde(default, skip_serializing_if = "Option::is_none")]
1220
    pub load_x100: Option<i64>,
1221
    #[serde(default, skip_serializing_if = "Option::is_none")]
1222
    pub speed: Option<i64>,
1223
    #[serde(default, skip_serializing_if = "Option::is_none")]
1224
    pub speed_class: Option<i64>,
1225
    #[serde(default, skip_serializing_if = "String::is_empty")]
1226
    pub kernel: String,
b66e70b7 Andy McCall ↶ 1227
}
1228
1229
/// A job a runner ran or is running.
1230
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1231
pub struct RunnerJob {
1232
    pub repo: String,
1233
    pub run: i64,
1234
    pub job: String,
1235
    pub status: String,
1236
    pub started_ms: Option<i64>,
1237
    pub finished_ms: Option<i64>,
1238
}
1239
1240
/// A job in the queue: running ones first, then queued ones in the order
1241
/// runners claim them.
1242
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1243
pub struct QueueItem {
1244
    pub repo: String,
1245
    pub run: i64,
1246
    pub job: String,
1247
    /// `running` or `queued`.
1248
    pub status: String,
1249
    /// The runner holding it, when running.
1250
    pub runner: String,
1251
}
62ceb2ee Andy McCall ↶ 1252
1253
// ------------------------------------------------------------- assistants
1254
1255
/// An AI assistant at a level (hub spec §13.4). The token never leaves the
1256
/// hub: `has_token` says whether one is set.
1257
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1258
pub struct Assistant {
1259
    pub name: String,
1260
    pub endpoint: String,
1261
    pub api: String,
1262
    pub model: String,
1263
    #[serde(default, skip_serializing_if = "String::is_empty")]
1264
    pub headers: String,
1265
    pub enabled: bool,
1266
    pub budget: i64,
1267
    pub has_token: bool,
1268
    /// Where it comes from: empty for the level's own, else `the site` or
1269
    /// `the NAME organisation`.
1270
    #[serde(default, skip_serializing_if = "String::is_empty")]
1271
    pub from: String,
1272
    /// Off because a level above turned a name like it off.
1273
    #[serde(default)]
1274
    pub off_above: bool,
1275
}
1276
1277
/// `POST …/assistants`: add one, or change the one of that name. A
1278
/// `preset` (`anthropic`, `openai`, `gemini`, `deepseek`, `mistral`,
1279
/// `perplexity`, `ollama`) fills what is left out; the model must be one
1280
/// the endpoint lists when it lists any; `token` is write-only.
1281
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1282
pub struct NewAssistant {
1283
    #[serde(default)]
1284
    pub name: String,
1285
    #[serde(default)]
1286
    pub preset: String,
1287
    #[serde(default)]
1288
    pub endpoint: String,
1289
    #[serde(default)]
1290
    pub api: String,
1291
    pub model: String,
1292
    #[serde(default)]
1293
    pub token: String,
1294
    #[serde(default)]
1295
    pub headers: String,
1296
    #[serde(default = "yes")]
1297
    pub enabled: bool,
1298
    #[serde(default)]
1299
    pub budget: Option<i64>,
1300
}
1301
1302
fn yes() -> bool {
1303
    true
1304
}
1305
1306
/// A level's prompt and those it inherits, outermost first.
1307
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1308
pub struct AssistantPrompt {
1309
    pub prompt: String,
1310
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1311
    pub inherited: Vec<(String, String)>,
1312
}
617c2840 Andy McCall ↶ 1313
1314
/// `GET /repos/{o}/{n}/coverage`: a coverage report from a Flow job
1315
/// (oxygenhub#113); `percent` values are of lines, functions and branches,
1316
/// absent when nothing was counted.
1317
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1318
pub struct CoverageReport {
1319
    pub id: i64,
1320
    pub run: i64,
1321
    pub job: String,
1322
    pub bookmark: String,
1323
    /// The run's state, by hash.
1324
    pub state: String,
1325
    /// `lcov` or `cobertura`.
1326
    pub format: String,
1327
    pub lines_found: i64,
1328
    pub lines_hit: i64,
1329
    pub percent: Option<f64>,
1330
    pub functions_found: i64,
1331
    pub functions_hit: i64,
1332
    pub branches_found: i64,
1333
    pub branches_hit: i64,
1334
    pub files: i64,
1335
    /// Files the report named that are not in the run's state.
1336
    pub dropped: i64,
1337
    pub created_ms: i64,
1338
    /// The report on the hub's Coverage tab, absolute.
1339
    pub url: String,
40dd3f86 Andy McCall ↶ 1340
    /// Who uploaded it from a workstation (#136), when no Flow job made it;
1341
    /// `run` and `job` are then 0 and "upload".
1342
    #[serde(default, skip_serializing_if = "Option::is_none")]
1343
    pub uploaded_by: Option<String>,
617c2840 Andy McCall ↶ 1344
}
1345
1346
/// One file of a coverage report.
1347
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1348
pub struct CoverageFile {
1349
    pub path: String,
1350
    pub lines_found: i64,
1351
    pub lines_hit: i64,
1352
    pub percent: Option<f64>,
1353
    pub functions_found: i64,
1354
    pub functions_hit: i64,
1355
    pub branches_found: i64,
1356
    pub branches_hit: i64,
1357
}
1358
1359
/// `GET /repos/{o}/{n}/coverage/{id}`: a report with its files.
1360
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1361
pub struct CoverageDetail {
1362
    pub report: CoverageReport,
1363
    pub files: Vec<CoverageFile>,
1364
}
1365
1366
/// `GET /repos/{o}/{n}/tests`: a JUnit test report from a Flow job
1367
/// (oxygenhub#114).
1368
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1369
pub struct TestReport {
1370
    pub id: i64,
1371
    pub run: i64,
1372
    pub job: String,
1373
    pub bookmark: String,
1374
    pub state: String,
1375
    pub tests: i64,
1376
    pub passed: i64,
1377
    pub failed: i64,
1378
    pub errors: i64,
1379
    pub skipped: i64,
1380
    /// The cases' times added up.
1381
    pub time_ms: i64,
1382
    pub created_ms: i64,
1383
    pub url: String,
1384
}
1385
1386
/// One test case of a report.
1387
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1388
pub struct TestCase {
1389
    pub suite: String,
1390
    pub classname: String,
1391
    pub name: String,
1392
    /// `passed`, `failed`, `error` or `skipped`.
1393
    pub status: String,
1394
    pub time_ms: i64,
1395
    pub message: String,
1396
    /// A failure's text and output, cut to 16 KiB; empty for a pass.
1397
    pub output: String,
1398
}
1399
1400
/// `GET /repos/{o}/{n}/tests/{id}`: a report with its cases
1401
/// (`?status=failed` for the failed and errored ones).
1402
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1403
pub struct TestReportDetail {
1404
    pub report: TestReport,
1405
    pub cases: Vec<TestCase>,
1406
}