OXYGENHUB
# 90326c9601f9 oxygenhub / crates / hub-api / src / lib.rs
26.4 KiB · Rust · last changed Flow runs, jobs and logs in the API; checks by heads 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
/// An OxygenFlow run (hub spec §13.2).
432
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
433
pub struct FlowRun {
434
    /// The run's number within its repository.
435
    pub number: i64,
436
    pub bookmark: String,
437
    /// The state's hash, as checks are keyed.
438
    pub state: String,
439
    /// Its heads, full change hashes.
440
    pub heads: Vec<String>,
441
    /// `queued`, `running`, `passed`, `failed` or `error` (an invalid pipeline).
442
    pub status: String,
443
    /// `push`, `manual` or `rerun:N`.
444
    pub trigger: String,
445
    pub actor: String,
446
    pub pipeline_hash: String,
447
    /// An invalid pipeline's problems.
448
    pub error: String,
449
    pub created_ms: i64,
450
    pub finished_ms: Option<i64>,
451
    pub url: String,
452
    /// Filled by the single-run endpoint.
453
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
454
    pub jobs: Vec<FlowJob>,
455
}
456
457
/// A job of a run.
458
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
459
pub struct FlowJob {
460
    pub name: String,
461
    /// `queued`, `running`, `passed`, `failed`, `skipped` or `error`.
462
    pub status: String,
463
    pub depends_on: Vec<String>,
464
    pub runner: String,
465
    pub exit_code: Option<i64>,
466
    pub error: String,
467
    pub started_ms: Option<i64>,
468
    pub finished_ms: Option<i64>,
469
    /// Log lines stored so far.
470
    pub log_lines: i64,
471
}
472
473
/// A line of a job's log.
474
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
475
pub struct FlowLogLine {
476
    /// Increasing within the job; pass the last one as `after` for more.
477
    pub seq: i64,
478
    /// Milliseconds since the job started.
479
    pub t: i64,
480
    /// `stdout`, `stderr` or `flow` (the runner's own notes).
481
    pub stream: String,
482
    pub text: String,
483
}
484
485
/// A check on a state hash (hub spec §13.1).
486
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
487
pub struct Check {
488
    pub state: String,
489
    pub name: String,
490
    pub status: CheckStatus,
491
    pub summary: String,
492
    pub url: String,
493
    pub reporter: String,
494
    /// The seal attestation's reference when the checker sealed the changes.
495
    pub seal: Option<String>,
496
    pub started_ms: i64,
497
    pub finished_ms: Option<i64>,
498
}
499
500
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
501
#[serde(rename_all = "lowercase")]
502
pub enum CheckStatus {
503
    Queued,
504
    Running,
505
    Passed,
506
    Failed,
507
    Cancelled,
508
    Skipped,
509
}
510
511
impl CheckStatus {
512
    pub fn as_str(self) -> &'static str {
513
        match self {
514
            CheckStatus::Queued => "queued",
515
            CheckStatus::Running => "running",
516
            CheckStatus::Passed => "passed",
517
            CheckStatus::Failed => "failed",
518
            CheckStatus::Cancelled => "cancelled",
519
            CheckStatus::Skipped => "skipped",
520
        }
521
    }
522
523
    pub fn parse(s: &str) -> Option<CheckStatus> {
524
        Some(match s {
525
            "queued" => CheckStatus::Queued,
526
            "running" => CheckStatus::Running,
527
            "passed" => CheckStatus::Passed,
528
            "failed" => CheckStatus::Failed,
529
            "cancelled" => CheckStatus::Cancelled,
530
            "skipped" => CheckStatus::Skipped,
531
            _ => return None,
532
        })
533
    }
