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