g1t/crates/contracts/src/events.rs

168 lines5,092 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Events service in Rust, with RFC 3339 times and accurate push events1//! Events published on the bus, and the events service that carries them.
2//! Mirrors `packages/contracts/src/events.ts`.
Rust repos service with shipping; pull requests kept in the model3
4use serde::Serialize;
5
6/// What a publisher supplies; the bus fills in the id and time.
7#[derive(Debug, Serialize)]
8#[serde(rename_all = "camelCase")]
9pub struct NewEvent<T: Serialize> {
10 #[serde(rename = "type")]
11 pub kind: &'static str,
12 /// The service that published it.
13 pub source: &'static str,
14 /// The repo the event concerns.
15 pub repo_id: Option<String>,
16 /// The user or agent that caused it, if any.
17 pub actor: Option<String>,
18 pub data: T,
19}
20
21#[derive(Debug, Serialize)]
22#[serde(rename_all = "camelCase")]
23pub struct RepoCreated {
24 pub repo_id: String,
25 pub namespace: String,
26 pub name: String,
27 pub is_private: bool,
28}
29
30#[derive(Debug, Serialize)]
31#[serde(rename_all = "camelCase")]
32pub struct RepoForked {
33 pub repo_id: String,
34 pub source_repo_id: String,
Issues and pull requests replace intents and attempts35 pub pull_id: String,
Rust repos service with shipping; pull requests kept in the model36}
37
Events service in Rust, with RFC 3339 times and accurate push events38/// One branch moved by a push. `after` is the commit it points to now.
Rust repos service with shipping; pull requests kept in the model39#[derive(Debug, Serialize)]
40#[serde(rename_all = "camelCase")]
41pub struct GitPush {
42 pub repo_id: String,
Events service in Rust, with RFC 3339 times and accurate push events43 /// The full ref, such as `refs/heads/main`.
Rust repos service with shipping; pull requests kept in the model44 #[serde(rename = "ref")]
45 pub git_ref: String,
46 pub after: String,
Events service in Rust, with RFC 3339 times and accurate push events47 /// Whether the ref is the repository's default branch.
48 pub default_branch: bool,
Rust repos service with shipping; pull requests kept in the model49}
Work service in Rust, with RFC 3339 timestamps50
Issues and pull requests replace intents and attempts51/// The payload of `issue.opened`, `issue.updated`, `issue.closed` and
52/// `issue.reopened`; each uses the fields that apply to it.
53#[derive(Debug, Default, Serialize)]
Work service in Rust, with RFC 3339 timestamps54#[serde(rename_all = "camelCase")]
Issues and pull requests replace intents and attempts55pub struct IssueEvent {
56 pub issue_id: String,
Work service in Rust, with RFC 3339 timestamps57 pub repo_id: String,
58 pub number: u32,
Issues and pull requests replace intents and attempts59 #[serde(skip_serializing_if = "Option::is_none")]
60 pub title: Option<String>,
61 /// On close: `completed` or `not_planned`.
62 #[serde(skip_serializing_if = "Option::is_none")]
63 pub reason: Option<&'static str>,
64 /// On close: the number of the pull request whose merge closed it.
65 #[serde(skip_serializing_if = "Option::is_none")]
66 pub resolved_by: Option<u32>,
Work service in Rust, with RFC 3339 timestamps67}
68
Issues and pull requests replace intents and attempts69/// The payload of `pull.opened`, `pull.ready`, `pull.closed` and
70/// `pull.merged`; each uses the fields that apply to it.
Work service in Rust, with RFC 3339 timestamps71#[derive(Debug, Default, Serialize)]
72#[serde(rename_all = "camelCase")]
Issues and pull requests replace intents and attempts73pub struct PullEvent {
74 pub pull_id: String,
Work service in Rust, with RFC 3339 timestamps75 pub repo_id: String,
Issues and pull requests replace intents and attempts76 pub number: u32,
77 /// The number of the issue it is for.
78 #[serde(skip_serializing_if = "Option::is_none")]
79 pub issue: Option<u32>,
Work service in Rust, with RFC 3339 timestamps80 #[serde(skip_serializing_if = "Option::is_none")]
81 pub agent: Option<String>,
Issues and pull requests replace intents and attempts82 /// On merge: the commit the branch now points to.
Work service in Rust, with RFC 3339 timestamps83 #[serde(skip_serializing_if = "Option::is_none")]
Issues and pull requests replace intents and attempts84 pub commit: Option<String>,
85 /// On close: the pull request that was merged instead.
Work service in Rust, with RFC 3339 timestamps86 #[serde(skip_serializing_if = "Option::is_none")]
Issues and pull requests replace intents and attempts87 pub superseded_by: Option<u32>,
Work service in Rust, with RFC 3339 timestamps88}
89
Issues and pull requests replace intents and attempts90/// `comment.created`. `number` is the issue or pull request commented on.
Work service in Rust, with RFC 3339 timestamps91#[derive(Debug, Serialize)]
92#[serde(rename_all = "camelCase")]
Issues and pull requests replace intents and attempts93pub struct CommentCreated {
94 pub comment_id: String,
95 pub repo_id: String,
96 pub number: u32,
97}
98
99#[derive(Debug, Serialize)]
100#[serde(rename_all = "camelCase")]
Work service in Rust, with RFC 3339 timestamps101pub struct SessionAppended {
Issues and pull requests replace intents and attempts102 pub pull_id: String,
103 pub repo_id: String,
104 pub number: u32,
Work service in Rust, with RFC 3339 timestamps105 pub count: u32,
106}
107
Events service in Rust, with RFC 3339 times and accurate push events108/// An event as stored in the log and delivered to subscribers. `data` is
109/// left as JSON; each reader decodes the types it cares about.
110#[derive(Clone, Debug, Serialize, serde::Deserialize)]
111#[serde(rename_all = "camelCase")]
112pub struct Event {
113 /// Sorts by the time the event was published.
114 pub id: String,
115 #[serde(rename = "type")]
116 pub kind: String,
117 /// The service that published it.
118 pub source: String,
119 /// RFC 3339.
120 pub time: String,
121 /// The repo the event concerns.
122 pub repo_id: Option<String>,
123 /// The user or agent that caused it, if any.
124 pub actor: Option<String>,
125 pub data: serde_json::Value,
126}
127
128/// `publish`, as a publisher sends it. Returns nothing.
129#[derive(Debug, Serialize)]
130pub struct Publish<T: Serialize> {
131 pub events: Vec<NewEvent<T>>,
132}
133
134/// `publish`, as the events service reads it.
135#[derive(Debug, serde::Deserialize)]
136pub struct PublishArgs {
137 pub events: Vec<Published>,
138}
139
140/// A [`NewEvent`] of any type, as received.
Work service in Rust, with RFC 3339 timestamps141#[derive(Debug, serde::Deserialize)]
142#[serde(rename_all = "camelCase")]
Events service in Rust, with RFC 3339 times and accurate push events143pub struct Published {
Work service in Rust, with RFC 3339 timestamps144 #[serde(rename = "type")]
145 pub kind: String,
Events service in Rust, with RFC 3339 times and accurate push events146 pub source: String,
147 #[serde(default)]
Work service in Rust, with RFC 3339 timestamps148 pub repo_id: Option<String>,
Events service in Rust, with RFC 3339 times and accurate push events149 #[serde(default)]
150 pub actor: Option<String>,
Work service in Rust, with RFC 3339 timestamps151 pub data: serde_json::Value,
152}
Events service in Rust, with RFC 3339 times and accurate push events153
154/// `list`: events from the log, newest first. Returns `Vec<Event>`.
155#[derive(Debug, Default, Serialize, serde::Deserialize)]
156#[serde(rename_all = "camelCase")]
157pub struct ListArgs {
158 #[serde(default)]
159 pub repo_id: Option<String>,
160 /// Only these types; all types when empty.
161 #[serde(default)]
162 pub types: Vec<String>,
163 /// Only events older than this event id.
164 #[serde(default)]
165 pub before: Option<String>,
166 #[serde(default)]
167 pub limit: Option<u32>,
168}