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