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