From 6836c1eabf60f14ad99633b57f8f7dc976a6485a Mon Sep 17 00:00:00 2001 From: Avikalp Kumar Gupta Date: Mon, 30 Oct 2023 21:08:59 +0530 Subject: [PATCH 1/2] bug fix: PR not getting detected - no entry in database (#54) * bug fix: removed IVec of value while inserting pr_info * bug fix: database key changed for PR-info to resolve key collision. --- vibi-dpu/src/db/prs.rs | 7 +++---- vibi-dpu/src/pubsub/listener.rs | 28 +--------------------------- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/vibi-dpu/src/db/prs.rs b/vibi-dpu/src/db/prs.rs index 8ceb2b6c..c02bf39f 100644 --- a/vibi-dpu/src/db/prs.rs +++ b/vibi-dpu/src/db/prs.rs @@ -4,7 +4,7 @@ use crate::db::config::get_db; use crate::utils::pr_info::PrInfo; pub async fn update_pr_info_in_db(workspace_slug: &str, repo_slug: &str, pr_info: &PrInfo, pr_number: &str) { - let key = format!("{}/{}/{}/{}", "bitbucket", workspace_slug, repo_slug, pr_number); + let key = format!("pr_info/{}/{}/{}/{}", "bitbucket", workspace_slug, repo_slug, pr_number); let db = get_db(); let pr_info_json_result = serde_json::to_vec(&pr_info); @@ -18,7 +18,7 @@ pub async fn update_pr_info_in_db(workspace_slug: &str, repo_slug: &str, pr_info let pr_info_bytes = pr_info_json_result.expect("empty pr_info_json_result"); // Update the entry in the database. It will create a new entry if the key does not exist. - let update_result = db.insert(IVec::from(key.as_bytes()), IVec::from(pr_info_bytes)); + let update_result = db.insert(IVec::from(key.as_bytes()), pr_info_bytes); if update_result.is_err() { let e = update_result.expect_err("No error in updating pr_info"); @@ -41,7 +41,6 @@ pub async fn process_and_update_pr_if_different(webhook_data: &Value, workspace_ let pr_info_db_opt = get_pr_info_from_db(workspace_slug, repo_slug, pr_number, repo_provider, &pr_info_parsed).await; if pr_info_db_opt.is_none() { eprintln!("[process_and_update_pr_if_different] No pr_info in db, parsed: {:?}", pr_info_parsed); - update_pr_info_in_db(&workspace_slug, &repo_slug, &pr_info_parsed, &pr_number).await; return true; // new pr } let pr_info_db = pr_info_db_opt.expect("Empty pr_info_db_opt"); @@ -74,7 +73,7 @@ fn parse_webhook_data(webhook_data: &Value) -> Option { pub async fn get_pr_info_from_db(workspace_slug: &str, repo_slug: &str, pr_number: &str, repo_provider: &str, pr_info_parsed: &PrInfo) -> Option { let db = get_db(); - let db_pr_key = format!("{}/{}/{}/{}", repo_provider, workspace_slug, repo_slug, pr_number); + let db_pr_key = format!("pr_info/{}/{}/{}/{}", repo_provider, workspace_slug, repo_slug, pr_number); let pr_info_res = db.get(IVec::from(db_pr_key.as_bytes())); if pr_info_res.is_err() { diff --git a/vibi-dpu/src/pubsub/listener.rs b/vibi-dpu/src/pubsub/listener.rs index 6b21fe5a..bd941726 100644 --- a/vibi-dpu/src/pubsub/listener.rs +++ b/vibi-dpu/src/pubsub/listener.rs @@ -12,7 +12,7 @@ use tokio::task; use std::collections::VecDeque; use sha256::digest; use tonic::Code; -use crate::{db::prs::process_and_update_pr_if_different, utils::user::ProviderEnum}; +use crate::db::prs::process_and_update_pr_if_different; use crate::core::{setup::handle_install_bitbucket, review::process_review}; #[derive(Debug, Deserialize)] @@ -72,32 +72,6 @@ async fn process_message(attributes: &HashMap, data_bytes: &Vec< }; } - -async fn prcoess_install_callback(data_bytes: &[u8]) { - println!("Processing install callback message"); - let msg_data_res = serde_json::from_slice::(data_bytes); - if msg_data_res.is_err() { - eprintln!("Error deserializing install callback: {:?}", msg_data_res); - return; - } - let data = msg_data_res.expect("msg_data not found"); - if data.repository_provider == ProviderEnum::Github.to_string().to_lowercase() { - println!("To be Implemented"); - // let code_async = data.installation_code.clone(); - // task::spawn(async move { - // handle_install_github(&code_async).await; - // println!("Processed install callback message"); - // }); - } - if data.repository_provider == ProviderEnum::Bitbucket.to_string().to_lowercase() { - let code_async = data.installation_code.clone(); - task::spawn(async move { - handle_install_bitbucket(&code_async).await; - println!("Processed install callback message"); - }); - } -} - pub async fn get_pubsub_client_config(keypath: &str) -> ClientConfig { let credfile = CredentialsFile::new_from_file(keypath.to_string()).await .expect("Failed to locate credentials file"); From 89d8086866aaa578967428212169f88bb2d11adf Mon Sep 17 00:00:00 2001 From: Tapish Rathore Date: Wed, 1 Nov 2023 19:42:42 +0530 Subject: [PATCH 2/2] added zero deletion file filter --- vibi-dpu/src/utils/gitops.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/vibi-dpu/src/utils/gitops.rs b/vibi-dpu/src/utils/gitops.rs index 6bde3d64..6b0d2b05 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 < 0) { + 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 {