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