OXYGENHUB
# 9041db4e4d92 oxygenhub / crates / hub-api / src / lib.rs
44.8 KiB · Rust · last changed Drops: per-user gists, each a small hidden Oxygen repository (#279) 16 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>,
3f4b0ea6 Andy McCall ↶ 939
}
940
739a763a Andy McCall ↶ 941
/// `PATCH /repos/{o}/{n}/proposals/{number}`: what is given changes,
942
/// the rest stays (oxygenhub#76).
943
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
944
pub struct ProposalEdit {
945
    #[serde(default, skip_serializing_if = "Option::is_none")]
946
    pub title: Option<String>,
947
    #[serde(default, skip_serializing_if = "Option::is_none")]
948
    pub body: Option<String>,
2291f8cc Andy McCall ↶ 949
    /// The whole set of labels, by name (triage); oxygenhub#80.
950
    #[serde(default, skip_serializing_if = "Option::is_none")]
951
    pub labels: Option<Vec<String>>,
71e65fcf Andy McCall ↶ 952
    /// `closed` or `open` (reopen), by its author or with triage access,
953
    /// as the page's Close and Reopen do (oxygenhub#140).
954
    #[serde(default, skip_serializing_if = "Option::is_none")]
955
    pub state: Option<String>,
739a763a Andy McCall ↶ 956
}
957
ced6d3af Andy McCall ↶ 958
/// `PATCH /repos/{owner}/{name}/releases/{tag}`: what to change; fields
959
/// left out stay as they are.
960
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
961
pub struct ReleaseEdit {
962
    #[serde(default, skip_serializing_if = "Option::is_none")]
963
    pub title: Option<String>,
964
    #[serde(default, skip_serializing_if = "Option::is_none")]
965
    pub notes: Option<String>,
966
    #[serde(default, skip_serializing_if = "Option::is_none")]
967
    pub prerelease: Option<bool>,
968
}
969
166f6e9b Andy McCall 970
/// A drop (oxygenhub#279): a small snippet of one or more files, its own
971
/// Oxygen repository, never listed among repositories. `GET /drops` lists
972
/// yours, `GET /users/{name}/drops` someone's public ones, and
973
/// `GET /drops/{id}` one with its files' content.
3f4b0ea6 Andy McCall ↶ 974
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
166f6e9b Andy McCall 975
pub struct Drop {
976
    /// 24 hex digits, unique on the hub.
977
    pub id: String,
978
    pub owner: String,
979
    pub title: String,
980
    pub description: String,
981
    /// `public` (listed on its owner's Drops page) or `secret` (unlisted:
982
    /// readable by anyone with its address).
983
    pub visibility: String,
984
    /// The drop's page.
985
    pub url: String,
986
    /// What `oxy clone` takes.
987
    pub clone_url: String,
988
    pub created_ms: i64,
989
    pub updated_ms: i64,
990
    pub files: Vec<DropFile>,
991
}
992
993
/// One of a drop's files. Lists carry no content; one drop's view carries
994
/// the content of each text file up to 512 KiB.
995
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
996
pub struct DropFile {
997
    pub name: String,
998
    pub size: u64,
999
    #[serde(default, skip_serializing_if = "Option::is_none")]
1000
    pub content: Option<String>,
1001
    /// The file's bytes on the default bookmark.
1002
    pub raw_url: String,
1003
}
1004
1005
/// `POST /drops`: a new drop with at least one file.
1006
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1007
pub struct NewDrop {
1008
    #[serde(default)]
1009
    pub title: String,
1010
    #[serde(default)]
1011
    pub description: String,
1012
    /// Unlisted, readable by anyone with its address.
1013
    #[serde(default)]
1014
    pub secret: bool,
1015
    pub files: Vec<NewDropFile>,
1016
}
1017
1018
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1019
pub struct NewDropFile {
1020
    pub name: String,
1021
    pub content: String,
1022
}
1023
1024
/// `PATCH /drops/{id}`: what to change; what is left out stays.
1025
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1026
pub struct DropEdit {
1027
    #[serde(default, skip_serializing_if = "Option::is_none")]
1028
    pub title: Option<String>,
1029
    #[serde(default, skip_serializing_if = "Option::is_none")]
1030
    pub description: Option<String>,
1031
    #[serde(default, skip_serializing_if = "Option::is_none")]
1032
    pub secret: Option<bool>,
1033
    /// Files to write, or to remove (`content` null); others are kept.
1034
    #[serde(default)]
1035
    pub files: Vec<DropFileEdit>,
1036
    /// The change's message (default "Edit TITLE").
1037
    #[serde(default, skip_serializing_if = "Option::is_none")]
1038
    pub message: Option<String>,
1039
}
1040
1041
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1042
pub struct DropFileEdit {
1043
    pub name: String,
1044
    #[serde(default)]
1045
    pub content: Option<String>,
1046
}
1047
1048
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
3f4b0ea6 Andy McCall ↶ 1049
pub struct NewRelease {
1050
    pub tag: String,
1051
    pub title: String,
1052
    #[serde(default)]
1053
    pub notes: Option<String>,
1054
    #[serde(default)]
1055
    pub prerelease: bool,
1056
}
1057
eb2a3502 Andy McCall ↶ 1058
/// `GET /repos/{o}/{n}/diffusion` (oxygenhub#153): what a repository
1059
/// takes from (the subrepos it pins) and what it diffuses to (the
1060
/// repositories that pin it), each as the Diffusion pages show it.
1061
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1062
pub struct Diffusion {
1063
    pub takes_from: Vec<DiffusionPin>,
1064
    pub diffuses_to: Vec<DiffusionPin>,
1065
}
1066
1067
/// One pin of an upstream by a consumer, both named `owner/name`.
1068
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1069
pub struct DiffusionPin {
1070
    pub upstream: String,
1071
    pub consumer: String,
1072
    /// Where the consumer pins it.
1073
    pub path: String,
1074
    /// The consumer's bookmark its bumps land on.
1075
    pub bookmark: String,
1076
    /// Upstream changes the pin lacks; absent when the hub cannot tell.
1077
    #[serde(default)]
1078
    pub behind: Option<u64>,
1079
    /// `off`, `green` or `any`.
1080
    pub follow: String,
1081
    /// The open bump proposal's number, on the consumer.
1082
    #[serde(default)]
1083
    pub bump: Option<i64>,
1084
    /// The newest run of the bump: number and status.
1085
    #[serde(default)]
1086
    pub run: Option<i64>,
1087
    #[serde(default)]
1088
    pub run_status: Option<String>,
1089
    /// The pill: the upstream's half, then the consumer's.
1090
    pub upstream_state: DiffusionHalf,
1091
    pub consumer_state: DiffusionHalf,
1092
}
1093
1094
/// One half of the Diffusion pill.
1095
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1096
pub struct DiffusionHalf {
1097
    /// `green`, `amber`, `red`, `grey` or `off`.
1098
    pub tone: String,
1099
    /// What the pill says: `checked`, `untested`, `passes`, `up to date`…
1100
    pub word: String,
1101
    /// The sentence behind it.
1102
    pub title: String,
1103
}
1104
b64e2537 Andy McCall ↶ 1105
/// Every type of the API, for schema generation.
1106
pub fn schemas() -> Vec<(&'static str, schemars::Schema)> {
1107
    vec![
1108
        ("Repository", schemars::schema_for!(Repository)),
eb2a3502 Andy McCall ↶ 1109
        ("Diffusion", schemars::schema_for!(Diffusion)),
1110
        ("DiffusionPin", schemars::schema_for!(DiffusionPin)),
1111
        ("DiffusionHalf", schemars::schema_for!(DiffusionHalf)),
b64e2537 Andy McCall ↶ 1112
        ("Visibility", schemars::schema_for!(Visibility)),
1113
        ("Bookmark", schemars::schema_for!(Bookmark)),
1114
        ("Tag", schemars::schema_for!(Tag)),
1115
        ("ChangeSummary", schemars::schema_for!(ChangeSummary)),
1116
        ("Author", schemars::schema_for!(Author)),
1117
        ("Signature", schemars::schema_for!(Signature)),
1118
        ("Problem", schemars::schema_for!(Problem)),
1119
        ("Proposal", schemars::schema_for!(Proposal)),
1120
        ("ProposalState", schemars::schema_for!(ProposalState)),
1121
        ("ProposalSource", schemars::schema_for!(ProposalSource)),
1122
        ("Approval", schemars::schema_for!(Approval)),
1123
        ("Issue", schemars::schema_for!(Issue)),
1124
        ("Label", schemars::schema_for!(Label)),
1125
        ("Milestone", schemars::schema_for!(Milestone)),
5ea4872f Andy McCall ↶ 1126
        ("NewMilestone", schemars::schema_for!(NewMilestone)),
1127
        ("MilestoneEdit", schemars::schema_for!(MilestoneEdit)),
b64e2537 Andy McCall ↶ 1128
        ("Comment", schemars::schema_for!(Comment)),
3f02e5ea Andy McCall ↶ 1129
        ("ProposalFile", schemars::schema_for!(ProposalFile)),
42a0ba4b Andy McCall ↶ 1130
        ("Notification", schemars::schema_for!(Notification)),
1131
        ("Inbox", schemars::schema_for!(Inbox)),
b64e2537 Andy McCall ↶ 1132
        ("Atom", schemars::schema_for!(Atom)),
1133
        ("Review", schemars::schema_for!(Review)),
1134
        ("TreeEntry", schemars::schema_for!(TreeEntry)),
1135
        ("BlameLine", schemars::schema_for!(BlameLine)),
1136
        ("FileChange", schemars::schema_for!(FileChange)),
1137
        ("ChangeDetail", schemars::schema_for!(ChangeDetail)),
1138
        ("History", schemars::schema_for!(History)),
1139
        ("Conflict", schemars::schema_for!(Conflict)),
1140
        ("Push", schemars::schema_for!(Push)),
1141
        ("Trust", schemars::schema_for!(Trust)),
1142
        ("Policy", schemars::schema_for!(Policy)),
1143
        ("Rule", schemars::schema_for!(Rule)),
1144
        ("Hook", schemars::schema_for!(Hook)),
1145
        ("NewHook", schemars::schema_for!(NewHook)),
1146
        ("Check", schemars::schema_for!(Check)),
1147
        ("CheckStatus", schemars::schema_for!(CheckStatus)),
1148
        ("NewCheck", schemars::schema_for!(NewCheck)),
1149
        ("User", schemars::schema_for!(User)),
1150
        ("Organisation", schemars::schema_for!(Organisation)),
1151
        ("NewRepository", schemars::schema_for!(NewRepository)),
1152
        ("NewIssue", schemars::schema_for!(NewIssue)),
76f262e1 Andy McCall ↶ 1153
        ("IssueEdit", schemars::schema_for!(IssueEdit)),
2291f8cc Andy McCall ↶ 1154
        ("ReleaseEdit", schemars::schema_for!(ReleaseEdit)),
1155
        ("ProposalEdit", schemars::schema_for!(ProposalEdit)),
76f262e1 Andy McCall ↶ 1156
        ("NewLabel", schemars::schema_for!(NewLabel)),
961c10be Andy McCall ↶ 1157
        ("RequiredChecks", schemars::schema_for!(RequiredChecks)),
ef20fdc1 Andy McCall ↶ 1158
        ("Project", schemars::schema_for!(Project)),
1159
        ("ProjectCard", schemars::schema_for!(ProjectCard)),
1160
        ("ProjectColumn", schemars::schema_for!(ProjectColumn)),
1161
        ("Board", schemars::schema_for!(Board)),
1162
        ("NewProject", schemars::schema_for!(NewProject)),
1163
        ("ProjectEdit", schemars::schema_for!(ProjectEdit)),
1164
        ("NewCard", schemars::schema_for!(NewCard)),
1165
        ("CardMove", schemars::schema_for!(CardMove)),
b64e2537 Andy McCall ↶ 1166
        ("NewComment", schemars::schema_for!(NewComment)),
1167
        ("NewProposal", schemars::schema_for!(NewProposal)),
1168
        ("NewReview", schemars::schema_for!(NewReview)),
1169
        ("IssueStateChange", schemars::schema_for!(IssueStateChange)),
1170
        ("WebhookEnvelope", schemars::schema_for!(WebhookEnvelope)),
1171
        ("ProposalEvent", schemars::schema_for!(ProposalEvent)),
3f4b0ea6 Andy McCall ↶ 1172
        ("Release", schemars::schema_for!(Release)),
bf1ab345 Andy McCall ↶ 1173
        ("FlowRun", schemars::schema_for!(FlowRun)),
1174
        ("FlowJob", schemars::schema_for!(FlowJob)),
1175
        ("FlowLogLine", schemars::schema_for!(FlowLogLine)),
1176
        ("AssetBuild", schemars::schema_for!(AssetBuild)),
3f4b0ea6 Andy McCall ↶ 1177
        ("ReleaseAsset", schemars::schema_for!(ReleaseAsset)),
1178
        ("NewRelease", schemars::schema_for!(NewRelease)),
166f6e9b Andy McCall 1179
        ("Drop", schemars::schema_for!(Drop)),
1180
        ("NewDrop", schemars::schema_for!(NewDrop)),
1181
        ("DropEdit", schemars::schema_for!(DropEdit)),
b64e2537 Andy McCall ↶ 1182
    ]
1183
}
b66e70b7 Andy McCall ↶ 1184
1185
/// An OxygenFlow runner (`GET /api/v1/runners`, site administrators).
1186
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1187
pub struct Runner {
1188
    pub id: i64,
1189
    pub name: String,
1190
    /// `online`, `offline`, `draining` or `disabled`.
1191
    pub status: String,
1192
    /// What it serves: empty for the whole site, an owner, or `owner/name`.
1193
    pub serves: String,
1194
    pub arch: String,
1195
    pub os: String,
1196
    pub version: String,
1197
    pub labels: Vec<String>,
1198
    pub max_jobs: i64,
1199
    pub memory_mib: Option<i64>,
1200
    pub cpus: Option<i64>,
1201
    /// The key that signs its receipts (KeyId hex), empty until bound.
1202
    pub key: String,
1203
    /// `registered` or `config` (a hub.toml token).
1204
    pub source: String,
1205
    pub last_seen_ms: Option<i64>,
1206
    /// Jobs it is running now.
1207
    pub running: i64,
2fb70d01 Andy McCall ↶ 1208
    /// What it measured at its last claim (oxygenflow#40): free disk in
1209
    /// MiB, the 1-minute load ×100, its speed score (100 on the reference
1210
    /// machine) and class 1–5, its kernel.
1211
    #[serde(default, skip_serializing_if = "Option::is_none")]
1212
    pub free_disk_mib: Option<i64>,
1213
    #[serde(default, skip_serializing_if = "Option::is_none")]
1214
    pub load_x100: Option<i64>,
1215
    #[serde(default, skip_serializing_if = "Option::is_none")]
1216
    pub speed: Option<i64>,
1217
    #[serde(default, skip_serializing_if = "Option::is_none")]
1218
    pub speed_class: Option<i64>,
1219
    #[serde(default, skip_serializing_if = "String::is_empty")]
1220
    pub kernel: String,
b66e70b7 Andy McCall ↶ 1221
}
1222
1223
/// A job a runner ran or is running.
1224
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1225
pub struct RunnerJob {
1226
    pub repo: String,
1227
    pub run: i64,
1228
    pub job: String,
1229
    pub status: String,
1230
    pub started_ms: Option<i64>,
1231
    pub finished_ms: Option<i64>,
1232
}
1233
1234
/// A job in the queue: running ones first, then queued ones in the order
1235
/// runners claim them.
1236
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1237
pub struct QueueItem {
1238
    pub repo: String,
1239
    pub run: i64,
1240
    pub job: String,
1241
    /// `running` or `queued`.
1242
    pub status: String,
1243
    /// The runner holding it, when running.
1244
    pub runner: String,
1245
}
62ceb2ee Andy McCall ↶ 1246
1247
// ------------------------------------------------------------- assistants
1248
1249
/// An AI assistant at a level (hub spec §13.4). The token never leaves the
1250
/// hub: `has_token` says whether one is set.
1251
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1252
pub struct Assistant {
1253
    pub name: String,
1254
    pub endpoint: String,
1255
    pub api: String,
1256
    pub model: String,
1257
    #[serde(default, skip_serializing_if = "String::is_empty")]
1258
    pub headers: String,
1259
    pub enabled: bool,
1260
    pub budget: i64,
1261
    pub has_token: bool,
1262
    /// Where it comes from: empty for the level's own, else `the site` or
1263
    /// `the NAME organisation`.
1264
    #[serde(default, skip_serializing_if = "String::is_empty")]
1265
    pub from: String,
1266
    /// Off because a level above turned a name like it off.
1267
    #[serde(default)]
1268
    pub off_above: bool,
1269
}
1270
1271
/// `POST …/assistants`: add one, or change the one of that name. A
1272
/// `preset` (`anthropic`, `openai`, `gemini`, `deepseek`, `mistral`,
1273
/// `perplexity`, `ollama`) fills what is left out; the model must be one
1274
/// the endpoint lists when it lists any; `token` is write-only.
1275
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1276
pub struct NewAssistant {
1277
    #[serde(default)]
1278
    pub name: String,
1279
    #[serde(default)]
1280
    pub preset: String,
1281
    #[serde(default)]
1282
    pub endpoint: String,
1283
    #[serde(default)]
1284
    pub api: String,
1285
    pub model: String,
1286
    #[serde(default)]
1287
    pub token: String,
1288
    #[serde(default)]
1289
    pub headers: String,
1290
    #[serde(default = "yes")]
1291
    pub enabled: bool,
1292
    #[serde(default)]
1293
    pub budget: Option<i64>,
1294
}
1295
1296
fn yes() -> bool {
1297
    true
1298
}
1299
1300
/// A level's prompt and those it inherits, outermost first.
1301
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1302
pub struct AssistantPrompt {
1303
    pub prompt: String,
1304
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1305
    pub inherited: Vec<(String, String)>,
1306
}
617c2840 Andy McCall ↶ 1307
1308
/// `GET /repos/{o}/{n}/coverage`: a coverage report from a Flow job
1309
/// (oxygenhub#113); `percent` values are of lines, functions and branches,
1310
/// absent when nothing was counted.
1311
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1312
pub struct CoverageReport {
1313
    pub id: i64,
1314
    pub run: i64,
1315
    pub job: String,
1316
    pub bookmark: String,
1317
    /// The run's state, by hash.
1318
    pub state: String,
1319
    /// `lcov` or `cobertura`.
1320
    pub format: String,
1321
    pub lines_found: i64,
1322
    pub lines_hit: i64,
1323
    pub percent: Option<f64>,
1324
    pub functions_found: i64,
1325
    pub functions_hit: i64,
1326
    pub branches_found: i64,
1327
    pub branches_hit: i64,
1328
    pub files: i64,
1329
    /// Files the report named that are not in the run's state.
1330
    pub dropped: i64,
1331
    pub created_ms: i64,
1332
    /// The report on the hub's Coverage tab, absolute.
1333
    pub url: String,
40dd3f86 Andy McCall ↶ 1334
    /// Who uploaded it from a workstation (#136), when no Flow job made it;
1335
    /// `run` and `job` are then 0 and "upload".
1336
    #[serde(default, skip_serializing_if = "Option::is_none")]
1337
    pub uploaded_by: Option<String>,
617c2840 Andy McCall ↶ 1338
}
1339
1340
/// One file of a coverage report.
1341
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1342
pub struct CoverageFile {
1343
    pub path: String,
1344
    pub lines_found: i64,
1345
    pub lines_hit: i64,
1346
    pub percent: Option<f64>,
1347
    pub functions_found: i64,
1348
    pub functions_hit: i64,
1349
    pub branches_found: i64,
1350
    pub branches_hit: i64,
1351
}
1352
1353
/// `GET /repos/{o}/{n}/coverage/{id}`: a report with its files.
1354
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1355
pub struct CoverageDetail {
1356
    pub report: CoverageReport,
1357
    pub files: Vec<CoverageFile>,
1358
}
1359
1360
/// `GET /repos/{o}/{n}/tests`: a JUnit test report from a Flow job
1361
/// (oxygenhub#114).
1362
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1363
pub struct TestReport {
1364
    pub id: i64,
1365
    pub run: i64,
1366
    pub job: String,
1367
    pub bookmark: String,
1368
    pub state: String,
1369
    pub tests: i64,
1370
    pub passed: i64,
1371
    pub failed: i64,
1372
    pub errors: i64,
1373
    pub skipped: i64,
1374
    /// The cases' times added up.
1375
    pub time_ms: i64,
1376
    pub created_ms: i64,
1377
    pub url: String,
1378
}
1379
1380
/// One test case of a report.
1381
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1382
pub struct TestCase {
1383
    pub suite: String,
1384
    pub classname: String,
1385
    pub name: String,
1386
    /// `passed`, `failed`, `error` or `skipped`.
1387
    pub status: String,
1388
    pub time_ms: i64,
1389
    pub message: String,
1390
    /// A failure's text and output, cut to 16 KiB; empty for a pass.
1391
    pub output: String,
1392
}
1393
1394
/// `GET /repos/{o}/{n}/tests/{id}`: a report with its cases
1395
/// (`?status=failed` for the failed and errored ones).
1396
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1397
pub struct TestReportDetail {
1398
    pub report: TestReport,
1399
    pub cases: Vec<TestCase>,
1400
}