OXYGENHUB
# f4e138301198 oxygenhub / crates / hub-api / src / lib.rs
48.9 KiB · Rust · last changed GET /api/v1/user/proposals: the dashboard's proposals, for apps 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
f4e13830 Andy McCall ↶ 681
/// `GET /user/proposals`: the caller's proposals to act on, as the web
682
/// dashboard lists them: open ones by others in repositories they belong
683
/// to that they have not reviewed yet, and their own open and draft ones.
684
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
685
pub struct UserProposals {
686
    pub review: Vec<ProposalBrief>,
687
    pub authored: Vec<ProposalBrief>,
688
}
689
690
/// A proposal in a list across repositories.
691
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
692
pub struct ProposalBrief {
693
    /// `owner/name`.
694
    pub repository: String,
695
    pub number: i64,
696
    pub title: String,
697
    pub author: String,
698
    pub state: ProposalState,
699
    pub conflicted: bool,
700
    pub updated_ms: i64,
701
    /// `https://hub/{owner}/{name}/proposal/{number}`.
702
    pub url: String,
703
}
704
ecac6e8d Andy McCall ↶ 705
/// `GET /user/orgs` (#302): an organisation the caller belongs to, and
706
/// their role there.
707
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
708
pub struct UserOrg {
709
    pub name: String,
710
    pub display_name: String,
711
    pub role: String,
b64e2537 Andy McCall ↶ 712
}
713
714
/// Forms accepted by the write endpoints.
715
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
716
pub struct NewRepository {
717
    pub owner: String,
718
    pub name: String,
719
    #[serde(default)]
720
    pub description: String,
721
    #[serde(default = "public")]
722
    pub visibility: Visibility,
723
}
724
725
fn public() -> Visibility {
726
    Visibility::Public
727
}
728
729
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
730
pub struct NewIssue {
731
    pub title: String,
732
    #[serde(default)]
733
    pub body: String,
76f262e1 Andy McCall ↶ 734
    /// Label names; each must exist. Needs triage.
735
    #[serde(default)]
736
    pub labels: Vec<String>,
737
    /// Usernames. Needs triage.
738
    #[serde(default)]
739
    pub assignees: Vec<String>,
740
    /// A milestone's title. Needs triage.
741
    #[serde(default)]
742
    pub milestone: Option<String>,
b64e2537 Andy McCall ↶ 743
}
744
76f262e1 Andy McCall ↶ 745
/// `PATCH /repos/{o}/{n}/issues/{number}`: only the fields given change.
746
/// Title and body: the author or triage. The rest: triage.
747
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
748
pub struct IssueEdit {
749
    #[serde(default)]
750
    pub title: Option<String>,
751
    #[serde(default)]
752
    pub body: Option<String>,
753
    /// The whole set of labels.
754
    #[serde(default)]
755
    pub labels: Option<Vec<String>>,
756
    /// The whole set of assignees.
757
    #[serde(default)]
758
    pub assignees: Option<Vec<String>>,
759
    /// A milestone's title; the empty string clears it.
760
    #[serde(default)]
761
    pub milestone: Option<String>,
762
}
763
961c10be Andy McCall ↶ 764
/// The checks a proposal needs, passed, to land on the repository's
765
/// default bookmark (hub spec §13.1). `GET` and `PUT
766
/// /repos/{o}/{n}/checks/required`.
767
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
768
pub struct RequiredChecks {
769
    pub names: Vec<String>,
770
}
771
ef20fdc1 Andy McCall ↶ 772
/// A project (hub spec §8.2).
773
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
774
pub struct Project {
775
    pub owner: String,
776
    pub number: i64,
777
    pub title: String,
778
    pub description: String,
779
    pub public: bool,
780
    pub closed: bool,
781
    pub updated_ms: i64,
782
    /// The board on the hub, absolute.
783
    pub url: String,
784
}
785
786
/// A card as the caller may see it.
787
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
788
pub struct ProjectCard {
789
    pub id: i64,
790
    /// `issue`, `proposal` or `note`.
791
    pub kind: String,
792
    /// `owner/name#N`; empty for a note.
793
    pub reference: String,
794
    /// The issue's or proposal's title, or the note.
795
    pub title: String,
796
    /// The issue's or proposal's state; empty for a note.
797
    pub state: String,
6a306cd0 Andy McCall ↶ 798
    /// The issue's or proposal's label names (oxygenhub#293).
799
    #[serde(default)]
800
    pub labels: Vec<String>,
801
    /// An issue's assignees' usernames.
802
    #[serde(default)]
803
    pub assignees: Vec<String>,
439ecd87 Andy McCall ↶ 804
    /// When it was archived (ms), for an archived card (oxygenhub#293).
805
    #[serde(default, skip_serializing_if = "Option::is_none")]
806
    pub archived_ms: Option<i64>,
ef20fdc1 Andy McCall ↶ 807
}
808
809
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
810
pub struct ProjectColumn {
811
    pub id: i64,
812
    pub name: String,
813
    pub cards: Vec<ProjectCard>,
814
}
815
816
/// `GET /projects/{owner}/{n}`.
817
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
818
pub struct Board {
819
    pub project: Project,
820
    pub columns: Vec<ProjectColumn>,
821
}
822
823
/// `POST /projects/{owner}`.
824
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
825
pub struct NewProject {
826
    pub title: String,
827
    #[serde(default)]
828
    pub description: String,
829
    #[serde(default)]
830
    pub private: bool,
831
}
832
833
/// `PATCH /projects/{owner}/{n}`: only the fields given change.
834
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
835
pub struct ProjectEdit {
b1e92a62 Andy McCall ↶ 836
    /// Transfer the board to this owner (#125): one the caller may make
837
    /// boards under. It takes the next number there.
838
    #[serde(default, skip_serializing_if = "Option::is_none")]
839
    pub owner: Option<String>,
ef20fdc1 Andy McCall ↶ 840
    #[serde(default)]
841
    pub title: Option<String>,
842
    #[serde(default)]
843
    pub description: Option<String>,
844
    #[serde(default)]
845
    pub private: Option<bool>,
846
    #[serde(default)]
847
    pub closed: Option<bool>,
848
}
849
850
/// `POST /projects/{owner}/{n}/cards`: a reference (`repo#12`) or a note,
851
/// into the column named (by id or name; the first column when absent).
852
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
853
pub struct NewCard {
854
    #[serde(default)]
855
    pub column: Option<String>,
856
    #[serde(default)]
857
    pub reference: String,
858
    #[serde(default)]
859
    pub note: String,
860
}
861
862
/// `PATCH /projects/{owner}/{n}/cards/{id}`: move to a column (id or name).
863
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
864
pub struct CardMove {
865
    pub column: String,
866
}
867
456f4197 Andy McCall ↶ 868
/// `POST /projects/{owner}/{n}/cards/move` (#289): every card of column
869
/// `from` to `column` at once, but those `except` names (card ids, or issue
870
/// and proposal numbers as `12`, `#12`, `name#12` or `owner/name#12`) and,
871
/// given `state`, only cards whose issue or proposal is in one of them
872
/// (`closed`, `landed`…). With `dry_run`, nothing moves.
873
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
874
pub struct CardsMove {
875
    pub from: String,
876
    pub column: String,
877
    #[serde(default)]
878
    pub except: Vec<String>,
879
    #[serde(default)]
880
    pub state: Vec<String>,
881
    #[serde(default)]
882
    pub dry_run: bool,
883
}
884
885
/// What a bulk move moved, and what it left in the column.
886
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
887
pub struct CardsMoved {
888
    pub moved: Vec<ProjectCard>,
439ecd87 Andy McCall ↶ 889
    pub kept: Vec<ProjectCard>,
890
    pub dry_run: bool,
891
}
892
893
/// `POST /projects/{owner}/{n}/cards/archive` (oxygenhub#293): take the
894
/// cards of column `from` off the board, kept and restorable, but those
895
/// `except` names and, given `state`, only cards whose issue or proposal is
896
/// in one of them; given `older_days`, only cards that joined the column
897
/// more than that many days ago. With `dry_run`, nothing is archived.
898
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
899
pub struct CardsArchive {
900
    pub from: String,
901
    #[serde(default)]
902
    pub older_days: Option<i64>,
903
    #[serde(default)]
904
    pub except: Vec<String>,
905
    #[serde(default)]
906
    pub state: Vec<String>,
907
    #[serde(default)]
908
    pub dry_run: bool,
909
}
910
911
/// What an archive took off the board, and what it left in the column.
912
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
913
pub struct CardsArchived {
914
    pub archived: Vec<ProjectCard>,
456f4197 Andy McCall ↶ 915
    pub kept: Vec<ProjectCard>,
916
    pub dry_run: bool,
917
}
918
76f262e1 Andy McCall ↶ 919
/// `POST /repos/{o}/{n}/labels`: create a label, or change one of that name.
920
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
921
pub struct NewLabel {
922
    pub name: String,
923
    /// `#rrggbb`; a default when absent.
924
    #[serde(default)]
925
    pub colour: Option<String>,
926
    #[serde(default)]
927
    pub description: String,
928
}
929
b64e2537 Andy McCall ↶ 930
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
931
pub struct NewComment {
932
    pub body: String,
3f4b0ea6 Andy McCall ↶ 933
    /// For a proposal: anchor the comment to this file's line (1-based) of
934
    /// the projected state; the hub records the line's atom.
935
    #[serde(default)]
936
    pub path: Option<String>,
937
    #[serde(default)]
938
    pub line: Option<usize>,
b64e2537 Andy McCall ↶ 939
}
940
941
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
942
pub struct NewProposal {
943
    pub title: String,
944
    #[serde(default)]
945
    pub body: String,
946
    pub target: String,
947
    /// A bookmark here, or `owner/name:bookmark` of a fork.
948
    pub source: String,
949
    #[serde(default)]
950
    pub draft: bool,
cc1cd197 Andy McCall ↶ 951
}
952
953
/// `POST .../proposals/{number}/reviewers`: accounts to ask for a review.
954
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
955
pub struct ReviewRequest {
956
    pub reviewers: Vec<String>,
7d2eb590 Andy McCall ↶ 957
}
958
959
/// `POST .../proposals/{number}/review-requests`: ask an AI assistant the
960
/// repository may use (hub spec §13.4) to review; it answers as a `comment`
961
/// review via the assistant.
962
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
963
pub struct AssistantRequest {
964
    pub assistant: String,
b64e2537 Andy McCall ↶ 965
}
966
967
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
968
pub struct NewReview {
969
    pub verdict: String,
970
    #[serde(default)]
971
    pub body: String,
972
}
973
974
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
975
pub struct IssueStateChange {
976
    /// `open` or `closed`.
977
    pub state: String,
978
    #[serde(default)]
979
    pub reason: String,
980
}
981
982
/// A webhook payload's envelope (hub spec §12.2).
983
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
984
pub struct WebhookEnvelope {
985
    pub event: String,
986
    pub delivery: String,
987
    pub repository: Option<Repository>,
988
    pub actor: String,
989
    pub at_ms: i64,
990
    pub data: serde_json::Value,
991
}
992
993
/// A server-sent event on a proposal's stream.
994
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
995
pub struct ProposalEvent {
996
    pub number: i64,
997
    pub kind: String,
998
    pub check: Option<Check>,
999
}
1000
3f4b0ea6 Andy McCall ↶ 1001
// --------------------------------------------------------------- releases
1002
1003
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1004
pub struct Release {
1005
    pub tag: String,
1006
    pub title: String,
1007
    pub notes: String,
1008
    pub prerelease: bool,
1009
    pub latest: bool,
1010
    pub author: String,
1011
    pub heads: Vec<String>,
1012
    pub signer: Option<String>,
1013
    pub assets: Vec<ReleaseAsset>,
1014
    pub archives: Vec<String>,
1015
    pub created_ms: i64,
1016
    pub url: String,
1017
}
1018
1019
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1020
pub struct ReleaseAsset {
1021
    pub name: String,
1022
    pub size: i64,
1023
    /// BLAKE3 of the content, hex.
1024
    pub hash: String,
1025
    pub content_type: String,
1026
    pub downloads: i64,
1027
    pub url: String,
10708ab8 Andy McCall ↶ 1028
    /// The OxygenFlow run and job whose artifact has this content, if any.
1029
    #[serde(default, skip_serializing_if = "Option::is_none")]
1030
    pub built_by: Option<AssetBuild>,
1031
}
1032
1033
/// Where a release asset was built (hub spec §9): a job's artifact with the
1034
/// same BLAKE3, and that job's signed receipt when one was kept.
1035
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1036
pub struct AssetBuild {
1037
    pub run: i64,
1038
    pub job: String,
1039
    pub artifact: String,
1040
    pub run_url: String,
1041
    /// The receipt attestation, hex; `None` when the receipt was not signed.
1042
    pub receipt: Option<String>,
1043
    pub receipt_url: Option<String>,
1044
    pub signer: Option<String>,
3f4b0ea6 Andy McCall ↶ 1045
}
1046
739a763a Andy McCall ↶ 1047
/// `PATCH /repos/{o}/{n}/proposals/{number}`: what is given changes,
1048
/// the rest stays (oxygenhub#76).
1049
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1050
pub struct ProposalEdit {
1051
    #[serde(default, skip_serializing_if = "Option::is_none")]
1052
    pub title: Option<String>,
1053
    #[serde(default, skip_serializing_if = "Option::is_none")]
1054
    pub body: Option<String>,
2291f8cc Andy McCall ↶ 1055
    /// The whole set of labels, by name (triage); oxygenhub#80.
1056
    #[serde(default, skip_serializing_if = "Option::is_none")]
1057
    pub labels: Option<Vec<String>>,
71e65fcf Andy McCall ↶ 1058
    /// `closed` or `open` (reopen), by its author or with triage access,
1059
    /// as the page's Close and Reopen do (oxygenhub#140).
1060
    #[serde(default, skip_serializing_if = "Option::is_none")]
1061
    pub state: Option<String>,
739a763a Andy McCall ↶ 1062
}
1063
ced6d3af Andy McCall ↶ 1064
/// `PATCH /repos/{owner}/{name}/releases/{tag}`: what to change; fields
1065
/// left out stay as they are.
1066
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1067
pub struct ReleaseEdit {
1068
    #[serde(default, skip_serializing_if = "Option::is_none")]
1069
    pub title: Option<String>,
1070
    #[serde(default, skip_serializing_if = "Option::is_none")]
1071
    pub notes: Option<String>,
1072
    #[serde(default, skip_serializing_if = "Option::is_none")]
1073
    pub prerelease: Option<bool>,
1074
}
1075
166f6e9b Andy McCall 1076
/// A drop (oxygenhub#279): a small snippet of one or more files, its own
1077
/// Oxygen repository, never listed among repositories. `GET /drops` lists
1078
/// yours, `GET /users/{name}/drops` someone's public ones, and
1079
/// `GET /drops/{id}` one with its files' content.
3f4b0ea6 Andy McCall ↶ 1080
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
166f6e9b Andy McCall 1081
pub struct Drop {
1082
    /// 24 hex digits, unique on the hub.
1083
    pub id: String,
1084
    pub owner: String,
1085
    pub title: String,
1086
    pub description: String,
1087
    /// `public` (listed on its owner's Drops page) or `secret` (unlisted:
1088
    /// readable by anyone with its address).
1089
    pub visibility: String,
1090
    /// The drop's page.
1091
    pub url: String,
1092
    /// What `oxy clone` takes.
1093
    pub clone_url: String,
1094
    pub created_ms: i64,
1095
    pub updated_ms: i64,
1096
    pub files: Vec<DropFile>,
1097
}
1098
1099
/// One of a drop's files. Lists carry no content; one drop's view carries
1100
/// the content of each text file up to 512 KiB.
1101
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1102
pub struct DropFile {
1103
    pub name: String,
1104
    pub size: u64,
1105
    #[serde(default, skip_serializing_if = "Option::is_none")]
1106
    pub content: Option<String>,
1107
    /// The file's bytes on the default bookmark.
1108
    pub raw_url: String,
1109
}
1110
1111
/// `POST /drops`: a new drop with at least one file.
1112
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1113
pub struct NewDrop {
1114
    #[serde(default)]
1115
    pub title: String,
1116
    #[serde(default)]
1117
    pub description: String,
1118
    /// Unlisted, readable by anyone with its address.
1119
    #[serde(default)]
1120
    pub secret: bool,
1121
    pub files: Vec<NewDropFile>,
1122
}
1123
1124
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1125
pub struct NewDropFile {
1126
    pub name: String,
1127
    pub content: String,
1128
}
1129
1130
/// `PATCH /drops/{id}`: what to change; what is left out stays.
1131
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1132
pub struct DropEdit {
1133
    #[serde(default, skip_serializing_if = "Option::is_none")]
1134
    pub title: Option<String>,
1135
    #[serde(default, skip_serializing_if = "Option::is_none")]
1136
    pub description: Option<String>,
1137
    #[serde(default, skip_serializing_if = "Option::is_none")]
1138
    pub secret: Option<bool>,
1139
    /// Files to write, or to remove (`content` null); others are kept.
1140
    #[serde(default)]
1141
    pub files: Vec<DropFileEdit>,
1142
    /// The change's message (default "Edit TITLE").
1143
    #[serde(default, skip_serializing_if = "Option::is_none")]
1144
    pub message: Option<String>,
1145
}
1146
1147
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1148
pub struct DropFileEdit {
1149
    pub name: String,
1150
    #[serde(default)]
1151
    pub content: Option<String>,
1152
}
1153
ba0a55bb Andy McCall ↶ 1154
/// `POST …/tags` (#295): tag the state of `target` (a bookmark, tag or
1155
/// change; the default bookmark when absent).
166f6e9b Andy McCall 1156
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
ba0a55bb Andy McCall ↶ 1157
pub struct NewTag {
1158
    pub name: String,
1159
    #[serde(default)]
1160
    pub target: Option<String>,
1161
    #[serde(default)]
1162
    pub message: Option<String>,
1163
}
1164
1165
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
3f4b0ea6 Andy McCall ↶ 1166
pub struct NewRelease {
1167
    pub tag: String,
1168
    pub title: String,
1169
    #[serde(default)]
1170
    pub notes: Option<String>,
1171
    #[serde(default)]
1172
    pub prerelease: bool,
1173
}
1174
eb2a3502 Andy McCall ↶ 1175
/// `GET /repos/{o}/{n}/diffusion` (oxygenhub#153): what a repository
1176
/// takes from (the subrepos it pins) and what it diffuses to (the
1177
/// repositories that pin it), each as the Diffusion pages show it.
1178
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1179
pub struct Diffusion {
1180
    pub takes_from: Vec<DiffusionPin>,
1181
    pub diffuses_to: Vec<DiffusionPin>,
1182
}
1183
1184
/// One pin of an upstream by a consumer, both named `owner/name`.
1185
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1186
pub struct DiffusionPin {
1187
    pub upstream: String,
1188
    pub consumer: String,
1189
    /// Where the consumer pins it.
1190
    pub path: String,
1191
    /// The consumer's bookmark its bumps land on.
1192
    pub bookmark: String,
1193
    /// Upstream changes the pin lacks; absent when the hub cannot tell.
1194
    #[serde(default)]
1195
    pub behind: Option<u64>,
1196
    /// `off`, `green` or `any`.
1197
    pub follow: String,
1198
    /// The open bump proposal's number, on the consumer.
1199
    #[serde(default)]
1200
    pub bump: Option<i64>,
1201
    /// The newest run of the bump: number and status.
1202
    #[serde(default)]
1203
    pub run: Option<i64>,
1204
    #[serde(default)]
1205
    pub run_status: Option<String>,
1206
    /// The pill: the upstream's half, then the consumer's.
1207
    pub upstream_state: DiffusionHalf,
1208
    pub consumer_state: DiffusionHalf,
1209
}
1210
1211
/// One half of the Diffusion pill.
1212
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1213
pub struct DiffusionHalf {
1214
    /// `green`, `amber`, `red`, `grey` or `off`.
1215
    pub tone: String,
1216
    /// What the pill says: `checked`, `untested`, `passes`, `up to date`…
1217
    pub word: String,
1218
    /// The sentence behind it.
1219
    pub title: String,
1220
}
1221
b64e2537 Andy McCall ↶ 1222
/// Every type of the API, for schema generation.
1223
pub fn schemas() -> Vec<(&'static str, schemars::Schema)> {
1224
    vec![
1225
        ("Repository", schemars::schema_for!(Repository)),
eb2a3502 Andy McCall ↶ 1226
        ("Diffusion", schemars::schema_for!(Diffusion)),
1227
        ("DiffusionPin", schemars::schema_for!(DiffusionPin)),
1228
        ("DiffusionHalf", schemars::schema_for!(DiffusionHalf)),
b64e2537 Andy McCall ↶ 1229
        ("Visibility", schemars::schema_for!(Visibility)),
1230
        ("Bookmark", schemars::schema_for!(Bookmark)),
1231
        ("Tag", schemars::schema_for!(Tag)),
1232
        ("ChangeSummary", schemars::schema_for!(ChangeSummary)),
1233
        ("Author", schemars::schema_for!(Author)),
1234
        ("Signature", schemars::schema_for!(Signature)),
1235
        ("Problem", schemars::schema_for!(Problem)),
1236
        ("Proposal", schemars::schema_for!(Proposal)),
1237
        ("ProposalState", schemars::schema_for!(ProposalState)),
1238
        ("ProposalSource", schemars::schema_for!(ProposalSource)),
1239
        ("Approval", schemars::schema_for!(Approval)),
1240
        ("Issue", schemars::schema_for!(Issue)),
1241
        ("Label", schemars::schema_for!(Label)),
1242
        ("Milestone", schemars::schema_for!(Milestone)),
5ea4872f Andy McCall ↶ 1243
        ("NewMilestone", schemars::schema_for!(NewMilestone)),
1244
        ("MilestoneEdit", schemars::schema_for!(MilestoneEdit)),
b64e2537 Andy McCall ↶ 1245
        ("Comment", schemars::schema_for!(Comment)),
3f02e5ea Andy McCall ↶ 1246
        ("ProposalFile", schemars::schema_for!(ProposalFile)),
42a0ba4b Andy McCall ↶ 1247
        ("Notification", schemars::schema_for!(Notification)),
1248
        ("Inbox", schemars::schema_for!(Inbox)),
b64e2537 Andy McCall ↶ 1249
        ("Atom", schemars::schema_for!(Atom)),
1250
        ("Review", schemars::schema_for!(Review)),
1251
        ("TreeEntry", schemars::schema_for!(TreeEntry)),
1252
        ("BlameLine", schemars::schema_for!(BlameLine)),
1253
        ("FileChange", schemars::schema_for!(FileChange)),
1254
        ("ChangeDetail", schemars::schema_for!(ChangeDetail)),
1255
        ("History", schemars::schema_for!(History)),
1256
        ("Conflict", schemars::schema_for!(Conflict)),
1257
        ("Push", schemars::schema_for!(Push)),
1258
        ("Trust", schemars::schema_for!(Trust)),
1259
        ("Policy", schemars::schema_for!(Policy)),
1260
        ("Rule", schemars::schema_for!(Rule)),
1261
        ("Hook", schemars::schema_for!(Hook)),
1262
        ("NewHook", schemars::schema_for!(NewHook)),
1263
        ("Check", schemars::schema_for!(Check)),
1264
        ("CheckStatus", schemars::schema_for!(CheckStatus)),
1265
        ("NewCheck", schemars::schema_for!(NewCheck)),
1266
        ("User", schemars::schema_for!(User)),
1267
        ("Organisation", schemars::schema_for!(Organisation)),
1268
        ("NewRepository", schemars::schema_for!(NewRepository)),
1269
        ("NewIssue", schemars::schema_for!(NewIssue)),
76f262e1 Andy McCall ↶ 1270
        ("IssueEdit", schemars::schema_for!(IssueEdit)),
2291f8cc Andy McCall ↶ 1271
        ("ReleaseEdit", schemars::schema_for!(ReleaseEdit)),
1272
        ("ProposalEdit", schemars::schema_for!(ProposalEdit)),
76f262e1 Andy McCall ↶ 1273
        ("NewLabel", schemars::schema_for!(NewLabel)),
961c10be Andy McCall ↶ 1274
        ("RequiredChecks", schemars::schema_for!(RequiredChecks)),
ef20fdc1 Andy McCall ↶ 1275
        ("Project", schemars::schema_for!(Project)),
1276
        ("ProjectCard", schemars::schema_for!(ProjectCard)),
1277
        ("ProjectColumn", schemars::schema_for!(ProjectColumn)),
1278
        ("Board", schemars::schema_for!(Board)),
1279
        ("NewProject", schemars::schema_for!(NewProject)),
1280
        ("ProjectEdit", schemars::schema_for!(ProjectEdit)),
1281
        ("NewCard", schemars::schema_for!(NewCard)),
1282
        ("CardMove", schemars::schema_for!(CardMove)),
b64e2537 Andy McCall ↶ 1283
        ("NewComment", schemars::schema_for!(NewComment)),
1284
        ("NewProposal", schemars::schema_for!(NewProposal)),
1285
        ("NewReview", schemars::schema_for!(NewReview)),
1286
        ("IssueStateChange", schemars::schema_for!(IssueStateChange)),
1287
        ("WebhookEnvelope", schemars::schema_for!(WebhookEnvelope)),
1288
        ("ProposalEvent", schemars::schema_for!(ProposalEvent)),
3f4b0ea6 Andy McCall ↶ 1289
        ("Release", schemars::schema_for!(Release)),
bf1ab345 Andy McCall ↶ 1290
        ("FlowRun", schemars::schema_for!(FlowRun)),
1291
        ("FlowJob", schemars::schema_for!(FlowJob)),
1292
        ("FlowLogLine", schemars::schema_for!(FlowLogLine)),
1293
        ("AssetBuild", schemars::schema_for!(AssetBuild)),
3f4b0ea6 Andy McCall ↶ 1294
        ("ReleaseAsset", schemars::schema_for!(ReleaseAsset)),
1295
        ("NewRelease", schemars::schema_for!(NewRelease)),
166f6e9b Andy McCall 1296
        ("Drop", schemars::schema_for!(Drop)),
1297
        ("NewDrop", schemars::schema_for!(NewDrop)),
1298
        ("DropEdit", schemars::schema_for!(DropEdit)),
b64e2537 Andy McCall ↶ 1299
    ]
1300
}
b66e70b7 Andy McCall ↶ 1301
1302
/// An OxygenFlow runner (`GET /api/v1/runners`, site administrators).
1303
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1304
pub struct Runner {
1305
    pub id: i64,
1306
    pub name: String,
1307
    /// `online`, `offline`, `draining` or `disabled`.
1308
    pub status: String,
1309
    /// What it serves: empty for the whole site, an owner, or `owner/name`.
1310
    pub serves: String,
1311
    pub arch: String,
1312
    pub os: String,
1313
    pub version: String,
1314
    pub labels: Vec<String>,
1315
    pub max_jobs: i64,
1316
    pub memory_mib: Option<i64>,
1317
    pub cpus: Option<i64>,
1318
    /// The key that signs its receipts (KeyId hex), empty until bound.
1319
    pub key: String,
1320
    /// `registered` or `config` (a hub.toml token).
1321
    pub source: String,
1322
    pub last_seen_ms: Option<i64>,
1323
    /// Jobs it is running now.
1324
    pub running: i64,
2fb70d01 Andy McCall ↶ 1325
    /// What it measured at its last claim (oxygenflow#40): free disk in
1326
    /// MiB, the 1-minute load ×100, its speed score (100 on the reference
1327
    /// machine) and class 1–5, its kernel.
1328
    #[serde(default, skip_serializing_if = "Option::is_none")]
1329
    pub free_disk_mib: Option<i64>,
1330
    #[serde(default, skip_serializing_if = "Option::is_none")]
1331
    pub load_x100: Option<i64>,
1332
    #[serde(default, skip_serializing_if = "Option::is_none")]
1333
    pub speed: Option<i64>,
1334
    #[serde(default, skip_serializing_if = "Option::is_none")]
1335
    pub speed_class: Option<i64>,
1336
    #[serde(default, skip_serializing_if = "String::is_empty")]
1337
    pub kernel: String,
b66e70b7 Andy McCall ↶ 1338
}
1339
1340
/// A job a runner ran or is running.
1341
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1342
pub struct RunnerJob {
1343
    pub repo: String,
1344
    pub run: i64,
1345
    pub job: String,
1346
    pub status: String,
1347
    pub started_ms: Option<i64>,
1348
    pub finished_ms: Option<i64>,
1349
}
1350
1351
/// A job in the queue: running ones first, then queued ones in the order
1352
/// runners claim them.
1353
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1354
pub struct QueueItem {
1355
    pub repo: String,
1356
    pub run: i64,
1357
    pub job: String,
1358
    /// `running` or `queued`.
1359
    pub status: String,
1360
    /// The runner holding it, when running.
1361
    pub runner: String,
1362
}
62ceb2ee Andy McCall ↶ 1363
1364
// ------------------------------------------------------------- assistants
1365
1366
/// An AI assistant at a level (hub spec §13.4). The token never leaves the
1367
/// hub: `has_token` says whether one is set.
1368
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1369
pub struct Assistant {
1370
    pub name: String,
1371
    pub endpoint: String,
1372
    pub api: String,
1373
    pub model: String,
1374
    #[serde(default, skip_serializing_if = "String::is_empty")]
1375
    pub headers: String,
1376
    pub enabled: bool,
1377
    pub budget: i64,
1378
    pub has_token: bool,
1379
    /// Where it comes from: empty for the level's own, else `the site` or
1380
    /// `the NAME organisation`.
1381
    #[serde(default, skip_serializing_if = "String::is_empty")]
1382
    pub from: String,
1383
    /// Off because a level above turned a name like it off.
1384
    #[serde(default)]
1385
    pub off_above: bool,
1386
}
1387
1388
/// `POST …/assistants`: add one, or change the one of that name. A
1389
/// `preset` (`anthropic`, `openai`, `gemini`, `deepseek`, `mistral`,
1390
/// `perplexity`, `ollama`) fills what is left out; the model must be one
1391
/// the endpoint lists when it lists any; `token` is write-only.
1392
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1393
pub struct NewAssistant {
1394
    #[serde(default)]
1395
    pub name: String,
1396
    #[serde(default)]
1397
    pub preset: String,
1398
    #[serde(default)]
1399
    pub endpoint: String,
1400
    #[serde(default)]
1401
    pub api: String,
1402
    pub model: String,
1403
    #[serde(default)]
1404
    pub token: String,
1405
    #[serde(default)]
1406
    pub headers: String,
1407
    #[serde(default = "yes")]
1408
    pub enabled: bool,
1409
    #[serde(default)]
1410
    pub budget: Option<i64>,
1411
}
1412
1413
fn yes() -> bool {
1414
    true
1415
}
1416
1417
/// A level's prompt and those it inherits, outermost first.
1418
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1419
pub struct AssistantPrompt {
1420
    pub prompt: String,
1421
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1422
    pub inherited: Vec<(String, String)>,
1423
}
617c2840 Andy McCall ↶ 1424
1425
/// `GET /repos/{o}/{n}/coverage`: a coverage report from a Flow job
1426
/// (oxygenhub#113); `percent` values are of lines, functions and branches,
1427
/// absent when nothing was counted.
1428
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1429
pub struct CoverageReport {
1430
    pub id: i64,
1431
    pub run: i64,
1432
    pub job: String,
1433
    pub bookmark: String,
1434
    /// The run's state, by hash.
1435
    pub state: String,
1436
    /// `lcov` or `cobertura`.
1437
    pub format: String,
1438
    pub lines_found: i64,
1439
    pub lines_hit: i64,
1440
    pub percent: Option<f64>,
1441
    pub functions_found: i64,
1442
    pub functions_hit: i64,
1443
    pub branches_found: i64,
1444
    pub branches_hit: i64,
1445
    pub files: i64,
1446
    /// Files the report named that are not in the run's state.
1447
    pub dropped: i64,
1448
    pub created_ms: i64,
1449
    /// The report on the hub's Coverage tab, absolute.
1450
    pub url: String,
40dd3f86 Andy McCall ↶ 1451
    /// Who uploaded it from a workstation (#136), when no Flow job made it;
1452
    /// `run` and `job` are then 0 and "upload".
1453
    #[serde(default, skip_serializing_if = "Option::is_none")]
1454
    pub uploaded_by: Option<String>,
617c2840 Andy McCall ↶ 1455
}
1456
1457
/// One file of a coverage report.
1458
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1459
pub struct CoverageFile {
1460
    pub path: String,
1461
    pub lines_found: i64,
1462
    pub lines_hit: i64,
1463
    pub percent: Option<f64>,
1464
    pub functions_found: i64,
1465
    pub functions_hit: i64,
1466
    pub branches_found: i64,
1467
    pub branches_hit: i64,
1468
}
1469
1470
/// `GET /repos/{o}/{n}/coverage/{id}`: a report with its files.
1471
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1472
pub struct CoverageDetail {
1473
    pub report: CoverageReport,
1474
    pub files: Vec<CoverageFile>,
1475
}
1476
1477
/// `GET /repos/{o}/{n}/tests`: a JUnit test report from a Flow job
1478
/// (oxygenhub#114).
1479
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1480
pub struct TestReport {
1481
    pub id: i64,
1482
    pub run: i64,
1483
    pub job: String,
1484
    pub bookmark: String,
1485
    pub state: String,
1486
    pub tests: i64,
1487
    pub passed: i64,
1488
    pub failed: i64,
1489
    pub errors: i64,
1490
    pub skipped: i64,
1491
    /// The cases' times added up.
1492
    pub time_ms: i64,
1493
    pub created_ms: i64,
1494
    pub url: String,
1495
}
1496
1497
/// One test case of a report.
1498
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1499
pub struct TestCase {
1500
    pub suite: String,
1501
    pub classname: String,
1502
    pub name: String,
1503
    /// `passed`, `failed`, `error` or `skipped`.
1504
    pub status: String,
1505
    pub time_ms: i64,
1506
    pub message: String,
1507
    /// A failure's text and output, cut to 16 KiB; empty for a pass.
1508
    pub output: String,
1509
}
1510
1511
/// `GET /repos/{o}/{n}/tests/{id}`: a report with its cases
1512
/// (`?status=failed` for the failed and errored ones).
1513
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1514
pub struct TestReportDetail {
1515
    pub report: TestReport,
1516
    pub cases: Vec<TestCase>,
1517
}