pr_01m47d15m3e54sn21z27rpy5n9/crates/contracts/src/events.rs
| 1 | //! Events published on the bus. Mirrors `packages/contracts/src/events.ts`. |
| 2 | |
| 3 | use serde::Serialize; |
| 4 | |
| 5 | /// What a publisher supplies; the bus fills in the id and time. |
| 6 | #[derive(Debug, Serialize)] |
| 7 | #[serde(rename_all = "camelCase")] |
| 8 | pub struct NewEvent<T: Serialize> { |
| 9 | #[serde(rename = "type")] |
| 10 | pub kind: &'static str, |
| 11 | /// The service that published it. |
| 12 | pub source: &'static str, |
| 13 | /// The repo the event concerns. |
| 14 | pub repo_id: Option<String>, |
| 15 | /// The user or agent that caused it, if any. |
| 16 | pub actor: Option<String>, |
| 17 | pub data: T, |
| 18 | } |
| 19 | |
| 20 | #[derive(Debug, Serialize)] |
| 21 | #[serde(rename_all = "camelCase")] |
| 22 | pub struct RepoCreated { |
| 23 | pub repo_id: String, |
| 24 | pub namespace: String, |
| 25 | pub name: String, |
| 26 | pub is_private: bool, |
| 27 | } |
| 28 | |
| 29 | #[derive(Debug, Serialize)] |
| 30 | #[serde(rename_all = "camelCase")] |
| 31 | pub struct RepoForked { |
| 32 | pub repo_id: String, |
| 33 | pub source_repo_id: String, |
| 34 | pub attempt_id: String, |
| 35 | } |
| 36 | |
| 37 | /// `after` is the commit the ref points to once the push has landed. |
| 38 | #[derive(Debug, Serialize)] |
| 39 | #[serde(rename_all = "camelCase")] |
| 40 | pub struct GitPush { |
| 41 | pub repo_id: String, |
| 42 | #[serde(rename = "ref")] |
| 43 | pub git_ref: String, |
| 44 | pub after: String, |
| 45 | } |
| 46 | |
| 47 | #[derive(Debug, Serialize)] |
| 48 | #[serde(rename_all = "camelCase")] |
| 49 | pub struct IntentOpened { |
| 50 | pub intent_id: String, |
| 51 | pub repo_id: String, |
| 52 | pub number: u32, |
| 53 | pub title: String, |
| 54 | } |
| 55 | |
| 56 | #[derive(Debug, Serialize)] |
| 57 | #[serde(rename_all = "camelCase")] |
| 58 | pub struct IntentClosed { |
| 59 | pub intent_id: String, |
| 60 | pub repo_id: String, |
| 61 | /// `shipped` or `withdrawn`. |
| 62 | pub reason: &'static str, |
| 63 | } |
| 64 | |
| 65 | /// The payload of `attempt.started`, `attempt.updated`, `attempt.submitted` |
| 66 | /// and `attempt.shipped`; each uses the fields that apply to it. |
| 67 | #[derive(Debug, Default, Serialize)] |
| 68 | #[serde(rename_all = "camelCase")] |
| 69 | pub struct AttemptEvent { |
| 70 | pub attempt_id: String, |
| 71 | pub intent_id: String, |
| 72 | pub repo_id: String, |
| 73 | #[serde(skip_serializing_if = "Option::is_none")] |
| 74 | pub agent: Option<String>, |
| 75 | #[serde(skip_serializing_if = "Option::is_none")] |
| 76 | pub status: Option<&'static str>, |
| 77 | #[serde(skip_serializing_if = "Option::is_none")] |
| 78 | pub commit: Option<String>, |
| 79 | } |
| 80 | |
| 81 | #[derive(Debug, Serialize)] |
| 82 | #[serde(rename_all = "camelCase")] |
| 83 | pub struct SessionAppended { |
| 84 | pub attempt_id: String, |
| 85 | pub session_id: String, |
| 86 | pub count: u32, |
| 87 | } |
| 88 | |
| 89 | /// An event as delivered to subscribers. `data` is left as JSON; each |
| 90 | /// subscriber decodes the types it cares about. |
| 91 | #[derive(Debug, serde::Deserialize)] |
| 92 | #[serde(rename_all = "camelCase")] |
| 93 | pub struct Delivered { |
| 94 | pub id: String, |
| 95 | #[serde(rename = "type")] |
| 96 | pub kind: String, |
| 97 | /// Milliseconds since the epoch, until the bus itself moves to RFC 3339. |
| 98 | pub time: serde_json::Value, |
| 99 | pub repo_id: Option<String>, |
| 100 | pub data: serde_json::Value, |
| 101 | } |