| 1 | //! Rows as they come out of D1, and their conversion to contract types. |
| 2 | |
| 3 | use g1t_contracts::User; |
| 4 | use g1t_contracts::repos::RepoPath; |
| 5 | use g1t_contracts::work::{ |
| 6 | Attempt, AttemptRuntime, AttemptStatus, Intent, IntentStatus, SessionEntry, SessionEntryKind, |
| 7 | }; |
| 8 | use serde::Deserialize; |
| 9 | |
| 10 | #[derive(Deserialize)] |
| 11 | pub struct IntentRow { |
| 12 | pub id: String, |
| 13 | pub repo_id: String, |
| 14 | pub number: u32, |
| 15 | pub title: String, |
| 16 | pub brief: String, |
| 17 | /// JSON array of commands. |
| 18 | pub checks: String, |
| 19 | pub status: IntentStatus, |
| 20 | pub author_id: String, |
| 21 | pub author_name: String, |
| 22 | pub created_at: String, |
| 23 | pub attempt_count: u32, |
| 24 | } |
| 25 | |
| 26 | impl From<IntentRow> for Intent { |
| 27 | fn from(row: IntentRow) -> Self { |
| 28 | Intent { |
| 29 | id: row.id, |
| 30 | repo_id: row.repo_id, |
| 31 | number: row.number, |
| 32 | title: row.title, |
| 33 | brief: row.brief, |
| 34 | checks: serde_json::from_str(&row.checks).unwrap_or_default(), |
| 35 | status: row.status, |
| 36 | author: User { |
| 37 | id: row.author_id, |
| 38 | username: row.author_name, |
| 39 | ..User::default() |
| 40 | }, |
| 41 | created_at: row.created_at, |
| 42 | attempt_count: row.attempt_count, |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | #[derive(Deserialize)] |
| 48 | pub struct AttemptRow { |
| 49 | pub id: String, |
| 50 | pub intent_id: String, |
| 51 | pub repo_id: String, |
| 52 | pub number: u32, |
| 53 | pub agent: String, |
| 54 | pub runtime: AttemptRuntime, |
| 55 | pub status: AttemptStatus, |
| 56 | pub summary: Option<String>, |
| 57 | pub fork_repo_id: String, |
| 58 | pub fork_namespace: String, |
| 59 | pub fork_name: String, |
| 60 | pub head_commit: Option<String>, |
| 61 | pub landed_base: Option<String>, |
| 62 | pub started_by_id: String, |
| 63 | pub started_by_name: String, |
| 64 | pub created_at: String, |
| 65 | pub updated_at: String, |
| 66 | } |
| 67 | |
| 68 | impl From<AttemptRow> for Attempt { |
| 69 | fn from(row: AttemptRow) -> Self { |
| 70 | Attempt { |
| 71 | id: row.id, |
| 72 | intent_id: row.intent_id, |
| 73 | repo_id: row.repo_id, |
| 74 | number: row.number, |
| 75 | agent: row.agent, |
| 76 | runtime: row.runtime, |
| 77 | status: row.status, |
| 78 | summary: row.summary, |
| 79 | fork: RepoPath { |
| 80 | namespace: row.fork_namespace, |
| 81 | name: row.fork_name, |
| 82 | }, |
| 83 | fork_repo_id: row.fork_repo_id, |
| 84 | head_commit: row.head_commit, |
| 85 | landed_base: row.landed_base, |
| 86 | started_by: User { |
| 87 | id: row.started_by_id, |
| 88 | username: row.started_by_name, |
| 89 | ..User::default() |
| 90 | }, |
| 91 | created_at: row.created_at, |
| 92 | updated_at: row.updated_at, |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | #[derive(Deserialize)] |
| 98 | pub struct SessionRow { |
| 99 | pub seq: u32, |
| 100 | pub kind: SessionEntryKind, |
| 101 | pub text: String, |
| 102 | pub tool: Option<String>, |
| 103 | pub commit: Option<String>, |
| 104 | pub at: String, |
| 105 | } |
| 106 | |
| 107 | impl From<SessionRow> for SessionEntry { |
| 108 | fn from(row: SessionRow) -> Self { |
| 109 | SessionEntry { |
| 110 | seq: row.seq, |
| 111 | kind: row.kind, |
| 112 | text: row.text, |
| 113 | tool: row.tool, |
| 114 | commit: row.commit, |
| 115 | at: row.at, |
| 116 | } |
| 117 | } |
| 118 | } |