#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum DiffTruncationLevel {
#[default]
Full,
Abbreviated,
FileList,
FileListAbbreviated,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DiffReviewContent {
pub content: String,
pub truncation_level: DiffTruncationLevel,
pub total_file_count: usize,
pub shown_file_count: Option<usize>,
pub baseline_oid: Option<String>,
pub baseline_short: Option<String>,
pub baseline_description: String,
}
impl DiffReviewContent {
#[must_use]
pub fn format_context_header(&self) -> String {
let baseline_line = self
.baseline_short
.as_ref()
.map(|short| {
format!(
"Diff Context: Compared against {} {}",
self.baseline_description, short
)
})
.unwrap_or_else(|| "Diff Context: Version information not available".to_string());
let truncation_line = match self.truncation_level {
DiffTruncationLevel::Full => None,
DiffTruncationLevel::Abbreviated => Some(format!(
"Note: Diff abbreviated - {}/{} files shown",
self.shown_file_count.unwrap_or(0),
self.total_file_count
)),
DiffTruncationLevel::FileList => Some(format!(
"Note: Only file list shown - {} files changed",
self.total_file_count
)),
DiffTruncationLevel::FileListAbbreviated => Some(format!(
"Note: File list abbreviated - {}/{} files shown",
self.shown_file_count.unwrap_or(0),
self.total_file_count
)),
};
let lines: Vec<String> = [Some(baseline_line), truncation_line]
.into_iter()
.flatten()
.collect();
if lines.is_empty() {
String::new()
} else {
format!("{}\n", lines.join("\n"))
}
}
}