OXYGENHUB
# c4c87f481d05 oxygenhub / crates / hub-api / src / lib.rs
29.4 KiB · Rust · last changed Runners: the queue on Admin → Runners, and the runner API (refs #41, part 4) 1 month ago source blame history raw
1
//! Types of the OxygenHub JSON API (hub spec §12.1). Everything here is
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
9
use schemars::JsonSchema;
10
use serde::{Deserialize, Serialize};
11
12
/// A repository as the API lists it.
13
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
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
27
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
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).
55
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
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.
65
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
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.
74
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
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,
83
}
84
85
/// Who wrote a change: the linked account when the signing key is linked,
86
/// else the key alone.
87
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
88
pub struct Author {
89
    pub name: String,
90
    pub email: String,
91
    pub key: String,
92
    /// The hub account this key is linked to, when any.
93
    pub account: Option<String>,
94
    /// Set when the change is signed by a key no account has linked, and
95
    /// says how its owner links it.
96
    #[serde(default, skip_serializing_if = "Option::is_none")]
97
    pub note: Option<String>,
98
}
99
100
impl Author {
101
    /// What `note` says for a key that no account has linked.
102
    pub const UNLINKED: &'static str =
103
        "signed by a key not linked to any account; its owner links it under Settings → Keys (/settings/keys)";
104
105
    /// The note for an author with this key and account.
106
    pub fn note_for(key: &str, account: &Option<String>) -> Option<String> {
107
        (!key.is_empty() && account.is_none()).then(|| Self::UNLINKED.to_string())
108
    }
109
}
110
111
/// Signature status of a change as `oxy verify` reports it.
112
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
113
#[serde(tag = "status", rename_all = "lowercase")]
114
pub enum Signature {
115
    Unsigned,
116
    Valid { key: String, sealed: bool, revoked: bool },
117
    Invalid { reason: String },
118
}
119
120
/// An RFC 7807 problem response.
121
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
122
pub struct Problem {
123
    pub status: u16,
124
    pub title: String,
125
    pub detail: String,
126
}
127
128
#[cfg(test)]
129
mod tests {
130
    use super::*;
131
132
    #[test]
133
    fn visibility_round_trips() {
134
        for v in [Visibility::Public, Visibility::Internal, Visibility::Private] {
135
            assert_eq!(Visibility::parse(v.as_str()), Some(v));
136
        }
137
        assert_eq!(Visibility::parse("secret"), None);
138
    }
139
}
140
141
// ---------------------------------------------------------------- proposals
142
143
/// A proposal: a request to add changes to a target bookmark (hub spec §7).
144
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
145
pub struct Proposal {
146
    pub number: i64,
147
    pub title: String,
148
    pub body: String,
149
    pub author: String,
150
    pub state: ProposalState,
151
    pub target: String,
152
    pub source: ProposalSource,
153
    /// The changes the proposal adds, dependency order, newest last.
154
    pub changes: Vec<ChangeSummary>,
155
    /// Heads of the projected state (target plus the changes), when computed.
156
    pub projected_heads: Vec<String>,
157
    pub projected_state: Option<String>,
158
    pub conflicted: bool,
159
    pub approvals: Vec<Approval>,
160
    pub landable: bool,
161
    pub blockers: Vec<String>,
162
    pub created_ms: i64,
163
    pub updated_ms: i64,
164
    /// `https://hub/{owner}/{name}/proposal/{number}`.
165
    pub url: String,
166
    /// Where `oxy` fetches the changes from.
167
    pub repository_url: String,
168
    /// The fork's clone URL when the source is a fork.
169
    pub source_url: Option<String>,
170
}
171
172
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
173
#[serde(rename_all = "lowercase")]
174
pub enum ProposalState {
175
    Draft,
176
    Open,
177
    Landed,
178
    Closed,
179
}
180
181
impl ProposalState {
182
    pub fn as_str(self) -> &'static str {
183
        match self {
184
            ProposalState::Draft => "draft",
185
            ProposalState::Open => "open",
186
            ProposalState::Landed => "landed",
187
            ProposalState::Closed => "closed",
188
        }
189
    }
