pr_01m47d15m3e54sn21z27rpy5n9/crates/contracts/src/events.rs

238 lines7,551 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
GitHub Actions on g1t, part one: reading workflows38/// One branch or tag 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,
GitHub Actions on g1t, part one: reading workflows46 /// Where it pointed before; absent for a new branch or tag.
47 #[serde(skip_serializing_if = "Option::is_none")]
48 pub before: Option<String>,
Rust repos service with shipping; pull requests kept in the model49 pub after: String,
Events service in Rust, with RFC 3339 times and accurate push events50 /// Whether the ref is the repository's default branch.
51 pub default_branch: bool,
Rust repos service with shipping; pull requests kept in the model52}
Work service in Rust, with RFC 3339 timestamps53
Agents as a team: lifecycle, merge queue, billing and a new shell54/// The payload of `issue.opened`, `issue.updated`, `issue.assigned`,
55/// `issue.closed` and `issue.reopened`; each uses the fields that apply to it.
Issues and pull requests replace intents and attempts56#[derive(Debug, Default, Serialize)]
Work service in Rust, with RFC 3339 timestamps57#[serde(rename_all = "camelCase")]
Issues and pull requests replace intents and attempts58pub struct IssueEvent {
59 pub issue_id: String,
Work service in Rust, with RFC 3339 timestamps60 pub repo_id: String,
61 pub number: u32,
Issues and pull requests replace intents and attempts62 #[serde(skip_serializing_if = "Option::is_none")]
63 pub title: Option<String>,
64 /// On close: `completed` or `not_planned`.
65 #[serde(skip_serializing_if = "Option::is_none")]
66 pub reason: Option<&'static str>,
67 /// On close: the number of the pull request whose merge closed it.
68 #[serde(skip_serializing_if = "Option::is_none")]
69 pub resolved_by: Option<u32>,
Agents as a team: lifecycle, merge queue, billing and a new shell70 /// On `issue.assigned`: the people it is now assigned to.
71 #[serde(skip_serializing_if = "Option::is_none")]
72 pub assignees: Option<Vec<String>>,
Work service in Rust, with RFC 3339 timestamps73}
74
Acceptance checks in sandboxes, line comments and review verdicts75/// The payload of `pull.opened`, `pull.ready`, `pull.updated` (its head
76/// moved), `pull.closed` and `pull.merged`; each uses the fields that apply to it.
Work service in Rust, with RFC 3339 timestamps77#[derive(Debug, Default, Serialize)]
78#[serde(rename_all = "camelCase")]
Issues and pull requests replace intents and attempts79pub struct PullEvent {
80 pub pull_id: String,
Work service in Rust, with RFC 3339 timestamps81 pub repo_id: String,
Issues and pull requests replace intents and attempts82 pub number: u32,
83 /// The number of the issue it is for.
84 #[serde(skip_serializing_if = "Option::is_none")]
85 pub issue: Option<u32>,
Work service in Rust, with RFC 3339 timestamps86 #[serde(skip_serializing_if = "Option::is_none")]
87 pub agent: Option<String>,
Issues and pull requests replace intents and attempts88 /// On merge: the commit the branch now points to.
Work service in Rust, with RFC 3339 timestamps89 #[serde(skip_serializing_if = "Option::is_none")]
Issues and pull requests replace intents and attempts90 pub commit: Option<String>,
91 /// On close: the pull request that was merged instead.
Work service in Rust, with RFC 3339 timestamps92 #[serde(skip_serializing_if = "Option::is_none")]
Issues and pull requests replace intents and attempts93 pub superseded_by: Option<u32>,
Work service in Rust, with RFC 3339 timestamps94}
95
Acceptance checks in sandboxes, line comments and review verdicts96/// `checks.completed`: a run of an issue's acceptance checks against a pull
97/// request finished.
98#[derive(Debug, Serialize)]
99#[serde(rename_all = "camelCase")]
100pub struct ChecksEvent {
101 pub pull_id: String,
102 pub repo_id: String,
103 pub number: u32,
104 /// `passed`, `failed` or `errored`.
105 pub status: &'static str,
106 /// The commit that was checked.
107 pub commit: String,
108}
109
Actions: workflow_run, workflow.completed, artifacts on the run page, Node 24110/// `workflow.completed`: a GitHub Actions run finished.
111#[derive(Debug, Serialize)]
112#[serde(rename_all = "camelCase")]
113pub struct WorkflowEvent {
114 pub run_id: String,
115 pub repo_id: String,
116 /// The workflow's name, and its file.
117 pub workflow: String,
118 pub path: String,
119 /// The run's number among the workflow's runs.
120 pub number: u64,
121 /// The GitHub event that started it, such as `push`.
122 pub event: String,
123 /// `success`, `failure`, `cancelled` or `skipped`.
124 pub conclusion: String,
125 #[serde(rename = "ref")]
126 pub git_ref: String,
127 pub sha: String,
128 /// The pull request it ran for, if any.
129 #[serde(skip_serializing_if = "Option::is_none")]
130 pub pull: Option<u32>,
131}
132
Agents as a team: lifecycle, merge queue, billing and a new shell133/// `review.completed`: a g1t agent finished reviewing a pull request, or
134/// could not.
135#[derive(Debug, Serialize)]
136#[serde(rename_all = "camelCase")]
137pub struct ReviewEvent {
138 pub pull_id: String,
139 pub repo_id: String,
140 pub number: u32,
141 /// `approve` or `request_changes`; absent when no review was written.
142 #[serde(skip_serializing_if = "Option::is_none")]
143 pub verdict: Option<&'static str>,
144}
145
Issues and pull requests replace intents and attempts146/// `comment.created`. `number` is the issue or pull request commented on.
Work service in Rust, with RFC 3339 timestamps147#[derive(Debug, Serialize)]
148#[serde(rename_all = "camelCase")]
Issues and pull requests replace intents and attempts149pub struct CommentCreated {
150 pub comment_id: String,
151 pub repo_id: String,
152 pub number: u32,
Agents as a team: lifecycle, merge queue, billing and a new shell153 /// Set when the comment is on a pull request.
154 #[serde(skip_serializing_if = "Option::is_none")]
155 pub pull_id: Option<String>,
156 /// Set when the comment is a review: approve or request changes.
157 #[serde(skip_serializing_if = "Option::is_none")]
158 pub verdict: Option<crate::work::Verdict>,
Issues and pull requests replace intents and attempts159}
160
161#[derive(Debug, Serialize)]
162#[serde(rename_all = "camelCase")]
Work service in Rust, with RFC 3339 timestamps163pub struct SessionAppended {
Issues and pull requests replace intents and attempts164 pub pull_id: String,
165 pub repo_id: String,
166 pub number: u32,
Work service in Rust, with RFC 3339 timestamps167 pub count: u32,
168}
169
Events service in Rust, with RFC 3339 times and accurate push events170/// An event as stored in the log and delivered to subscribers. `data` is
171/// left as JSON; each reader decodes the types it cares about.
172#[derive(Clone, Debug, Serialize, serde::Deserialize)]
173#[serde(rename_all = "camelCase")]
174pub struct Event {
175 /// Sorts by the time the event was published.
176 pub id: String,
177 #[serde(rename = "type")]
178 pub kind: String,
179 /// The service that published it.
180 pub source: String,
181 /// RFC 3339.
182 pub time: String,
183 /// The repo the event concerns.
184 pub repo_id: Option<String>,
185 /// The user or agent that caused it, if any.
186 pub actor: Option<String>,
187 pub data: serde_json::Value,
188}
189
190/// `publish`, as a publisher sends it. Returns nothing.
191#[derive(Debug, Serialize)]
192pub struct Publish<T: Serialize> {
193 pub events: Vec<NewEvent<T>>,
194}
195
196/// `publish`, as the events service reads it.
197#[derive(Debug, serde::Deserialize)]
198pub struct PublishArgs {
199 pub events: Vec<Published>,
200}
201
202/// A [`NewEvent`] of any type, as received.
Work service in Rust, with RFC 3339 timestamps203#[derive(Debug, serde::Deserialize)]
204#[serde(rename_all = "camelCase")]
Events service in Rust, with RFC 3339 times and accurate push events205pub struct Published {
Work service in Rust, with RFC 3339 timestamps206 #[serde(rename = "type")]
207 pub kind: String,
Events service in Rust, with RFC 3339 times and accurate push events208 pub source: String,
209 #[serde(default)]
Work service in Rust, with RFC 3339 timestamps210 pub repo_id: Option<String>,
Events service in Rust, with RFC 3339 times and accurate push events211 #[serde(default)]
212 pub actor: Option<String>,
Work service in Rust, with RFC 3339 timestamps213 pub data: serde_json::Value,
214}
Events service in Rust, with RFC 3339 times and accurate push events215
216/// `list`: events from the log, newest first. Returns `Vec<Event>`.
217#[derive(Debug, Default, Serialize, serde::Deserialize)]
218#[serde(rename_all = "camelCase")]
219pub struct ListArgs {
220 #[serde(default)]
221 pub repo_id: Option<String>,
222 /// Only these types; all types when empty.
223 #[serde(default)]
224 pub types: Vec<String>,
225 /// Only events older than this event id.
226 #[serde(default)]
227 pub before: Option<String>,
228 #[serde(default)]
229 pub limit: Option<u32>,
230}
Agents as a team: lifecycle, merge queue, billing and a new shell231
232/// `queue.changed`: a repository's merge queue gained, lost or settled an
233/// entry, so the next batch may be ready to test.
234#[derive(Debug, Serialize)]
235#[serde(rename_all = "camelCase")]
236pub struct QueueChanged {
237 pub repo_id: String,
238}