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