190
191
    pub fn parse(s: &str) -> Option<ProposalState> {
192
        Some(match s {
193
            "draft" => ProposalState::Draft,
194
            "open" => ProposalState::Open,
195
            "landed" => ProposalState::Landed,
196
            "closed" => ProposalState::Closed,
197
            _ => return None,
198
        })
199
    }
200
}
201
202
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
203
#[serde(tag = "kind", rename_all = "lowercase")]
204
pub enum ProposalSource {
205
    /// A bookmark of the same repository.
206
    Bookmark { bookmark: String },
207
    /// A bookmark of a fork.
208
    Fork { owner: String, name: String, bookmark: String },
209
    /// An explicit list of change hashes.
210
    Changes { hashes: Vec<String> },
211
}
212
213
/// A reviewer's approval, counted only when backed by a seal over every
214
/// change of the proposal signed with a key linked to the reviewer.
215
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
216
pub struct Approval {
217
    pub account: String,
218
    pub sealed: bool,
219
    pub key: Option<String>,
220
}
221
222
// ------------------------------------------------------------------ issues
223
224
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
225
pub struct Issue {
226
    pub number: i64,
227
    pub title: String,
228
    pub body: String,
229
    pub author: String,
230
    pub state: String,
231
    pub reason: String,
232
    pub labels: Vec<Label>,
233
    pub assignees: Vec<String>,
234
    pub milestone: Option<String>,
235
    pub comments: i64,
236
    pub locked: bool,
237
    pub pinned: bool,
238
    pub created_ms: i64,
239
    pub updated_ms: i64,
240
    pub closed_ms: Option<i64>,
241
    pub url: String,
242
}
243
244
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
245
pub struct Label {
246
    pub name: String,
247
    pub colour: String,
248
    pub description: String,
249
}
250
251
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
252
pub struct Milestone {
253
    pub title: String,
254
    pub description: String,
255
    pub due_ms: Option<i64>,
256
    pub state: String,
257
    pub open: i64,
258
    pub closed: i64,
259
}
260
261
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
262
pub struct Comment {
263
    pub id: i64,
264
    pub author: String,
265
    pub body: String,
266
    pub created_ms: i64,
267
    /// For proposal comments: the file and the atom the comment anchors to.
268
    pub path: Option<String>,
269
    pub anchor: Option<Atom>,
270
    pub resolved: bool,
271
}
272
273
/// One entry in the caller's inbox (hub spec §10).
274
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
275
pub struct Notification {
276
    pub id: i64,
277
    pub at_ms: i64,
278
    /// `issue.opened`, `proposal.comment`, `mention`, `review`, …
279
    pub kind: String,
280
    pub title: String,
281
    /// The page on the hub, absolute.
282
    pub url: String,
283
    pub actor: String,
284
    pub read: bool,
285
}
286
287
/// `GET /notifications`: the unread count and the newest entries, unread first.
288
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
289
pub struct Inbox {
290
    pub unread: i64,
291
    pub items: Vec<Notification>,
292
}
293
294
/// A file a proposal changes, between the target's state and the
295
/// projected state (hub spec §7.2). Fetch either side's bytes from
296
/// `/proposals/{number}/content/{base|head}/{path}`.
297
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
298
pub struct ProposalFile {
299
    pub path: String,
300
    /// For a rename, the path in the target's state.
301
    pub from: Option<String>,
302
    /// `added`, `removed`, `modified`, `renamed`, `mode` or `replaced`.
303
    pub kind: String,
304
    pub added: usize,
305
    pub removed: usize,
306
}
307
308
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
309
pub struct Atom {
310
    pub change: String,
311
    pub index: u32,
312
}
313
314
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
315
pub struct Review {
316
    pub id: i64,
317
    pub author: String,
318
    pub verdict: String,
319
    pub body: String,
320
    pub sealed: bool,
321
    pub created_ms: i64,
322
}
323
324
// ------------------------------------------------------------- repository
325
326
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
327
pub struct TreeEntry {
328
    pub name: String,
329
    pub path: String,
330
    pub kind: String,
331
    pub exec: bool,
332
    pub size: Option<u64>,
333
    pub conflicted: bool,
334
}
335
336
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
337
pub struct BlameLine {
338
    pub line: usize,
339
    pub change: String,
340
    pub index: u32,
341
    pub author: String,
342
    pub when_ms: u64,
343
    pub text: String,
344
}
345
346
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
347
pub struct FileChange {
348
    pub path: String,
349
    pub kind: String,
350
    pub from: Option<String>,
351
    pub added: usize,
352
    pub removed: usize,
353
}
354
355
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
356
pub struct ChangeDetail {
357
    pub change: ChangeSummary,
358
    pub body: String,
359
    pub dependents: Vec<String>,
360
    pub in_bookmarks: Vec<String>,
361
    pub in_tags: Vec<String>,
362
    pub files: Vec<FileChange>,
363
}
364
365
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
366
pub struct History {
367
    pub reference: String,
368
    pub heads: Vec<String>,
369
    pub total: usize,
370
    pub offset: usize,
371
    pub changes: Vec<ChangeSummary>,
372
}
373
374
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
375
pub struct Conflict {
376
    pub bookmark: String,
377
    pub path: String,
378
    pub kind: String,
379
    pub contributors: Vec<String>,
380
}
381
382
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
383
pub struct Push {
384
    pub at_ms: i64,
385
    pub pusher: String,
386
    pub reference: String,
387
    pub ok: bool,
388
    pub reason: String,
389
    pub old_state: String,
390
    pub new_state: String,
391
    pub heads: i64,
392
    pub changes: i64,
393
}
394
395
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
396
pub struct Trust {
397
    pub policy: Option<Policy>,
398
    pub signed: usize,
399
    pub sealed: usize,
400
    pub unsigned: usize,
401
    pub invalid: Vec<String>,
402
    pub hub_key: String,
403
}
404
405
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
406
pub struct Policy {
407
    pub serial: u64,
408
    pub expires_ms: u64,
409
    pub roots: Vec<String>,
410
    pub root_threshold: u32,
411
    pub rules: Vec<Rule>,
412
}
413
414
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
415
pub struct Rule {
416
    pub pattern: String,
417
    pub keys: Vec<String>,
418
    pub threshold: u32,
419
    pub require: String,
420
    pub allow_conflicts: bool,
421
}
422
423
// ---------------------------------------------------------- hooks, checks
424
425
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
426
pub struct Hook {
427
    pub id: i64,
428
    pub url: String,
429
    pub events: String,
430
    pub active: bool,
431
    pub created_ms: i64,
432
}
433
434
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
435
pub struct NewHook {
436
    pub url: String,
437
    pub secret: String,
438
    #[serde(default = "star")]
439
    pub events: String,
440
}
441
442
fn star() -> String {
443
    "*".into()
444
}
445
446
/// An OxygenFlow run (hub spec §13.2).
447
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
448
pub struct FlowRun {
449
    /// The run's number within its repository.
450
    pub number: i64,
451
    pub bookmark: String,
452
    /// The state's hash, as checks are keyed.
453
    pub state: String,
454
    /// Its heads, full change hashes.
455
    pub heads: Vec<String>,
456
    /// `queued`, `running`, `passed`, `failed` or `error` (an invalid pipeline).
457
    pub status: String,
458
    /// `push`, `manual` or `rerun:N`.
459
    pub trigger: String,
460
    pub actor: String,
461
    pub pipeline_hash: String,
462
    /// An invalid pipeline's problems.
463
    pub error: String,
464
    pub created_ms: i64,
465
    pub finished_ms: Option<i64>,
466
    pub url: String,
467
    /// For a run waiting for a runner, its first queued job's 1-based
468
    /// place among all queued jobs.
469
    #[serde(default, skip_serializing_if = "Option::is_none")]
470
    pub queue_position: Option<i64>,
471
    /// Filled by the single-run endpoint.
472
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
473
    pub jobs: Vec<FlowJob>,
474
}
475
476
/// A job of a run.
477
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
478
pub struct FlowJob {
479
    pub name: String,
480
    /// `queued`, `running`, `passed`, `failed`, `skipped` or `error`.
481
    pub status: String,
482
    pub depends_on: Vec<String>,
483
    pub runner: String,
484
    pub exit_code: Option<i64>,
485
    pub error: String,
486
    pub started_ms: Option<i64>,
487
    pub finished_ms: Option<i64>,
488
    /// Log lines stored so far.
489
    pub log_lines: i64,
490
}
491
492
/// A line of a job's log.
493
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
494
pub struct FlowLogLine {
495
    /// Increasing within the job; pass the last one as `after` for more.
496
    pub seq: i64,
497
    /// Milliseconds since the job started.
498
    pub t: i64,
499
    /// `stdout`, `stderr` or `flow` (the runner's own notes).
500
    pub stream: String,
501
    pub text: String,
502
}
503
504
/// A check on a state hash (hub spec §13.1).
505
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
506
pub struct Check {
507
    pub state: String,
508
    pub name: String,
509
    pub status: CheckStatus,
510
    pub summary: String,
511
    pub url: String,
512
    pub reporter: String,
513
    /// The seal attestation's reference when the checker sealed the changes.
514
    pub seal: Option<String>,
515
    pub started_ms: i64,
516
    pub finished_ms: Option<i64>,
517
}
518
519
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
520
#[serde(rename_all = "lowercase")]
521
pub enum CheckStatus {
522
    Queued,
523
    Running,
524
    Passed,
525
    Failed,
526
    Cancelled,
527
    Skipped,
528
}
529
530
impl CheckStatus {
531
    pub fn as_str(self) -> &'static str {
532
        match self {
533
            CheckStatus::Queued => "queued",
534
            CheckStatus::Running => "running",
535
            CheckStatus::Passed => "passed",
536
            CheckStatus::Failed => "failed",
537
            CheckStatus::Cancelled => "cancelled",
538
            CheckStatus::Skipped => "skipped",
539
        }
540
    }
