g1t/services/work/src/rows.rs

192 lines5,095 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::{
Acceptance checks in sandboxes, line comments and review verdicts6 CheckStatus, Comment, Issue, IssueReason, Pull, PullStatus, Runtime, SessionEntry,
7 SessionEntryKind, State, Verdict,
Work service in Rust, with RFC 3339 timestamps8};
9use serde::Deserialize;
10
Issues and pull requests replace intents and attempts11fn user(id: String, username: String) -> User {
12 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,
Work service in Rust, with RFC 3339 timestamps40}
41
Issues and pull requests replace intents and attempts42impl From<IssueRow> for Issue {
43 fn from(row: IssueRow) -> Self {
44 Issue {
Work service in Rust, with RFC 3339 timestamps45 id: row.id,
46 repo_id: row.repo_id,
47 number: row.number,
48 title: row.title,
Issues and pull requests replace intents and attempts49 body: row.body,
50 labels: serde_json::from_str(&row.labels).unwrap_or_default(),
Work service in Rust, with RFC 3339 timestamps51 checks: serde_json::from_str(&row.checks).unwrap_or_default(),
Issues and pull requests replace intents and attempts52 state: row.state,
53 reason: row.reason,
54 resolved_by: row.resolved_by,
55 author: user(row.author_id, row.author_name),
Work service in Rust, with RFC 3339 timestamps56 created_at: row.created_at,
Issues and pull requests replace intents and attempts57 updated_at: row.updated_at,
58 closed_at: row.closed_at,
59 pull_count: row.pull_count,
60 comment_count: row.comment_count,
Work service in Rust, with RFC 3339 timestamps61 }
62 }
63}
64
65#[derive(Deserialize)]
Issues and pull requests replace intents and attempts66pub struct PullRow {
Work service in Rust, with RFC 3339 timestamps67 pub id: String,
68 pub repo_id: String,
69 pub number: u32,
Issues and pull requests replace intents and attempts70 pub issue_number: Option<u32>,
71 pub title: String,
72 pub body: Option<String>,
Work service in Rust, with RFC 3339 timestamps73 pub agent: String,
Issues and pull requests replace intents and attempts74 pub runtime: Runtime,
75 pub status: PullStatus,
Pull requests from branches76 pub fork_repo_id: Option<String>,
77 pub fork_namespace: Option<String>,
78 pub fork_name: Option<String>,
79 pub source_branch: Option<String>,
Work service in Rust, with RFC 3339 timestamps80 pub head_commit: Option<String>,
Issues and pull requests replace intents and attempts81 pub merge_base: Option<String>,
82 pub merged_by: Option<String>,
83 pub merged_at: Option<String>,
84 pub superseded_by: Option<u32>,
Acceptance checks in sandboxes, line comments and review verdicts85 pub check_status: Option<CheckStatus>,
Issues and pull requests replace intents and attempts86 pub author_id: String,
87 pub author_name: String,
Work service in Rust, with RFC 3339 timestamps88 pub created_at: String,
89 pub updated_at: String,
90}
91
Issues and pull requests replace intents and attempts92impl From<PullRow> for Pull {
93 fn from(row: PullRow) -> Self {
94 Pull {
Work service in Rust, with RFC 3339 timestamps95 id: row.id,
96 repo_id: row.repo_id,
97 number: row.number,
Issues and pull requests replace intents and attempts98 issue: row.issue_number,
99 title: row.title,
100 body: row.body,
Work service in Rust, with RFC 3339 timestamps101 agent: row.agent,
102 runtime: row.runtime,
103 status: row.status,
Pull requests from branches104 fork: row
105 .fork_namespace
106 .zip(row.fork_name)
107 .map(|(namespace, name)| RepoPath { namespace, name }),
Work service in Rust, with RFC 3339 timestamps108 fork_repo_id: row.fork_repo_id,
Pull requests from branches109 branch: row.source_branch,
Work service in Rust, with RFC 3339 timestamps110 head_commit: row.head_commit,
Issues and pull requests replace intents and attempts111 merge_base: row.merge_base,
112 merged_by: row.merged_by,
113 merged_at: row.merged_at,
114 superseded_by: row.superseded_by,
Acceptance checks in sandboxes, line comments and review verdicts115 check_status: row.check_status,
Issues and pull requests replace intents and attempts116 author: user(row.author_id, row.author_name),
Work service in Rust, with RFC 3339 timestamps117 created_at: row.created_at,
118 updated_at: row.updated_at,
119 }
120 }
121}
122
123#[derive(Deserialize)]
Issues and pull requests replace intents and attempts124pub struct CommentRow {
125 pub id: String,
126 pub author_id: String,
127 pub author_name: String,
128 pub body: String,
Acceptance checks in sandboxes, line comments and review verdicts129 pub path: Option<String>,
130 pub line: Option<u32>,
131 pub verdict: Option<Verdict>,
Issues and pull requests replace intents and attempts132 pub created_at: String,
133}
134
135impl From<CommentRow> for Comment {
136 fn from(row: CommentRow) -> Self {
137 Comment {
138 id: row.id,
139 author: user(row.author_id, row.author_name),
140 body: row.body,
Acceptance checks in sandboxes, line comments and review verdicts141 path: row.path,
142 line: row.line,
143 verdict: row.verdict,
Issues and pull requests replace intents and attempts144 created_at: row.created_at,
145 }
146 }
147}
148
149#[derive(Deserialize)]
Work service in Rust, with RFC 3339 timestamps150pub struct SessionRow {
151 pub seq: u32,
152 pub kind: SessionEntryKind,
153 pub text: String,
154 pub tool: Option<String>,
155 pub commit: Option<String>,
156 pub at: String,
157}
158
159impl From<SessionRow> for SessionEntry {
160 fn from(row: SessionRow) -> Self {
161 SessionEntry {
162 seq: row.seq,
163 kind: row.kind,
164 text: row.text,
165 tool: row.tool,
166 commit: row.commit,
167 at: row.at,
168 }
169 }
170}
Issues and pull requests replace intents and attempts171
Acceptance checks in sandboxes, line comments and review verdicts172/// A pull request whose head a push moved.
173#[derive(Deserialize)]
174pub struct MovedRow {
175 pub id: String,
176 pub repo_id: String,
177 pub number: u32,
178 pub issue_number: Option<u32>,
179 pub status: PullStatus,
180}
181
Issues and pull requests replace intents and attempts182/// A single number selected as `n`.
183#[derive(Deserialize)]
184pub struct NumberRow {
185 pub n: u32,
186}
187
188/// A single string selected as `value`.
189#[derive(Deserialize)]
190pub struct ValueRow {
191 pub value: String,
192}