| 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 pull_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 | /// The payload of `issue.opened`, `issue.updated`, `issue.closed` and |
| 48 | /// `issue.reopened`; each uses the fields that apply to it. |
| 49 | #[derive(Debug, Default, Serialize)] |
| 50 | #[serde(rename_all = "camelCase")] |
| 51 | pub struct IssueEvent { |
| 52 | pub issue_id: String, |
| 53 | pub repo_id: String, |
| 54 | pub number: u32, |
| 55 | #[serde(skip_serializing_if = "Option::is_none")] |
| 56 | pub title: Option<String>, |
| 57 | /// On close: `completed` or `not_planned`. |
| 58 | #[serde(skip_serializing_if = "Option::is_none")] |
| 59 | pub reason: Option<&'static str>, |
| 60 | /// On close: the number of the pull request whose merge closed it. |
| 61 | #[serde(skip_serializing_if = "Option::is_none")] |
| 62 | pub resolved_by: Option<u32>, |
| 63 | } |
| 64 | |
| 65 | /// The payload of `pull.opened`, `pull.ready`, `pull.closed` and |
| 66 | /// `pull.merged`; each uses the fields that apply to it. |
| 67 | #[derive(Debug, Default, Serialize)] |
| 68 | #[serde(rename_all = "camelCase")] |
| 69 | pub struct PullEvent { |
| 70 | pub pull_id: String, |
| 71 | pub repo_id: String, |
| 72 | pub number: u32, |
| 73 | /// The number of the issue it is for. |
| 74 | #[serde(skip_serializing_if = "Option::is_none")] |
| 75 | pub issue: Option<u32>, |
| 76 | #[serde(skip_serializing_if = "Option::is_none")] |
| 77 | pub agent: Option<String>, |
| 78 | /// On merge: the commit the branch now points to. |
| 79 | #[serde(skip_serializing_if = "Option::is_none")] |
| 80 | pub commit: Option<String>, |
| 81 | /// On close: the pull request that was merged instead. |
| 82 | #[serde(skip_serializing_if = "Option::is_none")] |
| 83 | pub superseded_by: Option<u32>, |
| 84 | } |
| 85 | |
| 86 | /// `comment.created`. `number` is the issue or pull request commented on. |
| 87 | #[derive(Debug, Serialize)] |
| 88 | #[serde(rename_all = "camelCase")] |
| 89 | pub struct CommentCreated { |
| 90 | pub comment_id: String, |
| 91 | pub repo_id: String, |
| 92 | pub number: u32, |
| 93 | } |
| 94 | |
| 95 | #[derive(Debug, Serialize)] |
| 96 | #[serde(rename_all = "camelCase")] |
| 97 | pub struct SessionAppended { |
| 98 | pub pull_id: String, |
| 99 | pub repo_id: String, |
| 100 | pub number: u32, |
| 101 | pub count: u32, |
| 102 | } |
| 103 | |
| 104 | /// An event as delivered to subscribers. `data` is left as JSON; each |
| 105 | /// subscriber decodes the types it cares about. |
| 106 | #[derive(Debug, serde::Deserialize)] |
| 107 | #[serde(rename_all = "camelCase")] |
| 108 | pub struct Delivered { |
| 109 | pub id: String, |
| 110 | #[serde(rename = "type")] |
| 111 | pub kind: String, |
| 112 | /// Milliseconds since the epoch, until the bus itself moves to RFC 3339. |
| 113 | pub time: serde_json::Value, |
| 114 | pub repo_id: Option<String>, |
| 115 | pub data: serde_json::Value, |
| 116 | } |