Skip to main content

seal_tui/
db.rs

1//! Shared types for review data and the `SealClient` trait.
2
3use std::collections::HashMap;
4
5use anyhow::Result;
6use serde::{Deserialize, Serialize};
7
8/// Summary of a review for list views.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct ReviewSummary {
11    pub review_id: String,
12    pub title: String,
13    pub author: String,
14    pub status: String,
15    pub thread_count: i64,
16    pub open_thread_count: i64,
17    #[serde(default)]
18    pub reviewers: Vec<String>,
19}
20
21/// Full details of a review.
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct ReviewDetail {
24    pub review_id: String,
25    pub jj_change_id: String,
26    pub scm_kind: String,
27    pub scm_anchor: String,
28    pub initial_commit: String,
29    pub final_commit: Option<String>,
30    pub title: String,
31    pub description: Option<String>,
32    pub author: String,
33    pub created_at: String,
34    pub status: String,
35    pub status_changed_at: Option<String>,
36    pub status_changed_by: Option<String>,
37    pub abandon_reason: Option<String>,
38    pub thread_count: i64,
39    pub open_thread_count: i64,
40}
41
42/// Summary of a thread for list views.
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct ThreadSummary {
45    pub thread_id: String,
46    pub file_path: String,
47    pub selection_start: i64,
48    pub selection_end: Option<i64>,
49    pub status: String,
50    pub comment_count: i64,
51}
52
53/// Full details of a thread.
54#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct ThreadDetail {
56    pub thread_id: String,
57    pub review_id: String,
58    pub file_path: String,
59    pub selection_type: String,
60    pub selection_start: i64,
61    pub selection_end: Option<i64>,
62    pub commit_hash: String,
63    pub author: String,
64    pub created_at: String,
65    pub status: String,
66    pub status_changed_at: Option<String>,
67    pub status_changed_by: Option<String>,
68    pub resolve_reason: Option<String>,
69    pub reopen_reason: Option<String>,
70}
71
72/// A single comment in a thread.
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct Comment {
75    pub comment_id: String,
76    pub author: String,
77    pub body: String,
78    pub created_at: String,
79}
80
81/// Per-file diff and content data from seal.
82pub struct FileData {
83    pub path: String,
84    /// Unified diff text for this file (if available).
85    pub diff: Option<String>,
86    /// Windowed file content for orphaned thread context.
87    pub content: Option<FileContentData>,
88}
89
90/// Windowed file content returned by seal for orphaned threads.
91pub struct FileContentData {
92    /// 1-based line number of the first line in `lines`.
93    pub start_line: i64,
94    pub lines: Vec<String>,
95}
96
97/// Bundle of review data loaded in one call.
98pub struct ReviewData {
99    pub detail: ReviewDetail,
100    pub threads: Vec<ThreadSummary>,
101    pub comments: HashMap<String, Vec<Comment>>,
102    /// Per-file diffs and content (populated when `--include-diffs` is used).
103    pub files: Vec<FileData>,
104}
105
106/// Trait for loading review data from any backend.
107pub trait SealClient {
108    /// List reviews, optionally filtered by status.
109    ///
110    /// # Errors
111    ///
112    /// Returns an error if the backend query fails.
113    fn list_reviews(&self, status: Option<&str>) -> Result<Vec<ReviewSummary>>;
114
115    /// Load full review data (detail, threads, comments) for a review.
116    ///
117    /// # Errors
118    ///
119    /// Returns an error if the backend query fails.
120    fn load_review_data(&self, review_id: &str) -> Result<Option<ReviewData>>;
121
122    /// Add a comment to a review on specific lines (auto-creates thread).
123    ///
124    /// # Errors
125    ///
126    /// Returns an error if the CLI call fails.
127    fn comment(
128        &self,
129        review_id: &str,
130        file_path: &str,
131        start_line: i64,
132        end_line: Option<i64>,
133        body: &str,
134    ) -> Result<()>;
135
136    /// Reply to an existing thread.
137    ///
138    /// # Errors
139    ///
140    /// Returns an error if the CLI call fails.
141    fn reply(&self, thread_id: &str, body: &str) -> Result<()>;
142}