From 650f6ed0a4e70fbda31e2f5c1974dbbfa7ec5cf1 Mon Sep 17 00:00:00 2001 From: Tapish Rathore Date: Wed, 1 Nov 2023 22:23:27 +0530 Subject: [PATCH] Add file and hunk deletion filter --- vibi-dpu/src/utils/gitops.rs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/vibi-dpu/src/utils/gitops.rs b/vibi-dpu/src/utils/gitops.rs index 6bde3d64..6f33b2eb 100644 --- a/vibi-dpu/src/utils/gitops.rs +++ b/vibi-dpu/src/utils/gitops.rs @@ -151,21 +151,22 @@ pub fn get_excluded_files(review: &Review) -> Option<(Vec, Vec Option<(Vec, Vec)>{ let statvec = process_statitems(statstr); - let mut bigfiles = Vec::::new(); - let mut smallfiles = Vec::::new(); + let mut excluded_files = Vec::::new(); + let mut filtered_files = Vec::::new(); let line_threshold = 500; for item in statvec { // logic for exclusion if (item.additions > line_threshold) || (item.deletions > line_threshold) || - (item.additions + item.deletions > line_threshold) { - bigfiles.push(item); + (item.additions + item.deletions > line_threshold) || + (item.deletions < 1) { + excluded_files.push(item); } else { - smallfiles.push(item); + filtered_files.push(item); } } - return Some((bigfiles, smallfiles)); + return Some((excluded_files, filtered_files)); } fn generate_statitem(statitems: &Vec<&str>) -> StatItem { @@ -253,7 +254,9 @@ fn process_diff(filepath: &str, diff: &str, linemap: &mut HashMap bool { + // Split the hunk into lines + let lines = hunk.split('\n').collect::>(); + + // Iterate through the lines to check for deletions + for line in lines.iter() { + if line.starts_with('-') && !line.starts_with("---") { + return true; + } + } + + return false; +} + pub fn process_diffmap(diffmap: &HashMap) -> HashMap> { let mut linemap: HashMap> = HashMap::new(); for (filepath, diff) in diffmap {