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