541
542
    pub fn parse(s: &str) -> Option<CheckStatus> {
543
        Some(match s {
544
            "queued" => CheckStatus::Queued,
545
            "running" => CheckStatus::Running,
546
            "passed" => CheckStatus::Passed,
547
            "failed" => CheckStatus::Failed,
548
            "cancelled" => CheckStatus::Cancelled,
549
            "skipped" => CheckStatus::Skipped,
550
            _ => return None,
551
        })
552
    }
553
}
554
555
/// What a checker posts.
556
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
557
pub struct NewCheck {
558
    pub state: String,
559
    pub name: String,
560
    pub status: CheckStatus,
561
    #[serde(default)]
562
    pub summary: String,
563
    #[serde(default)]
564
    pub url: String,
565
    /// Hex of a seal attestation reference the checker pushed, if any.
566
    #[serde(default)]
567
    pub seal: Option<String>,
568
}
569
570
// ------------------------------------------------------------- accounts
571
572
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
573
pub struct User {
574
    pub username: String,
575
    pub display_name: String,
576
    pub is_admin: bool,
577
    pub keys: Vec<String>,
578
    pub created_ms: i64,
579
}
580
581
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
582
pub struct Organisation {
583
    pub name: String,
584
    pub display_name: String,
585
    pub description: String,
586
    pub members: Vec<String>,
587
}
588
589
/// Forms accepted by the write endpoints.
590
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
591
pub struct NewRepository {
592
    pub owner: String,
593
    pub name: String,
594
    #[serde(default)]
595
    pub description: String,
596
    #[serde(default = "public")]
597
    pub visibility: Visibility,
598
}
599
600
fn public() -> Visibility {
601
    Visibility::Public
602
}
603
604
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
605
pub struct NewIssue {
606
    pub title: String,
607
    #[serde(default)]
608
    pub body: String,
609
    /// Label names; each must exist. Needs triage.
610
    #[serde(default)]
611
    pub labels: Vec<String>,
612
    /// Usernames. Needs triage.
613
    #[serde(default)]
614
    pub assignees: Vec<String>,
615
    /// A milestone's title. Needs triage.
616
    #[serde(default)]
617
    pub milestone: Option<String>,
618
}
619
620
/// `PATCH /repos/{o}/{n}/issues/{number}`: only the fields given change.
621
/// Title and body: the author or triage. The rest: triage.
622
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
623
pub struct IssueEdit {
624
    #[serde(default)]
625
    pub title: Option<String>,
626
    #[serde(default)]
627
    pub body: Option<String>,
628
    /// The whole set of labels.
629
    #[serde(default)]
630
    pub labels: Option<Vec<String>>,
631
    /// The whole set of assignees.
632
    #[serde(default)]
633
    pub assignees: Option<Vec<String>>,
634
    /// A milestone's title; the empty string clears it.
635
    #[serde(default)]
636
    pub milestone: Option<String>,
637
}
638
639
/// The checks a proposal needs, passed, to land on the repository's
640
/// default bookmark (hub spec §13.1). `GET` and `PUT
641
/// /repos/{o}/{n}/checks/required`.
642
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
643
pub struct RequiredChecks {
644
    pub names: Vec<String>,
645
}
646
647
/// A project (hub spec §8.2).
648
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
649
pub struct Project {
650
    pub owner: String,
651
    pub number: i64,
652
    pub title: String,
653
    pub description: String,
654
    pub public: bool,
655
    pub closed: bool,
656
    pub updated_ms: i64,
657
    /// The board on the hub, absolute.
658
    pub url: String,
659
}
660
661
/// A card as the caller may see it.
662
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
663
pub struct ProjectCard {
664
    pub id: i64,
665
    /// `issue`, `proposal` or `note`.
666
    pub kind: String,
667
    /// `owner/name#N`; empty for a note.
668
    pub reference: String,
669
    /// The issue's or proposal's title, or the note.
670
    pub title: String,
671
    /// The issue's or proposal's state; empty for a note.
672
    pub state: String,
673
}
674
675
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
676
pub struct ProjectColumn {
677
    pub id: i64,
678
    pub name: String,
679
    pub cards: Vec<ProjectCard>,
680
}
681
682
/// `GET /projects/{owner}/{n}`.
683
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
684
pub struct Board {
685
    pub project: Project,
686
    pub columns: Vec<ProjectColumn>,
687
}
688
689
/// `POST /projects/{owner}`.
690
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
691
pub struct NewProject {
692
    pub title: String,
693
    #[serde(default)]
694
    pub description: String,
695
    #[serde(default)]
696
    pub private: bool,
697
}
698
699
/// `PATCH /projects/{owner}/{n}`: only the fields given change.
700
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
701
pub struct ProjectEdit {
702
    #[serde(default)]
703
    pub title: Option<String>,
704
    #[serde(default)]
705
    pub description: Option<String>,
706
    #[serde(default)]
707
    pub private: Option<bool>,
708
    #[serde(default)]
709
    pub closed: Option<bool>,
710
}
711
712
/// `POST /projects/{owner}/{n}/cards`: a reference (`repo#12`) or a note,
713
/// into the column named (by id or name; the first column when absent).
714
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
715
pub struct NewCard {
716
    #[serde(default)]
717
    pub column: Option<String>,
718
    #[serde(default)]
719
    pub reference: String,
720
    #[serde(default)]
721
    pub note: String,
722
}
723
724
/// `PATCH /projects/{owner}/{n}/cards/{id}`: move to a column (id or name).
725
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
726
pub struct CardMove {
727
    pub column: String,
728
}
729
730
/// `POST /repos/{o}/{n}/labels`: create a label, or change one of that name.
731
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
732
pub struct NewLabel {
733
    pub name: String,
734
    /// `#rrggbb`; a default when absent.
735
    #[serde(default)]
736
    pub colour: Option<String>,
737
    #[serde(default)]
738
    pub description: String,
739
}
740
741
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
742
pub struct NewComment {
743
    pub body: String,
744
    /// For a proposal: anchor the comment to this file's line (1-based) of
745
    /// the projected state; the hub records the line's atom.
746
    #[serde(default)]
747
    pub path: Option<String>,
748
    #[serde(default)]
749
    pub line: Option<usize>,
750
}
751
752
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
753
pub struct NewProposal {
754
    pub title: String,
755
    #[serde(default)]
756
    pub body: String,
757
    pub target: String,
758
    /// A bookmark here, or `owner/name:bookmark` of a fork.
759
    pub source: String,
760
    #[serde(default)]
761
    pub draft: bool,
762
}
763
764
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
765
pub struct NewReview {
766
    pub verdict: String,
767
    #[serde(default)]
768
    pub body: String,
769
}
770
771
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
772
pub struct IssueStateChange {
773
    /// `open` or `closed`.
774
    pub state: String,
775
    #[serde(default)]
776
    pub reason: String,
777
}
778
779
/// A webhook payload's envelope (hub spec §12.2).
780
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
781
pub struct WebhookEnvelope {
782
    pub event: String,
783
    pub delivery: String,
784
    pub repository: Option<Repository>,
785
    pub actor: String,
786
    pub at_ms: i64,
787
    pub data: serde_json::Value,
788
}
789
790
/// A server-sent event on a proposal's stream.
791
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
792
pub struct ProposalEvent {
793
    pub number: i64,
794
    pub kind: String,
795
    pub check: Option<Check>,
796
}
797
798
// --------------------------------------------------------------- releases
799
800
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
801
pub struct Release {
802
    pub tag: String,
803
    pub title: String,
804
    pub notes: String,
805
    pub prerelease: bool,
806
    pub latest: bool,
807
    pub author: String,
808
    pub heads: Vec<String>,
809
    pub signer: Option<String>,
810
    pub assets: Vec<ReleaseAsset>,
811
    pub archives: Vec<String>,
812
    pub created_ms: i64,
813
    pub url: String,
814
}
815
816
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
817
pub struct ReleaseAsset {
818
    pub name: String,
819
    pub size: i64,
820
    /// BLAKE3 of the content, hex.
821
    pub hash: String,
822
    pub content_type: String,
823
    pub downloads: i64,
824
    pub url: String,
825
    /// The OxygenFlow run and job whose artifact has this content, if any.
826
    #[serde(default, skip_serializing_if = "Option::is_none")]
827
    pub built_by: Option<AssetBuild>,
828
}
829
830
/// Where a release asset was built (hub spec §9): a job's artifact with the
831
/// same BLAKE3, and that job's signed receipt when one was kept.
832
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
833
pub struct AssetBuild {
834
    pub run: i64,
835
    pub job: String,
836
    pub artifact: String,
837
    pub run_url: String,
838
    /// The receipt attestation, hex; `None` when the receipt was not signed.
839
    pub receipt: Option<String>,
840
    pub receipt_url: Option<String>,
841
    pub signer: Option<String>,
842
}
843
844
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
845
pub struct NewRelease {
846
    pub tag: String,
847
    pub title: String,
848
    #[serde(default)]
849
    pub notes: Option<String>,
850
    #[serde(default)]
851
    pub prerelease: bool,
852
}
853
854
/// Every type of the API, for schema generation.
855
pub fn schemas() -> Vec<(&'static str, schemars::Schema)> {
856
    vec![
857
        ("Repository", schemars::schema_for!(Repository)),
858
        ("Visibility", schemars::schema_for!(Visibility)),
859
        ("Bookmark", schemars::schema_for!(Bookmark)),
860
        ("Tag", schemars::schema_for!(Tag)),
861
        ("ChangeSummary", schemars::schema_for!(ChangeSummary)),
862
        ("Author", schemars::schema_for!(Author)),
863
        ("Signature", schemars::schema_for!(Signature)),
864
        ("Problem", schemars::schema_for!(Problem)),
865
        ("Proposal", schemars::schema_for!(Proposal)),
866
        ("ProposalState", schemars::schema_for!(ProposalState)),
867
        ("ProposalSource", schemars::schema_for!(ProposalSource)),
868
        ("Approval", schemars::schema_for!(Approval)),
869
        ("Issue", schemars::schema_for!(Issue)),
870
        ("Label", schemars::schema_for!(Label)),
871
        ("Milestone", schemars::schema_for!(Milestone)),
872
        ("Comment", schemars::schema_for!(Comment)),
873
        ("ProposalFile", schemars::schema_for!(ProposalFile)),
874
        ("Notification", schemars::schema_for!(Notification)),
875
        ("Inbox", schemars::schema_for!(Inbox)),
876
        ("Atom", schemars::schema_for!(Atom)),
877
        ("Review", schemars::schema_for!(Review)),
878
        ("TreeEntry", schemars::schema_for!(TreeEntry)),
879
        ("BlameLine", schemars::schema_for!(BlameLine)),
880
        ("FileChange", schemars::schema_for!(FileChange)),
881
        ("ChangeDetail", schemars::schema_for!(ChangeDetail)),
882
        ("History", schemars::schema_for!(History)),
883
        ("Conflict", schemars::schema_for!(Conflict)),
884
        ("Push", schemars::schema_for!(Push)),
885
        ("Trust", schemars::schema_for!(Trust)),
886
        ("Policy", schemars::schema_for!(Policy)),
887
        ("Rule", schemars::schema_for!(Rule)),
888
        ("Hook", schemars::schema_for!(Hook)),
889
        ("NewHook", schemars::schema_for!(NewHook)),
890
        ("Check", schemars::schema_for!(Check)),
891
        ("CheckStatus", schemars::schema_for!(CheckStatus)),
892
        ("NewCheck", schemars::schema_for!(NewCheck)),
893
        ("User", schemars::schema_for!(User)),
894
        ("Organisation", schemars::schema_for!(Organisation)),
895
        ("NewRepository", schemars::schema_for!(NewRepository)),
896
        ("NewIssue", schemars::schema_for!(NewIssue)),
897
        ("IssueEdit", schemars::schema_for!(IssueEdit)),
898
        ("NewLabel", schemars::schema_for!(NewLabel)),
899
        ("RequiredChecks", schemars::schema_for!(RequiredChecks)),
900
        ("Project", schemars::schema_for!(Project)),
901
        ("ProjectCard", schemars::schema_for!(ProjectCard)),
902
        ("ProjectColumn", schemars::schema_for!(ProjectColumn)),
903
        ("Board", schemars::schema_for!(Board)),
904
        ("NewProject", schemars::schema_for!(NewProject)),
905
        ("ProjectEdit", schemars::schema_for!(ProjectEdit)),
906
        ("NewCard", schemars::schema_for!(NewCard)),
907
        ("CardMove", schemars::schema_for!(CardMove)),
908
        ("NewComment", schemars::schema_for!(NewComment)),
909
        ("NewProposal", schemars::schema_for!(NewProposal)),
910
        ("NewReview", schemars::schema_for!(NewReview)),
911
        ("IssueStateChange", schemars::schema_for!(IssueStateChange)),
912
        ("WebhookEnvelope", schemars::schema_for!(WebhookEnvelope)),
913
        ("ProposalEvent", schemars::schema_for!(ProposalEvent)),
914
        ("Release", schemars::schema_for!(Release)),
915
        ("ReleaseAsset", schemars::schema_for!(ReleaseAsset)),
916
        ("NewRelease", schemars::schema_for!(NewRelease)),
917
    ]
918
}
919
920
/// An OxygenFlow runner (`GET /api/v1/runners`, site administrators).
921
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
922
pub struct Runner {
923
    pub id: i64,
924
    pub name: String,
925
    /// `online`, `offline`, `draining` or `disabled`.
926
    pub status: String,
927
    /// What it serves: empty for the whole site, an owner, or `owner/name`.
928
    pub serves: String,
929
    pub arch: String,
930
    pub os: String,
931
    pub version: String,
932
    pub labels: Vec<String>,
933
    pub max_jobs: i64,
934
    pub memory_mib: Option<i64>,
935
    pub cpus: Option<i64>,
936
    /// The key that signs its receipts (KeyId hex), empty until bound.
937
    pub key: String,
938
    /// `registered` or `config` (a hub.toml token).
939
    pub source: String,
940
    pub last_seen_ms: Option<i64>,
941
    /// Jobs it is running now.
942
    pub running: i64,
943
}
944
945
/// A job a runner ran or is running.
946
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
947
pub struct RunnerJob {
948
    pub repo: String,
949
    pub run: i64,
950
    pub job: String,
951
    pub status: String,
952
    pub started_ms: Option<i64>,
953
    pub finished_ms: Option<i64>,
954
}
955
956
/// A job in the queue: running ones first, then queued ones in the order
957
/// runners claim them.
958
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
959
pub struct QueueItem {
960
    pub repo: String,
961
    pub run: i64,
962
    pub job: String,
963
    /// `running` or `queued`.
964
    pub status: String,
965
    /// The runner holding it, when running.
966
    pub runner: String,
967
}