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