534
}
535
536
/// What a checker posts.
537
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
538
pub struct NewCheck {
539
    pub state: String,
540
    pub name: String,
541
    pub status: CheckStatus,
542
    #[serde(default)]
543
    pub summary: String,
544
    #[serde(default)]
545
    pub url: String,
546
    /// Hex of a seal attestation reference the checker pushed, if any.
547
    #[serde(default)]
548
    pub seal: Option<String>,
549
}
550
551
// ------------------------------------------------------------- accounts
552
553
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
554
pub struct User {
555
    pub username: String,
556
    pub display_name: String,
557
    pub is_admin: bool,
558
    pub keys: Vec<String>,
559
    pub created_ms: i64,
560
}
561
562
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
563
pub struct Organisation {
564
    pub name: String,
565
    pub display_name: String,
566
    pub description: String,
567
    pub members: Vec<String>,
568
}
569
570
/// Forms accepted by the write endpoints.
571
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
572
pub struct NewRepository {
573
    pub owner: String,
574
    pub name: String,
575
    #[serde(default)]
576
    pub description: String,
577
    #[serde(default = "public")]
578
    pub visibility: Visibility,
579
}
580
581
fn public() -> Visibility {
582
    Visibility::Public
583
}
584
585
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
586
pub struct NewIssue {
587
    pub title: String,
588
    #[serde(default)]
589
    pub body: String,
590
    /// Label names; each must exist. Needs triage.
591
    #[serde(default)]
592
    pub labels: Vec<String>,
593
    /// Usernames. Needs triage.
594
    #[serde(default)]
595
    pub assignees: Vec<String>,
596
    /// A milestone's title. Needs triage.
597
    #[serde(default)]
598
    pub milestone: Option<String>,
599
}
600
601
/// `PATCH /repos/{o}/{n}/issues/{number}`: only the fields given change.
602
/// Title and body: the author or triage. The rest: triage.
603
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
604
pub struct IssueEdit {
605
    #[serde(default)]
606
    pub title: Option<String>,
607
    #[serde(default)]
608
    pub body: Option<String>,
609
    /// The whole set of labels.
610
    #[serde(default)]
611
    pub labels: Option<Vec<String>>,
612
    /// The whole set of assignees.
613
    #[serde(default)]
614
    pub assignees: Option<Vec<String>>,
615
    /// A milestone's title; the empty string clears it.
616
    #[serde(default)]
617
    pub milestone: Option<String>,
618
}
619
620
/// The checks a proposal needs, passed, to land on the repository's
621
/// default bookmark (hub spec §13.1). `GET` and `PUT
622
/// /repos/{o}/{n}/checks/required`.
623
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
624
pub struct RequiredChecks {
625
    pub names: Vec<String>,
626
}
627
628
/// A project (hub spec §8.2).
629
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
630
pub struct Project {
631
    pub owner: String,
632
    pub number: i64,
633
    pub title: String,
634
    pub description: String,
635
    pub public: bool,
636
    pub closed: bool,
637
    pub updated_ms: i64,
638
    /// The board on the hub, absolute.
639
    pub url: String,
640
}
641
642
/// A card as the caller may see it.
643
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
644
pub struct ProjectCard {
645
    pub id: i64,
646
    /// `issue`, `proposal` or `note`.
647
    pub kind: String,
648
    /// `owner/name#N`; empty for a note.
649
    pub reference: String,
650
    /// The issue's or proposal's title, or the note.
651
    pub title: String,
652
    /// The issue's or proposal's state; empty for a note.
653
    pub state: String,
654
}
655
656
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
657
pub struct ProjectColumn {
658
    pub id: i64,
659
    pub name: String,
660
    pub cards: Vec<ProjectCard>,
661
}
662
663
/// `GET /projects/{owner}/{n}`.
664
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
665
pub struct Board {
666
    pub project: Project,
667
    pub columns: Vec<ProjectColumn>,
668
}
669
670
/// `POST /projects/{owner}`.
671
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
672
pub struct NewProject {
673
    pub title: String,
674
    #[serde(default)]
675
    pub description: String,
676
    #[serde(default)]
677
    pub private: bool,
678
}
679
680
/// `PATCH /projects/{owner}/{n}`: only the fields given change.
681
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
682
pub struct ProjectEdit {
683
    #[serde(default)]
684
    pub title: Option<String>,
685
    #[serde(default)]
686
    pub description: Option<String>,
687
    #[serde(default)]
688
    pub private: Option<bool>,
689
    #[serde(default)]
690
    pub closed: Option<bool>,
691
}
692
693
/// `POST /projects/{owner}/{n}/cards`: a reference (`repo#12`) or a note,
694
/// into the column named (by id or name; the first column when absent).
695
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
696
pub struct NewCard {
697
    #[serde(default)]
698
    pub column: Option<String>,
699
    #[serde(default)]
700
    pub reference: String,
701
    #[serde(default)]
702
    pub note: String,
703
}
704
705
/// `PATCH /projects/{owner}/{n}/cards/{id}`: move to a column (id or name).
706
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
707
pub struct CardMove {
708
    pub column: String,
709
}
710
711
/// `POST /repos/{o}/{n}/labels`: create a label, or change one of that name.
712
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
713
pub struct NewLabel {
714
    pub name: String,
715
    /// `#rrggbb`; a default when absent.
716
    #[serde(default)]
717
    pub colour: Option<String>,
718
    #[serde(default)]
719
    pub description: String,
720
}
721
722
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
723
pub struct NewComment {
724
    pub body: String,
725
    /// For a proposal: anchor the comment to this file's line (1-based) of
726
    /// the projected state; the hub records the line's atom.
727
    #[serde(default)]
728
    pub path: Option<String>,
729
    #[serde(default)]
730
    pub line: Option<usize>,
731
}
732
733
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
734
pub struct NewProposal {
735
    pub title: String,
736
    #[serde(default)]
737
    pub body: String,
738
    pub target: String,
739
    /// A bookmark here, or `owner/name:bookmark` of a fork.
740
    pub source: String,
741
    #[serde(default)]
742
    pub draft: bool,
743
}
744
745
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
746
pub struct NewReview {
747
    pub verdict: String,
748
    #[serde(default)]
749
    pub body: String,
750
}
751
752
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
753
pub struct IssueStateChange {
754
    /// `open` or `closed`.
755
    pub state: String,
756
    #[serde(default)]
757
    pub reason: String,
758
}
759
760
/// A webhook payload's envelope (hub spec §12.2).
761
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
762
pub struct WebhookEnvelope {
763
    pub event: String,
764
    pub delivery: String,
765
    pub repository: Option<Repository>,
766
    pub actor: String,
767
    pub at_ms: i64,
768
    pub data: serde_json::Value,
769
}
770
771
/// A server-sent event on a proposal's stream.
772
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
773
pub struct ProposalEvent {
774
    pub number: i64,
775
    pub kind: String,
776
    pub check: Option<Check>,
777
}
778
779
// --------------------------------------------------------------- releases
780
781
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
782
pub struct Release {
783
    pub tag: String,
784
    pub title: String,
785
    pub notes: String,
786
    pub prerelease: bool,
787
    pub latest: bool,
788
    pub author: String,
789
    pub heads: Vec<String>,
790
    pub signer: Option<String>,
791
    pub assets: Vec<ReleaseAsset>,
792
    pub archives: Vec<String>,
793
    pub created_ms: i64,
794
    pub url: String,
795
}
796
797
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
798
pub struct ReleaseAsset {
799
    pub name: String,
800
    pub size: i64,
801
    /// BLAKE3 of the content, hex.
802
    pub hash: String,
803
    pub content_type: String,
804
    pub downloads: i64,
805
    pub url: String,
806
}
807
808
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
809
pub struct NewRelease {
810
    pub tag: String,
811
    pub title: String,
812
    #[serde(default)]
813
    pub notes: Option<String>,
814
    #[serde(default)]
815
    pub prerelease: bool,
816
}
817
818
/// Every type of the API, for schema generation.
819
pub fn schemas() -> Vec<(&'static str, schemars::Schema)> {
820
    vec![
821
        ("Repository", schemars::schema_for!(Repository)),
822
        ("Visibility", schemars::schema_for!(Visibility)),
823
        ("Bookmark", schemars::schema_for!(Bookmark)),
824
        ("Tag", schemars::schema_for!(Tag)),
825
        ("ChangeSummary", schemars::schema_for!(ChangeSummary)),
826
        ("Author", schemars::schema_for!(Author)),
827
        ("Signature", schemars::schema_for!(Signature)),
828
        ("Problem", schemars::schema_for!(Problem)),
829
        ("Proposal", schemars::schema_for!(Proposal)),
830
        ("ProposalState", schemars::schema_for!(ProposalState)),
831
        ("ProposalSource", schemars::schema_for!(ProposalSource)),
832
        ("Approval", schemars::schema_for!(Approval)),
833
        ("Issue", schemars::schema_for!(Issue)),
834
        ("Label", schemars::schema_for!(Label)),
835
        ("Milestone", schemars::schema_for!(Milestone)),
836
        ("Comment", schemars::schema_for!(Comment)),
837
        ("ProposalFile", schemars::schema_for!(ProposalFile)),
838
        ("Notification", schemars::schema_for!(Notification)),
839
        ("Inbox", schemars::schema_for!(Inbox)),
840
        ("Atom", schemars::schema_for!(Atom)),
841
        ("Review", schemars::schema_for!(Review)),
842
        ("TreeEntry", schemars::schema_for!(TreeEntry)),
843
        ("BlameLine", schemars::schema_for!(BlameLine)),
844
        ("FileChange", schemars::schema_for!(FileChange)),
845
        ("ChangeDetail", schemars::schema_for!(ChangeDetail)),
846
        ("History", schemars::schema_for!(History)),
847
        ("Conflict", schemars::schema_for!(Conflict)),
848
        ("Push", schemars::schema_for!(Push)),
849
        ("Trust", schemars::schema_for!(Trust)),
850
        ("Policy", schemars::schema_for!(Policy)),
851
        ("Rule", schemars::schema_for!(Rule)),
852
        ("Hook", schemars::schema_for!(Hook)),
853
        ("NewHook", schemars::schema_for!(NewHook)),
854
        ("Check", schemars::schema_for!(Check)),
855
        ("CheckStatus", schemars::schema_for!(CheckStatus)),
856
        ("NewCheck", schemars::schema_for!(NewCheck)),
857
        ("User", schemars::schema_for!(User)),
858
        ("Organisation", schemars::schema_for!(Organisation)),
859
        ("NewRepository", schemars::schema_for!(NewRepository)),
860
        ("NewIssue", schemars::schema_for!(NewIssue)),
861
        ("IssueEdit", schemars::schema_for!(IssueEdit)),
862
        ("NewLabel", schemars::schema_for!(NewLabel)),
863
        ("RequiredChecks", schemars::schema_for!(RequiredChecks)),
864
        ("Project", schemars::schema_for!(Project)),
865
        ("ProjectCard", schemars::schema_for!(ProjectCard)),
866
        ("ProjectColumn", schemars::schema_for!(ProjectColumn)),
867
        ("Board", schemars::schema_for!(Board)),
868
        ("NewProject", schemars::schema_for!(NewProject)),
869
        ("ProjectEdit", schemars::schema_for!(ProjectEdit)),
870
        ("NewCard", schemars::schema_for!(NewCard)),
871
        ("CardMove", schemars::schema_for!(CardMove)),
872
        ("NewComment", schemars::schema_for!(NewComment)),
873
        ("NewProposal", schemars::schema_for!(NewProposal)),
874
        ("NewReview", schemars::schema_for!(NewReview)),
875
        ("IssueStateChange", schemars::schema_for!(IssueStateChange)),
876
        ("WebhookEnvelope", schemars::schema_for!(WebhookEnvelope)),
877
        ("ProposalEvent", schemars::schema_for!(ProposalEvent)),
878
        ("Release", schemars::schema_for!(Release)),
879
        ("ReleaseAsset", schemars::schema_for!(ReleaseAsset)),
880
        ("NewRelease", schemars::schema_for!(NewRelease)),
881
    ]
882
}