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