use std::path::PathBuf;
use std::sync::Arc;
use commitbee::domain::{ChangeStatus, DiffStats, FileCategory, FileChange, StagedChanges};
#[allow(dead_code)]
pub fn make_file_change(
path: &str,
status: ChangeStatus,
diff: &str,
additions: usize,
deletions: usize,
) -> FileChange {
FileChange {
path: PathBuf::from(path),
status,
diff: Arc::from(diff),
additions,
deletions,
category: FileCategory::from_path(&PathBuf::from(path)),
is_binary: false,
old_path: None,
rename_similarity: None,
}
}
#[allow(dead_code)]
pub fn make_renamed_file(old_path: &str, new_path: &str, similarity: u8) -> FileChange {
FileChange {
path: PathBuf::from(new_path),
status: ChangeStatus::Renamed,
diff: Arc::from(""),
additions: 0,
deletions: 0,
category: FileCategory::from_path(&PathBuf::from(new_path)),
is_binary: false,
old_path: Some(PathBuf::from(old_path)),
rename_similarity: Some(similarity),
}
}
#[allow(dead_code)]
pub fn make_staged_changes(files: Vec<FileChange>) -> StagedChanges {
let insertions: usize = files.iter().map(|f| f.additions).sum();
let deletions: usize = files.iter().map(|f| f.deletions).sum();
StagedChanges {
stats: DiffStats {
files_changed: files.len(),
insertions,
deletions,
},
files,
}
}