OXYGENHUB
# a0d4bbfbedd1 oxygenhub / crates / hub-api / src / lib.rs
24.7 KiB · Rust · last changed Required checks over the API: GET and PUT /repos/{o}/{n}/checks/required (admins, the whole list, audited) 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
}
95
96
/// Signature status of a change as `oxy verify` reports it.
97
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
98
#[serde(tag = "status", rename_all = "lowercase")]
99
pub enum Signature {
100
    Unsigned,
101
    Valid { key: String, sealed: bool, revoked: bool },
102
    Invalid { reason: String },
103
}
104
105
/// An RFC 7807 problem response.
106
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
107
pub struct Problem {
108
    pub status: u16,
109
    pub title: String,
110
    pub detail: String,
111
}
112
113
#[cfg(test)]
114
mod tests {
115
    use super::*;
116
117
    #[test]
118
    fn visibility_round_trips() {
119
        for v in [Visibility::Public, Visibility::Internal, Visibility::Private] {
120
            assert_eq!(Visibility::parse(v.as_str()), Some(v));
121
        }
122
        assert_eq!(Visibility::parse("secret"), None);
123
    }
124
}
125
126
// ---------------------------------------------------------------- proposals
127
128
/// A proposal: a request to add changes to a target bookmark (hub spec §7).
129
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
130
pub struct Proposal {
131
    pub number: i64,
132
    pub title: String,
133
    pub body: String,
134
    pub author: String,
135
    pub state: ProposalState,
136
    pub target: String,
137
    pub source: ProposalSource,
138
    /// The changes the proposal adds, dependency order, newest last.
139
    pub changes: Vec<ChangeSummary>,
140
    /// Heads of the projected state (target plus the changes), when computed.
141
    pub projected_heads: Vec<String>,
142
    pub projected_state: Option<String>,
143
    pub conflicted: bool,
144
    pub approvals: Vec<Approval>,
145
    pub landable: bool,
146
    pub blockers: Vec<String>,
147
    pub created_ms: i64,
148
    pub updated_ms: i64,
149
    /// `https://hub/{owner}/{name}/proposal/{number}`.
150
    pub url: String,
151
    /// Where `oxy` fetches the changes from.
152
    pub repository_url: String,
153
    /// The fork's clone URL when the source is a fork.
154
    pub source_url: Option<String>,
155
}
156
157
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
158
#[serde(rename_all = "lowercase")]
159
pub enum ProposalState {
160
    Draft,
161
    Open,
162
    Landed,
163
    Closed,
164
}
165
166
impl ProposalState {
167
    pub fn as_str(self) -> &'static str {
168
        match self {
169
            ProposalState::Draft => "draft",
170
            ProposalState::Open => "open",
171
            ProposalState::Landed => "landed",
172
            ProposalState::Closed => "closed",
173
        }
174
    }
175
176
    pub fn parse(s: &str) -> Option<ProposalState> {
177
        Some(match s {
178
            "draft" => ProposalState::Draft,
179
            "open" => ProposalState::Open,
180
            "landed" => ProposalState::Landed,
181
            "closed" => ProposalState::Closed,
182
            _ => return None,
183
        })
184
    }
