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