g1t/services/work/src/rows.rs

171 lines4,444 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::{
Issues and pull requests replace intents and attempts6 Comment, Issue, IssueReason, Pull, PullStatus, Runtime, SessionEntry, SessionEntryKind, State,
Work service in Rust, with RFC 3339 timestamps7};
8use serde::Deserialize;
9
Issues and pull requests replace intents and attempts10fn user(id: String, username: String) -> User {
11 User {
12 id,
13 username,
14 ..User::default()
15 }
16}
17
Work service in Rust, with RFC 3339 timestamps18#[derive(Deserialize)]
Issues and pull requests replace intents and attempts19pub struct IssueRow {
Work service in Rust, with RFC 3339 timestamps20 pub id: String,
21 pub repo_id: String,
22 pub number: u32,
23 pub title: String,
Issues and pull requests replace intents and attempts24 pub body: String,
25 /// JSON array of label names.
26 pub labels: String,
Work service in Rust, with RFC 3339 timestamps27 /// JSON array of commands.
28 pub checks: String,
Issues and pull requests replace intents and attempts29 pub state: State,
30 pub reason: Option<IssueReason>,
31 pub resolved_by: Option<u32>,
Work service in Rust, with RFC 3339 timestamps32 pub author_id: String,
33 pub author_name: String,
34 pub created_at: String,
Issues and pull requests replace intents and attempts35 pub updated_at: String,
36 pub closed_at: Option<String>,
37 pub pull_count: u32,
38 pub comment_count: u32,
Work service in Rust, with RFC 3339 timestamps39}
40
Issues and pull requests replace intents and attempts41impl From<IssueRow> for Issue {
42 fn from(row: IssueRow) -> Self {
43 Issue {
Work service in Rust, with RFC 3339 timestamps44 id: row.id,
45 repo_id: row.repo_id,
46 number: row.number,
47 title: row.title,
Issues and pull requests replace intents and attempts48 body: row.body,
49 labels: serde_json::from_str(&row.labels).unwrap_or_default(),
Work service in Rust, with RFC 3339 timestamps50 checks: serde_json::from_str(&row.checks).unwrap_or_default(),
Issues and pull requests replace intents and attempts51 state: row.state,
52 reason: row.reason,
53 resolved_by: row.resolved_by,
54 author: user(row.author_id, row.author_name),
Work service in Rust, with RFC 3339 timestamps55 created_at: row.created_at,
Issues and pull requests replace intents and attempts56 updated_at: row.updated_at,
57 closed_at: row.closed_at,
58 pull_count: row.pull_count,
59 comment_count: row.comment_count,
Work service in Rust, with RFC 3339 timestamps60 }
61 }
62}
63
64#[derive(Deserialize)]
Issues and pull requests replace intents and attempts65pub struct PullRow {
Work service in Rust, with RFC 3339 timestamps66 pub id: String,
67 pub repo_id: String,
68 pub number: u32,
Issues and pull requests replace intents and attempts69 pub issue_number: Option<u32>,
70 pub title: String,
71 pub body: Option<String>,
Work service in Rust, with RFC 3339 timestamps72 pub agent: String,
Issues and pull requests replace intents and attempts73 pub runtime: Runtime,
74 pub status: PullStatus,
Work service in Rust, with RFC 3339 timestamps75 pub fork_repo_id: String,
76 pub fork_namespace: String,
77 pub fork_name: String,
78 pub head_commit: Option<String>,
Issues and pull requests replace intents and attempts79 pub merge_base: Option<String>,
80 pub merged_by: Option<String>,
81 pub merged_at: Option<String>,
82 pub superseded_by: Option<u32>,
83 pub author_id: String,
84 pub author_name: String,
Work service in Rust, with RFC 3339 timestamps85 pub created_at: String,
86 pub updated_at: String,
87}
88
Issues and pull requests replace intents and attempts89impl From<PullRow> for Pull {
90 fn from(row: PullRow) -> Self {
91 Pull {
Work service in Rust, with RFC 3339 timestamps92 id: row.id,
93 repo_id: row.repo_id,
94 number: row.number,
Issues and pull requests replace intents and attempts95 issue: row.issue_number,
96 title: row.title,
97 body: row.body,
Work service in Rust, with RFC 3339 timestamps98 agent: row.agent,
99 runtime: row.runtime,
100 status: row.status,
101 fork: RepoPath {
102 namespace: row.fork_namespace,
103 name: row.fork_name,
104 },
105 fork_repo_id: row.fork_repo_id,
106 head_commit: row.head_commit,
Issues and pull requests replace intents and attempts107 merge_base: row.merge_base,
108 merged_by: row.merged_by,
109 merged_at: row.merged_at,
110 superseded_by: row.superseded_by,
111 author: user(row.author_id, row.author_name),
Work service in Rust, with RFC 3339 timestamps112 created_at: row.created_at,
113 updated_at: row.updated_at,
114 }
115 }
116}
117
118#[derive(Deserialize)]
Issues and pull requests replace intents and attempts119pub struct CommentRow {
120 pub id: String,
121 pub author_id: String,
122 pub author_name: String,
123 pub body: String,
124 pub created_at: String,
125}
126
127impl From<CommentRow> for Comment {
128 fn from(row: CommentRow) -> Self {
129 Comment {
130 id: row.id,
131 author: user(row.author_id, row.author_name),
132 body: row.body,
133 created_at: row.created_at,
134 }
135 }
136}
137
138#[derive(Deserialize)]
Work service in Rust, with RFC 3339 timestamps139pub struct SessionRow {
140 pub seq: u32,
141 pub kind: SessionEntryKind,
142 pub text: String,
143 pub tool: Option<String>,
144 pub commit: Option<String>,
145 pub at: String,
146}
147
148impl From<SessionRow> for SessionEntry {
149 fn from(row: SessionRow) -> Self {
150 SessionEntry {
151 seq: row.seq,
152 kind: row.kind,
153 text: row.text,
154 tool: row.tool,
155 commit: row.commit,
156 at: row.at,
157 }
158 }
159}
Issues and pull requests replace intents and attempts160
161/// A single number selected as `n`.
162#[derive(Deserialize)]
163pub struct NumberRow {
164 pub n: u32,
165}
166
167/// A single string selected as `value`.
168#[derive(Deserialize)]
169pub struct ValueRow {
170 pub value: String,
171}