185
}
186
187
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
188
#[serde(tag = "kind", rename_all = "lowercase")]
189
pub enum ProposalSource {
190
    /// A bookmark of the same repository.
191
    Bookmark { bookmark: String },
192
    /// A bookmark of a fork.
193
    Fork { owner: String, name: String, bookmark: String },
194
    /// An explicit list of change hashes.
195
    Changes { hashes: Vec<String> },
196
}
197
198
/// A reviewer's approval, counted only when backed by a seal over every
199
/// change of the proposal signed with a key linked to the reviewer.
200
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
201
pub struct Approval {
202
    pub account: String,
203
    pub sealed: bool,
204
    pub key: Option<String>,
205
}
206
207
// ------------------------------------------------------------------ issues
208
209
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
210
pub struct Issue {
211
    pub number: i64,
212
    pub title: String,
213
    pub body: String,
214
    pub author: String,
215
    pub state: String,
216
    pub reason: String,
217
    pub labels: Vec<Label>,
218
    pub assignees: Vec<String>,
219
    pub milestone: Option<String>,
220
    pub comments: i64,
221
    pub locked: bool,
222
    pub pinned: bool,
223
    pub created_ms: i64,
224
    pub updated_ms: i64,
225
    pub closed_ms: Option<i64>,
226
    pub url: String,
227
}
228
229
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
230
pub struct Label {
231
    pub name: String,
232
    pub colour: String,
233
    pub description: String,
234
}
235
236
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
237
pub struct Milestone {
238
    pub title: String,
239
    pub description: String,
240
    pub due_ms: Option<i64>,
241
    pub state: String,
242
    pub open: i64,
243
    pub closed: i64,
244
}
245
246
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
247
pub struct Comment {
248
    pub id: i64,
249
    pub author: String,
250
    pub body: String,
251
    pub created_ms: i64,
252
    /// For proposal comments: the file and the atom the comment anchors to.
253
    pub path: Option<String>,
254
    pub anchor: Option<Atom>,
255
    pub resolved: bool,
256
}
257
258
/// One entry in the caller's inbox (hub spec §10).
259
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
260
pub struct Notification {
261
    pub id: i64,
262
    pub at_ms: i64,
263
    /// `issue.opened`, `proposal.comment`, `mention`, `review`, …
264
    pub kind: String,
265
    pub title: String,
266
    /// The page on the hub, absolute.
267
    pub url: String,
268
    pub actor: String,
269
    pub read: bool,
270
}
271
272
/// `GET /notifications`: the unread count and the newest entries, unread first.
273
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
274
pub struct Inbox {
275
    pub unread: i64,
276
    pub items: Vec<Notification>,
277
}
278
279
/// A file a proposal changes, between the target's state and the
280
/// projected state (hub spec §7.2). Fetch either side's bytes from
281
/// `/proposals/{number}/content/{base|head}/{path}`.
282
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
283
pub struct ProposalFile {
284
    pub path: String,
285
    /// For a rename, the path in the target's state.
286
    pub from: Option<String>,
287
    /// `added`, `removed`, `modified`, `renamed`, `mode` or `replaced`.
288
    pub kind: String,
289
    pub added: usize,
290
    pub removed: usize,
291
}
292
293
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
294
pub struct Atom {
295
    pub change: String,
296
    pub index: u32,
297
}
298
299
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
300
pub struct Review {
301
    pub id: i64,
302
    pub author: String,
303
    pub verdict: String,
304
    pub body: String,
305
    pub sealed: bool,
306
    pub created_ms: i64,
307
}
308
309
// ------------------------------------------------------------- repository
310
311
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
312
pub struct TreeEntry {
313
    pub name: String,
314
    pub path: String,
315
    pub kind: String,
316
    pub exec: bool,
317
    pub size: Option<u64>,
318
    pub conflicted: bool,
319
}
320
321
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
322
pub struct BlameLine {
323
    pub line: usize,
324
    pub change: String,
325
    pub index: u32,
326
    pub author: String,
327
    pub when_ms: u64,
328
    pub text: String,
329
}
330
331
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
332
pub struct FileChange {
333
    pub path: String,
334
    pub kind: String,
335
    pub from: Option<String>,
336
    pub added: usize,
337
    pub removed: usize,
338
}
339
340
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
341
pub struct ChangeDetail {
342
    pub change: ChangeSummary,
343
    pub body: String,
344
    pub dependents: Vec<String>,
345
    pub in_bookmarks: Vec<String>,
346
    pub in_tags: Vec<String>,
347
    pub files: Vec<FileChange>,
348
}
349
350
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
351
pub struct History {
352
    pub reference: String,
353
    pub heads: Vec<String>,
354
    pub total: usize,
355
    pub offset: usize,
356
    pub changes: Vec<ChangeSummary>,
357
}
358
359
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
360
pub struct Conflict {
361
    pub bookmark: String,
362
    pub path: String,
363
    pub kind: String,
364
    pub contributors: Vec<String>,
365
}
366
367
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
368
pub struct Push {
369
    pub at_ms: i64,
370
    pub pusher: String,
371
    pub reference: String,
372
    pub ok: bool,
373
    pub reason: String,
374
    pub old_state: String,
375
    pub new_state: String,
376
    pub heads: i64,
377
    pub changes: i64,
378
}
379
380
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
381
pub struct Trust {
382
    pub policy: Option<Policy>,
383
    pub signed: usize,
384
    pub sealed: usize,
385
    pub unsigned: usize,
386
    pub invalid: Vec<String>,
387
    pub hub_key: String,
388
}
389
390
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
391
pub struct Policy {
392
    pub serial: u64,
393
    pub expires_ms: u64,
394
    pub roots: Vec<String>,
395
    pub root_threshold: u32,
396
    pub rules: Vec<Rule>,
397
}
398
399
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
400
pub struct Rule {
401
    pub pattern: String,
402
    pub keys: Vec<String>,
403
    pub threshold: u32,
404
    pub require: String,
405
    pub allow_conflicts: bool,
406
}
407
408
// ---------------------------------------------------------- hooks, checks
409
410
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
411
pub struct Hook {
412
    pub id: i64,
413
    pub url: String,
414
    pub events: String,
415
    pub active: bool,
416
    pub created_ms: i64,
417
}
418
419
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
420
pub struct NewHook {
421
    pub url: String,
422
    pub secret: String,
423
    #[serde(default = "star")]
424
    pub events: String,
425
}
426
427
fn star() -> String {
428
    "*".into()
429
}
430
431
/// A check on a state hash (hub spec §13.1).
432
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
433
pub struct Check {
434
    pub state: String,
435
    pub name: String,
436
    pub status: CheckStatus,
437
    pub summary: String,
438
    pub url: String,
439
    pub reporter: String,
440
    /// The seal attestation's reference when the checker sealed the changes.
441
    pub seal: Option<String>,
442
    pub started_ms: i64,
443
    pub finished_ms: Option<i64>,
444
}
445
446
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
447
#[serde(rename_all = "lowercase")]
448
pub enum CheckStatus {
449
    Queued,
450
    Running,
451
    Passed,
452
    Failed,
453
    Cancelled,
454
    Skipped,
455
}
456
457
impl CheckStatus {
458
    pub fn as_str(self) -> &'static str {
459
        match self {
460
            CheckStatus::Queued => "queued",
461
            CheckStatus::Running => "running",
462
            CheckStatus::Passed => "passed",
463
            CheckStatus::Failed => "failed",
464
            CheckStatus::Cancelled => "cancelled",
465
            CheckStatus::Skipped => "skipped",
466
        }
467
    }
