pr_01m47d15m3e54sn21z27rpy5n9/services/work/src/rows.rs

229 lines6,541 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.

Work service in Rust, with RFC 3339 timestamps1//! Rows as they come out of D1, and their conversion to contract types.
2
3use g1t_contracts::User;
4use g1t_contracts::repos::RepoPath;
5use g1t_contracts::work::{
Agents as a team: lifecycle, merge queue, billing and a new shell6 CheckStatus, Comment, CommentKind, Issue, IssueReason, Pull, PullStatus, Runtime, SessionEntry,
Acceptance checks in sandboxes, line comments and review verdicts7 SessionEntryKind, State, Verdict,
Work service in Rust, with RFC 3339 timestamps8};
9use serde::Deserialize;
10
Agents as a team: lifecycle, merge queue, billing and a new shell11pub(crate) fn user(id: String, username: String) -> User {
Issues and pull requests replace intents and attempts12 User {
13 id,
14 username,
15 ..User::default()
16 }
17}
18
Work service in Rust, with RFC 3339 timestamps19#[derive(Deserialize)]
Issues and pull requests replace intents and attempts20pub struct IssueRow {
Work service in Rust, with RFC 3339 timestamps21 pub id: String,
22 pub repo_id: String,
23 pub number: u32,
24 pub title: String,
Issues and pull requests replace intents and attempts25 pub body: String,
26 /// JSON array of label names.
27 pub labels: String,
Work service in Rust, with RFC 3339 timestamps28 /// JSON array of commands.
29 pub checks: String,
Issues and pull requests replace intents and attempts30 pub state: State,
31 pub reason: Option<IssueReason>,
32 pub resolved_by: Option<u32>,
Work service in Rust, with RFC 3339 timestamps33 pub author_id: String,
34 pub author_name: String,
35 pub created_at: String,
Issues and pull requests replace intents and attempts36 pub updated_at: String,
37 pub closed_at: Option<String>,
38 pub pull_count: u32,
39 pub comment_count: u32,
Agents as a team: lifecycle, merge queue, billing and a new shell40 /// JSON array of usernames.
41 pub assignees: String,
42 /// JSON array of issue numbers.
43 pub blocked_by: String,
44 /// JSON of who queued it for a g1t agent, if anyone has.
45 pub queued_by: Option<String>,
46 pub agent: Option<String>,
Work service in Rust, with RFC 3339 timestamps47}
48
Issues and pull requests replace intents and attempts49impl From<IssueRow> for Issue {
50 fn from(row: IssueRow) -> Self {
51 Issue {
Work service in Rust, with RFC 3339 timestamps52 id: row.id,
53 repo_id: row.repo_id,
54 number: row.number,
55 title: row.title,
Issues and pull requests replace intents and attempts56 body: row.body,
57 labels: serde_json::from_str(&row.labels).unwrap_or_default(),
Work service in Rust, with RFC 3339 timestamps58 checks: serde_json::from_str(&row.checks).unwrap_or_default(),
Issues and pull requests replace intents and attempts59 state: row.state,
60 reason: row.reason,
61 resolved_by: row.resolved_by,
62 author: user(row.author_id, row.author_name),
Work service in Rust, with RFC 3339 timestamps63 created_at: row.created_at,
Issues and pull requests replace intents and attempts64 updated_at: row.updated_at,
65 closed_at: row.closed_at,
66 pull_count: row.pull_count,
67 comment_count: row.comment_count,
Agents as a team: lifecycle, merge queue, billing and a new shell68 assignees: serde_json::from_str(&row.assignees).unwrap_or_default(),
69 blocked_by: serde_json::from_str(&row.blocked_by).unwrap_or_default(),
70 queued: row.queued_by.is_some(),
71 agent: row.agent,
Work service in Rust, with RFC 3339 timestamps72 }
73 }
74}
75
Agents as a team: lifecycle, merge queue, billing and a new shell76/// The remembered assessment of a pull request, read beside its row.
Work service in Rust, with RFC 3339 timestamps77#[derive(Deserialize)]
Agents as a team: lifecycle, merge queue, billing and a new shell78pub struct Snapshot {
79 pub stage: Option<g1t_contracts::work::Stage>,
80 pub stage_detail: Option<String>,
81 #[serde(default)]
82 pub revisions: u32,
83 /// Whether g1t is seeing it through at all.
84 #[serde(default)]
85 pub managed: u32,
86}
87
88#[derive(Deserialize)]
Issues and pull requests replace intents and attempts89pub struct PullRow {
Work service in Rust, with RFC 3339 timestamps90 pub id: String,
91 pub repo_id: String,
92 pub number: u32,
Issues and pull requests replace intents and attempts93 pub issue_number: Option<u32>,
94 pub title: String,
95 pub body: Option<String>,
Work service in Rust, with RFC 3339 timestamps96 pub agent: String,
Issues and pull requests replace intents and attempts97 pub runtime: Runtime,
98 pub status: PullStatus,
Pull requests from branches99 pub fork_repo_id: Option<String>,
100 pub fork_namespace: Option<String>,
101 pub fork_name: Option<String>,
102 pub source_branch: Option<String>,
Work service in Rust, with RFC 3339 timestamps103 pub head_commit: Option<String>,
Issues and pull requests replace intents and attempts104 pub merge_base: Option<String>,
105 pub merged_by: Option<String>,
106 pub merged_at: Option<String>,
107 pub superseded_by: Option<u32>,
Acceptance checks in sandboxes, line comments and review verdicts108 pub check_status: Option<CheckStatus>,
Agents as a team: lifecycle, merge queue, billing and a new shell109 /// JSON array of changed files; `None` until first worked out.
110 pub files: Option<String>,
111 /// JSON arrays of usernames.
112 pub assignees: String,
113 pub reviewers: String,
Issues and pull requests replace intents and attempts114 pub author_id: String,
115 pub author_name: String,
Work service in Rust, with RFC 3339 timestamps116 pub created_at: String,
117 pub updated_at: String,
118}
119
Issues and pull requests replace intents and attempts120impl From<PullRow> for Pull {
121 fn from(row: PullRow) -> Self {
122 Pull {
Work service in Rust, with RFC 3339 timestamps123 id: row.id,
124 repo_id: row.repo_id,
125 number: row.number,
Issues and pull requests replace intents and attempts126 issue: row.issue_number,
127 title: row.title,
128 body: row.body,
Work service in Rust, with RFC 3339 timestamps129 agent: row.agent,
130 runtime: row.runtime,
131 status: row.status,
Pull requests from branches132 fork: row
133 .fork_namespace
134 .zip(row.fork_name)
135 .map(|(namespace, name)| RepoPath { namespace, name }),
Work service in Rust, with RFC 3339 timestamps136 fork_repo_id: row.fork_repo_id,
Pull requests from branches137 branch: row.source_branch,
Work service in Rust, with RFC 3339 timestamps138 head_commit: row.head_commit,
Issues and pull requests replace intents and attempts139 merge_base: row.merge_base,
140 merged_by: row.merged_by,
141 merged_at: row.merged_at,
142 superseded_by: row.superseded_by,
Acceptance checks in sandboxes, line comments and review verdicts143 check_status: row.check_status,
Agents as a team: lifecycle, merge queue, billing and a new shell144 files: row
145 .files
146 .as_deref()
147 .and_then(|files| serde_json::from_str(files).ok())
148 .unwrap_or_default(),
149 assignees: serde_json::from_str(&row.assignees).unwrap_or_default(),
150 reviewers: serde_json::from_str(&row.reviewers).unwrap_or_default(),
Issues and pull requests replace intents and attempts151 author: user(row.author_id, row.author_name),
Work service in Rust, with RFC 3339 timestamps152 created_at: row.created_at,
153 updated_at: row.updated_at,
154 }
155 }
156}
157
158#[derive(Deserialize)]
Issues and pull requests replace intents and attempts159pub struct CommentRow {
160 pub id: String,
Agents as a team: lifecycle, merge queue, billing and a new shell161 pub kind: CommentKind,
Issues and pull requests replace intents and attempts162 pub author_id: String,
163 pub author_name: String,
164 pub body: String,
Acceptance checks in sandboxes, line comments and review verdicts165 pub path: Option<String>,
166 pub line: Option<u32>,
167 pub verdict: Option<Verdict>,
Issues and pull requests replace intents and attempts168 pub created_at: String,
169}
170
171impl From<CommentRow> for Comment {
172 fn from(row: CommentRow) -> Self {
173 Comment {
174 id: row.id,
Agents as a team: lifecycle, merge queue, billing and a new shell175 kind: row.kind,
Issues and pull requests replace intents and attempts176 author: user(row.author_id, row.author_name),
177 body: row.body,
Acceptance checks in sandboxes, line comments and review verdicts178 path: row.path,
179 line: row.line,
180 verdict: row.verdict,
Issues and pull requests replace intents and attempts181 created_at: row.created_at,
182 }
183 }
184}
185
186#[derive(Deserialize)]
Work service in Rust, with RFC 3339 timestamps187pub struct SessionRow {
188 pub seq: u32,
189 pub kind: SessionEntryKind,
190 pub text: String,
191 pub tool: Option<String>,
192 pub commit: Option<String>,
193 pub at: String,
194}
195
196impl From<SessionRow> for SessionEntry {
197 fn from(row: SessionRow) -> Self {
198 SessionEntry {
199 seq: row.seq,
200 kind: row.kind,
201 text: row.text,
202 tool: row.tool,
203 commit: row.commit,
204 at: row.at,
205 }
206 }
207}
Issues and pull requests replace intents and attempts208
Acceptance checks in sandboxes, line comments and review verdicts209/// A pull request whose head a push moved.
210#[derive(Deserialize)]
211pub struct MovedRow {
212 pub id: String,
213 pub repo_id: String,
214 pub number: u32,
215 pub issue_number: Option<u32>,
216 pub status: PullStatus,
217}
218
Issues and pull requests replace intents and attempts219/// A single number selected as `n`.
220#[derive(Deserialize)]
221pub struct NumberRow {
222 pub n: u32,
223}
224
225/// A single string selected as `value`.
226#[derive(Deserialize)]
227pub struct ValueRow {
228 pub value: String,
229}