468
469
    pub fn parse(s: &str) -> Option<CheckStatus> {
470
        Some(match s {
471
            "queued" => CheckStatus::Queued,
472
            "running" => CheckStatus::Running,
473
            "passed" => CheckStatus::Passed,
474
            "failed" => CheckStatus::Failed,
475
            "cancelled" => CheckStatus::Cancelled,
476
            "skipped" => CheckStatus::Skipped,
477
            _ => return None,
478
        })
479
    }
480
}
481
482
/// What a checker posts.
483
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
484
pub struct NewCheck {
485
    pub state: String,
486
    pub name: String,
487
    pub status: CheckStatus,
488
    #[serde(default)]
489
    pub summary: String,
490
    #[serde(default)]
491
    pub url: String,
492
    /// Hex of a seal attestation reference the checker pushed, if any.
493
    #[serde(default)]
494
    pub seal: Option<String>,
495
}
496
497
// ------------------------------------------------------------- accounts
498
499
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
500
pub struct User {
501
    pub username: String,
502
    pub display_name: String,
503
    pub is_admin: bool,
504
    pub keys: Vec<String>,
505
    pub created_ms: i64,
506
}
507
508
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
509
pub struct Organisation {
510
    pub name: String,
511
    pub display_name: String,
512
    pub description: String,
513
    pub members: Vec<String>,
514
}
515
516
/// Forms accepted by the write endpoints.
517
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
518
pub struct NewRepository {
519
    pub owner: String,
520
    pub name: String,
521
    #[serde(default)]
522
    pub description: String,
523
    #[serde(default = "public")]
524
    pub visibility: Visibility,
525
}
526
527
fn public() -> Visibility {
528
    Visibility::Public
529
}
530
531
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
532
pub struct NewIssue {
533
    pub title: String,
534
    #[serde(default)]
535
    pub body: String,
536
    /// Label names; each must exist. Needs triage.
537
    #[serde(default)]
538
    pub labels: Vec<String>,
539
    /// Usernames. Needs triage.
540
    #[serde(default)]
541
    pub assignees: Vec<String>,
542
    /// A milestone's title. Needs triage.
543
    #[serde(default)]
544
    pub milestone: Option<String>,
545
}
546
547
/// `PATCH /repos/{o}/{n}/issues/{number}`: only the fields given change.
548
/// Title and body: the author or triage. The rest: triage.
549
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
550
pub struct IssueEdit {
551
    #[serde(default)]
552
    pub title: Option<String>,
553
    #[serde(default)]
554
    pub body: Option<String>,
555
    /// The whole set of labels.
556
    #[serde(default)]
557
    pub labels: Option<Vec<String>>,
558
    /// The whole set of assignees.
559
    #[serde(default)]
560
    pub assignees: Option<Vec<String>>,
561
    /// A milestone's title; the empty string clears it.
562
    #[serde(default)]
563
    pub milestone: Option<String>,
564
}
565
566
/// The checks a proposal needs, passed, to land on the repository's
567
/// default bookmark (hub spec §13.1). `GET` and `PUT
568
/// /repos/{o}/{n}/checks/required`.
569
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
570
pub struct RequiredChecks {
571
    pub names: Vec<String>,
572
}
573
574
/// A project (hub spec §8.2).
575
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
576
pub struct Project {
577
    pub owner: String,
578
    pub number: i64,
579
    pub title: String,
580
    pub description: String,
581
    pub public: bool,
582
    pub closed: bool,
583
    pub updated_ms: i64,
584
    /// The board on the hub, absolute.
585
    pub url: String,
586
}
587
588
/// A card as the caller may see it.
589
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
590
pub struct ProjectCard {
591
    pub id: i64,
592
    /// `issue`, `proposal` or `note`.
593
    pub kind: String,
594
    /// `owner/name#N`; empty for a note.
595
    pub reference: String,
596
    /// The issue's or proposal's title, or the note.
597
    pub title: String,
598
    /// The issue's or proposal's state; empty for a note.
599
    pub state: String,
600
}
601
602
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
603
pub struct ProjectColumn {
604
    pub id: i64,
605
    pub name: String,
606
    pub cards: Vec<ProjectCard>,
607
}
608
609
/// `GET /projects/{owner}/{n}`.
610
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
611
pub struct Board {
612
    pub project: Project,
613
    pub columns: Vec<ProjectColumn>,
614
}
615
616
/// `POST /projects/{owner}`.
617
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
618
pub struct NewProject {
619
    pub title: String,
620
    #[serde(default)]
621
    pub description: String,
622
    #[serde(default)]
623
    pub private: bool,
624
}
625
626
/// `PATCH /projects/{owner}/{n}`: only the fields given change.
627
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
628
pub struct ProjectEdit {
629
    #[serde(default)]
630
    pub title: Option<String>,
631
    #[serde(default)]
632
    pub description: Option<String>,
633
    #[serde(default)]
634
    pub private: Option<bool>,
635
    #[serde(default)]
636
    pub closed: Option<bool>,
637
}
638
639
/// `POST /projects/{owner}/{n}/cards`: a reference (`repo#12`) or a note,
640
/// into the column named (by id or name; the first column when absent).
641
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
642
pub struct NewCard {
643
    #[serde(default)]
644
    pub column: Option<String>,
645
    #[serde(default)]
646
    pub reference: String,
647
    #[serde(default)]
648
    pub note: String,
649
}
650
651
/// `PATCH /projects/{owner}/{n}/cards/{id}`: move to a column (id or name).
652
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
653
pub struct CardMove {
654
    pub column: String,
655
}
656
657
/// `POST /repos/{o}/{n}/labels`: create a label, or change one of that name.
658
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
659
pub struct NewLabel {
660
    pub name: String,
661
    /// `#rrggbb`; a default when absent.
662
    #[serde(default)]
663
    pub colour: Option<String>,
664
    #[serde(default)]
665
    pub description: String,
666
}
667
668
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
669
pub struct NewComment {
670
    pub body: String,
671
    /// For a proposal: anchor the comment to this file's line (1-based) of
672
    /// the projected state; the hub records the line's atom.
673
    #[serde(default)]
674
    pub path: Option<String>,
675
    #[serde(default)]
676
    pub line: Option<usize>,
677
}
678
679
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
680
pub struct NewProposal {
681
    pub title: String,
682
    #[serde(default)]
683
    pub body: String,
684
    pub target: String,
685
    /// A bookmark here, or `owner/name:bookmark` of a fork.
686
    pub source: String,
687
    #[serde(default)]
688
    pub draft: bool,
689
}
690
691
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
692
pub struct NewReview {
693
    pub verdict: String,
694
    #[serde(default)]
695
    pub body: String,
696
}
697
698
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
699
pub struct IssueStateChange {
700
    /// `open` or `closed`.
701
    pub state: String,
702
    #[serde(default)]
703
    pub reason: String,
704
}
705
706
/// A webhook payload's envelope (hub spec §12.2).
707
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
708
pub struct WebhookEnvelope {
709
    pub event: String,
710
    pub delivery: String,
711
    pub repository: Option<Repository>,
712
    pub actor: String,
713
    pub at_ms: i64,
714
    pub data: serde_json::Value,
715
}
716
717
/// A server-sent event on a proposal's stream.
718
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
719
pub struct ProposalEvent {
720
    pub number: i64,
721
    pub kind: String,
722
    pub check: Option<Check>,
723
}
724
725
// --------------------------------------------------------------- releases
726
727
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
728
pub struct Release {
729
    pub tag: String,
730
    pub title: String,
731
    pub notes: String,
732
    pub prerelease: bool,
733
    pub latest: bool,
734
    pub author: String,
735
    pub heads: Vec<String>,
736
    pub signer: Option<String>,
737
    pub assets: Vec<ReleaseAsset>,
738
    pub archives: Vec<String>,
739
    pub created_ms: i64,
740
    pub url: String,
741
}
742
743
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
744
pub struct ReleaseAsset {
745
    pub name: String,
746
    pub size: i64,
747
    /// BLAKE3 of the content, hex.
748
    pub hash: String,
749
    pub content_type: String,
750
    pub downloads: i64,
751
    pub url: String,
752
}
753
754
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
755
pub struct NewRelease {
756
    pub tag: String,
757
    pub title: String,
758
    #[serde(default)]
759
    pub notes: Option<String>,
760
    #[serde(default)]
761
    pub prerelease: bool,
762
}
763
764
/// Every type of the API, for schema generation.
765
pub fn schemas() -> Vec<(&'static str, schemars::Schema)> {
766
    vec![
767
        ("Repository", schemars::schema_for!(Repository)),
768
        ("Visibility", schemars::schema_for!(Visibility)),
769
        ("Bookmark", schemars::schema_for!(Bookmark)),
770
        ("Tag", schemars::schema_for!(Tag)),
771
        ("ChangeSummary", schemars::schema_for!(ChangeSummary)),
772
        ("Author", schemars::schema_for!(Author)),
773
        ("Signature", schemars::schema_for!(Signature)),
774
        ("Problem", schemars::schema_for!(Problem)),
775
        ("Proposal", schemars::schema_for!(Proposal)),
776
        ("ProposalState", schemars::schema_for!(ProposalState)),
777
        ("ProposalSource", schemars::schema_for!(ProposalSource)),
778
        ("Approval", schemars::schema_for!(Approval)),
779
        ("Issue", schemars::schema_for!(Issue)),
780
        ("Label", schemars::schema_for!(Label)),
781
        ("Milestone", schemars::schema_for!(Milestone)),
782
        ("Comment", schemars::schema_for!(Comment)),
783
        ("ProposalFile", schemars::schema_for!(ProposalFile)),
784
        ("Notification", schemars::schema_for!(Notification)),
785
        ("Inbox", schemars::schema_for!(Inbox)),
786
        ("Atom", schemars::schema_for!(Atom)),
787
        ("Review", schemars::schema_for!(Review)),
788
        ("TreeEntry", schemars::schema_for!(TreeEntry)),
789
        ("BlameLine", schemars::schema_for!(BlameLine)),
790
        ("FileChange", schemars::schema_for!(FileChange)),
791
        ("ChangeDetail", schemars::schema_for!(ChangeDetail)),
792
        ("History", schemars::schema_for!(History)),
793
        ("Conflict", schemars::schema_for!(Conflict)),
794
        ("Push", schemars::schema_for!(Push)),
795
        ("Trust", schemars::schema_for!(Trust)),
796
        ("Policy", schemars::schema_for!(Policy)),
797
        ("Rule", schemars::schema_for!(Rule)),
798
        ("Hook", schemars::schema_for!(Hook)),
799
        ("NewHook", schemars::schema_for!(NewHook)),
800
        ("Check", schemars::schema_for!(Check)),
801
        ("CheckStatus", schemars::schema_for!(CheckStatus)),
802
        ("NewCheck", schemars::schema_for!(NewCheck)),
803
        ("User", schemars::schema_for!(User)),
804
        ("Organisation", schemars::schema_for!(Organisation)),
805
        ("NewRepository", schemars::schema_for!(NewRepository)),
806
        ("NewIssue", schemars::schema_for!(NewIssue)),
807
        ("IssueEdit", schemars::schema_for!(IssueEdit)),
808
        ("NewLabel", schemars::schema_for!(NewLabel)),
809
        ("RequiredChecks", schemars::schema_for!(RequiredChecks)),
810
        ("Project", schemars::schema_for!(Project)),
811
        ("ProjectCard", schemars::schema_for!(ProjectCard)),
812
        ("ProjectColumn", schemars::schema_for!(ProjectColumn)),
813
        ("Board", schemars::schema_for!(Board)),
814
        ("NewProject", schemars::schema_for!(NewProject)),
815
        ("ProjectEdit", schemars::schema_for!(ProjectEdit)),
816
        ("NewCard", schemars::schema_for!(NewCard)),
817
        ("CardMove", schemars::schema_for!(CardMove)),
818
        ("NewComment", schemars::schema_for!(NewComment)),
819
        ("NewProposal", schemars::schema_for!(NewProposal)),
820
        ("NewReview", schemars::schema_for!(NewReview)),
821
        ("IssueStateChange", schemars::schema_for!(IssueStateChange)),
822
        ("WebhookEnvelope", schemars::schema_for!(WebhookEnvelope)),
823
        ("ProposalEvent", schemars::schema_for!(ProposalEvent)),
824
        ("Release", schemars::schema_for!(Release)),
825
        ("ReleaseAsset", schemars::schema_for!(ReleaseAsset)),
826
        ("NewRelease", schemars::schema_for!(NewRelease)),
827
    ]
828
}