Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diff Graph implementation #187

Merged
merged 45 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4d2b184
Add llm calling and mermaid comment generating functions
tapishr Jun 22, 2024
68b967b
remove token and convert return type to option
tapishr Jun 22, 2024
368d610
Call llm generate api with proper inputs
tapishr Jun 30, 2024
101e01e
Implement prompt formatting and llm calling with blocks of code
tapishr Jul 4, 2024
9442eb5
modularised code and added elemets to generate mermaid components
tapishr Jul 6, 2024
bbc74a8
Add comment generating functions
tapishr Jul 7, 2024
3b62d4c
Add code to render all subgraphs and edges and concatenate
tapishr Jul 7, 2024
d308fbc
Fix prompt path in docker
tapishr Jul 8, 2024
662fe9c
remove import line assumption
tapishr Jul 8, 2024
46475dd
fix response parsing for flinemap
tapishr Jul 8, 2024
ec75135
misc fixes to comment generation and git parsing
tapishr Jul 9, 2024
4f4e26d
implement git checkout
tapishr Jul 9, 2024
683710d
dummy whitespace commit
tapishr Jul 10, 2024
36529f3
Add previous state in function line extraction
tapishr Jul 20, 2024
c9fe29e
re-implement getting function line range
tapishr Jul 26, 2024
e6f3ad9
fix directory traversal and implement numbered content
tapishr Jul 28, 2024
8bb7eb2
Implement edge rendering and diff info generation
tapishr Aug 12, 2024
7cb5769
identify deleted files in diff graph
tapishr Aug 12, 2024
0db988d
separated the relevance & mermaid graph processing functions
avikalpg Sep 2, 2024
bead6d2
create diff_graph in core to handle DiffGraph creation directly from …
avikalpg Sep 2, 2024
a4a7e1e
fix: review: remove the repo-config conditions from calling send_hunk…
avikalpg Sep 3, 2024
c7bba0a
Implement edge rendering and adjacency list
tapishr Sep 3, 2024
6960788
Merge branch 'tr/callPhind' of github.com:vibinex/vibi-dpu into akg/m…
avikalpg Sep 3, 2024
3c9ce00
Merge pull request #183 from vibinex/akg/multi_comment
tapishr Sep 3, 2024
0799afe
fix edge storage and duplication
tapishr Sep 5, 2024
3bc8c64
add node styling and href
tapishr Sep 6, 2024
c47e532
fix node rendering and implement subgraph rendering
tapishr Sep 6, 2024
0eeff01
implement edge rendering and flowchart config fix
tapishr Sep 6, 2024
cfe569f
misc fixes and todos
tapishr Sep 6, 2024
de19077
add edge link
tapishr Sep 6, 2024
9fe33f9
fixed adding func calls for hunks
tapishr Sep 16, 2024
ac70d68
fix flowchart text and relative path
tapishr Sep 17, 2024
06d34e4
stored diff func calls in diff graph struct
tapishr Sep 23, 2024
40f427e
fix empty name in nodes
tapishr Sep 24, 2024
3413a48
rewrite import and function call import
tapishr Oct 3, 2024
6dba807
Implement looking up file path from import
tapishr Oct 10, 2024
5094866
Add prompts and ripgrep to dockerfile
tapishr Oct 10, 2024
2d41069
Implement looking at one func def at one time
tapishr Oct 11, 2024
67672f1
fix func def schema description and parsing func line from git diff
tapishr Oct 11, 2024
99bc426
fix function line matching
tapishr Oct 11, 2024
691fb56
Implement getting function name from llm
tapishr Oct 12, 2024
eb00357
cache func name, add language and fix abs path in rg
tapishr Oct 12, 2024
d67a36a
fix identifying diff files with language
tapishr Oct 12, 2024
81a289c
remove strsim
tapishr Oct 12, 2024
0ba7fc5
update version and remove strsim
tapishr Oct 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM ubuntu:latest
# # Install dependencies required by the application
RUN \
apt-get update && \
apt-get install ca-certificates git -y && \
apt-get install ca-certificates git ripgrep -y && \
apt-get clean
ADD http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb /tmp
RUN chmod a+x /tmp/libssl1.1_1.1.1f-1ubuntu2_amd64.deb && \
Expand Down Expand Up @@ -45,7 +45,7 @@ ENV PROVIDER=$PROVIDER
COPY ./vibi-dpu/target/debug/vibi-dpu /app/vibi-dpu
COPY ./pubsub-sa.json /app/pubsub-sa.json
COPY ./repo-profiler.pem /app/repo-profiler.pem

COPY ./prompts /app/prompts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Issue Detected with prompts Directory

The prompts directory does not exist in the repository, which will cause the Docker build to fail when attempting to copy it.

  • Dockerfile (Line 48)
    COPY ./prompts /app/prompts
    
🔗 Analysis chain

New step to copy 'prompts' directory: Approved

The addition of this step to copy the ./prompts directory into the container at /app/prompts suggests that the application now utilizes prompt files. This is likely related to new functionality, possibly involving AI or templating features.

To ensure the prompts directory exists and contains necessary files, let's run a verification script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the existence and contents of the prompts directory

# Check if the prompts directory exists
if [ -d "./prompts" ]; then
    echo "prompts directory exists."
    # List contents of the prompts directory
    echo "Contents of prompts directory:"
    ls -la ./prompts
else
    echo "Error: prompts directory does not exist."
fi

Length of output: 113

# Create directory for configuration
RUN mkdir /app/config

Expand Down
6 changes: 3 additions & 3 deletions vibi-dpu/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vibi-dpu"
version = "1.0.0"
version = "2.0.0"
edition = "2021"
authors = ["Tapish Rathore <tapish@vibinex.com>"]
license = "GPL-3.0-or-later"
Expand All @@ -21,7 +21,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
base64ct = "1.5.3"
sha256 = "1.1.1"
reqwest = { version = "0.11", features = ["json", "blocking"] }
reqwest = { version = "0.11", features = ["json", "blocking", "stream"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

The "stream" feature added to reqwest is not utilized in the codebase.

Consider removing this feature to maintain minimal and efficient dependencies.

🔗 Analysis chain

Verify usage of the new reqwest "stream" feature.

The addition of the "stream" feature to the reqwest dependency is a good improvement that can enable more efficient handling of large HTTP responses.

To ensure this new feature is being utilized, please run the following script to check for its usage in the codebase:

If the feature is not currently used, consider removing it to keep the dependencies minimal, or add a TODO comment to implement streaming in the future.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of reqwest streaming functionality

# Test: Search for common streaming methods from reqwest
rg --type rust 'reqwest::.*Client.*stream' || echo "No direct usage of reqwest streaming found."

Length of output: 141

google-cloud-pubsub = "0.15.0"
google-cloud-default = { version = "0.3.0", features = ["pubsub"] }
google-cloud-googleapis = "0.9.0"
Expand All @@ -37,5 +37,5 @@ once_cell = "1.18.0" # MIT
jsonwebtoken = "8.3.0" # MIT
fern = "0.6.2" # MIT
log = "0.4.20" # MIT/Apache2

walkdir = "2.5.0" # Unlicence/MIT
# todo - check all lib licences
46 changes: 46 additions & 0 deletions vibi-dpu/src/core/diff_graph.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use crate::graph::mermaid_elements::generate_mermaid_flowchart;
use crate::utils::user::ProviderEnum;
use crate::utils::review::Review;
use crate::core::github;
use crate::utils::gitops::StatItem;

pub async fn send_diff_graph(review: &Review, excluded_files: &Vec<StatItem>, small_files: &Vec<StatItem>, access_token: &str) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use slices &[StatItem] instead of &Vec<StatItem> for function parameters

In Rust, it's more idiomatic to accept slices (&[T]) rather than references to vectors (&Vec<T>). This allows for more flexible function signatures and can accept both slices and vectors without unnecessary constraints.

Apply this diff to update the function signatures:

-pub async fn send_diff_graph(review: &Review, excluded_files: &Vec<StatItem>, small_files: &Vec<StatItem>, access_token: &str) {
+pub async fn send_diff_graph(review: &Review, excluded_files: &[StatItem], small_files: &[StatItem], access_token: &str) {
-async fn diff_graph_comment_text(excluded_files: &Vec<StatItem>, small_files: &Vec<StatItem>, review: &Review) -> String {
+async fn diff_graph_comment_text(excluded_files: &[StatItem], small_files: &[StatItem], review: &Review) -> String {
-async fn mermaid_comment(diff_files: &Vec<StatItem>, review: &Review) -> Option<String> {
+async fn mermaid_comment(diff_files: &[StatItem], review: &Review) -> Option<String> {

Also applies to: 18-18, 33-33

let comment = diff_graph_comment_text(excluded_files, small_files, review).await;
// add comment for GitHub
if review.provider().to_string() == ProviderEnum::Github.to_string() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Simplify enum comparison by matching enum variants directly

Instead of converting enums to strings for comparison, you can compare enums directly. This makes the code more idiomatic and efficient.

Apply this diff to simplify the comparison:

-if review.provider().to_string() == ProviderEnum::Github.to_string() {
+if review.provider() == &ProviderEnum::Github {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if review.provider().to_string() == ProviderEnum::Github.to_string() {
if review.provider() == &ProviderEnum::Github {

log::info!("Inserting comment on repo {}...", review.repo_name());
github::comment::add_comment(&comment, review, &access_token).await;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid passing unnecessary references to access_token

Since access_token is already a &str, passing &access_token results in an unnecessary double reference (&&str). You can pass access_token directly.

Apply this diff to correct the function call:

-		github::comment::add_comment(&comment, review, &access_token).await;
+		github::comment::add_comment(&comment, review, access_token).await;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
github::comment::add_comment(&comment, review, &access_token).await;
github::comment::add_comment(&comment, review, access_token).await;

}

// TODO: add comment for Bitbucket
}

async fn diff_graph_comment_text(excluded_files: &Vec<StatItem>, small_files: &Vec<StatItem>, review: &Review) -> String {
let mut comment = "Diff Graph:\n\n".to_string();

let all_diff_files: Vec<StatItem> = excluded_files
.iter()
.chain(small_files.iter())
.cloned() // Clone the StatItem instances since `iter` returns references
.collect(); // Collect into a new vector
if let Some(mermaid_text) = mermaid_comment(&all_diff_files, review).await {
comment += mermaid_text.as_str();
}
comment += "\nTo modify DiffGraph settings, go to [your Vibinex settings page.](https://vibinex.com/settings)\n";
return comment;
}

async fn mermaid_comment(diff_files: &Vec<StatItem>, review: &Review) -> Option<String> {
let flowchart_str_opt = generate_mermaid_flowchart(diff_files, review).await;
if flowchart_str_opt.is_none() {
log::error!("[mermaid_comment] Unable to generate flowchart for review: {}", review.id());
return None;
}
let flowchart_str = flowchart_str_opt.expect("Empty flowchart_str_opt");
Comment on lines +33 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify mermaid_comment function using if let

You can streamline the handling of flowchart_str_opt by using if let Some(...) instead of separately checking for None and then unwrapping with expect.

Apply this diff to refactor the function:

 async fn mermaid_comment(diff_files: &[StatItem], review: &Review) -> Option<String> {
-    let flowchart_str_opt = generate_mermaid_flowchart(diff_files, review).await;
-    if flowchart_str_opt.is_none() {
+    if let Some(flowchart_str) = generate_mermaid_flowchart(diff_files, review).await {
+        let mermaid_comment = format!(
+            "### Call Stack Diff\n```mermaid\n{}\n```",
+            flowchart_str,
+        );
+        Some(mermaid_comment)
+    } else {
         log::error!("[mermaid_comment] Unable to generate flowchart for review: {}", review.id());
-        return None;
-    }
-    let flowchart_str = flowchart_str_opt.expect("Empty flowchart_str_opt");
-    let mermaid_comment = format!(
-        "### Call Stack Diff\n```mermaid\n{}\n```",
-        flowchart_str,
-    );
-    return Some(mermaid_comment);
+        None
+    }
 }

let mermaid_comment = format!(
"### Call Stack Diff\n```mermaid\n{}\n```",
flowchart_str,
);
return Some(mermaid_comment);
}

3 changes: 2 additions & 1 deletion vibi-dpu/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pub mod utils;
pub mod approval;
pub mod bitbucket;
pub mod github;
pub mod trigger;
pub mod trigger;
pub mod diff_graph;
18 changes: 13 additions & 5 deletions vibi-dpu/src/core/relevance.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::collections::{HashMap, HashSet};

use crate::{bitbucket::{self, user::author_from_commit}, core::github, db::review::save_review_to_db, utils::{aliases::get_login_handles, relevance::Relevance, hunk::{HunkMap, PrHunkItem}, user::ProviderEnum}};
use crate::{bitbucket::{self, user::author_from_commit}, core::github, db::review::save_review_to_db, utils::{aliases::get_login_handles, gitops::StatItem, hunk::{HunkMap, PrHunkItem}, relevance::Relevance, user::ProviderEnum}};
use crate::utils::review::Review;
use crate::utils::repo_config::RepoConfig;

pub async fn process_relevance(hunkmap: &HunkMap, review: &Review,
pub async fn process_relevance(hunkmap: &HunkMap, excluded_files: &Vec<StatItem>, review: &Review,
repo_config: &mut RepoConfig, access_token: &str, old_review_opt: &Option<Review>,
) {
log::info!("Processing relevance of code authors...");
Expand All @@ -22,7 +22,7 @@ pub async fn process_relevance(hunkmap: &HunkMap, review: &Review,
let relevance_vec = relevance_vec_opt.expect("Empty coverage_obj_opt");
if repo_config.comment() {
// create comment text
let comment = comment_text(&relevance_vec, repo_config.auto_assign());
let comment = relevant_reviewers_comment_text(&relevance_vec, repo_config.auto_assign(), excluded_files).await;
// add comment
if review.provider().to_string() == ProviderEnum::Bitbucket.to_string() {
// TODO - add feature flag check
Expand Down Expand Up @@ -184,7 +184,8 @@ async fn calculate_relevance(prhunk: &PrHunkItem, review: &mut Review) -> Option
return Some(relevance_vec);
}

fn comment_text(relevance_vec: &Vec<Relevance>, auto_assign: bool) -> String {
async fn relevant_reviewers_comment_text(relevance_vec: &Vec<Relevance>, auto_assign: bool,
excluded_files: &Vec<StatItem>) -> String {
Comment on lines +187 to +188
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove unnecessary async and replace &Vec<T> with slices

The function relevant_reviewers_comment_text does not perform any asynchronous operations or use await. Consider removing the async keyword. Additionally, replacing &Vec<T> with slices &[T] can make your function more flexible and idiomatic.

Apply this diff to update the function signature:

-async fn relevant_reviewers_comment_text(relevance_vec: &Vec<Relevance>, auto_assign: bool,
-    excluded_files: &Vec<StatItem>) -> String {
+fn relevant_reviewers_comment_text(relevance_vec: &[Relevance], auto_assign: bool,
+    excluded_files: &[StatItem]) -> String {

Remember to update any calls to this function and adjust the parameter usages within the function body accordingly.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async fn relevant_reviewers_comment_text(relevance_vec: &Vec<Relevance>, auto_assign: bool,
excluded_files: &Vec<StatItem>) -> String {
fn relevant_reviewers_comment_text(relevance_vec: &[Relevance], auto_assign: bool,
excluded_files: &[StatItem]) -> String {

let mut comment = "Relevant users for this PR:\n\n".to_string(); // Added two newlines
comment += "| Contributor Name/Alias | Relevance |\n"; // Added a newline at the end
comment += "| -------------- | --------------- |\n"; // Added a newline at the end
Expand All @@ -208,6 +209,14 @@ fn comment_text(relevance_vec: &Vec<Relevance>, auto_assign: bool) -> String {
comment += &format!("Missing profile handles for {} aliases. [Go to your Vibinex settings page](https://vibinex.com/settings) to map aliases to profile handles.", unmapped_aliases.len());
}

if !excluded_files.is_empty() {
comment += "\n\n";
comment += "Ignoring following files due to large size: ";
for file_item in excluded_files {
comment += &format!("- {}\n", file_item.filepath.as_str());
}
}

if auto_assign {
comment += "\n\n";
comment += "Auto assigning to relevant reviewers.";
Expand All @@ -216,7 +225,6 @@ fn comment_text(relevance_vec: &Vec<Relevance>, auto_assign: bool) -> String {
comment += "If you are a relevant reviewer, you can use the [Vibinex browser extension](https://chromewebstore.google.com/detail/vibinex-code-review/jafgelpkkkopeaefadkdjcmnicgpcncc) to see parts of the PR relevant to you\n"; // Added a newline at the end
comment += "Relevance of the reviewer is calculated based on the git blame information of the PR. To know more, hit us up at contact@vibinex.com.\n\n"; // Added two newlines
comment += "To change comment and auto-assign settings, go to [your Vibinex settings page.](https://vibinex.com/u)\n"; // Added a newline at the end

return comment;
}

Expand Down
42 changes: 30 additions & 12 deletions vibi-dpu/src/core/review.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use std::env;
use std::{env, thread, time::Duration};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Replace thread::sleep with asynchronous tokio::time::sleep

Using thread::sleep in an asynchronous context blocks the entire thread, which can lead to performance issues in an async runtime. Instead, use tokio::time::sleep(Duration::from_secs(1)).await to asynchronously suspend the task without blocking other tasks.

Apply this diff to fix the issue:

-use std::{env, thread, time::Duration};
+use std::{env};
+use tokio::time::{sleep, Duration};

At line 129:

-        thread::sleep(Duration::from_secs(1));
+        sleep(Duration::from_secs(1)).await;

Also applies to: 129-129

use serde_json::Value;

use crate::{
core::{relevance::process_relevance, utils::get_access_token},
core::{relevance::process_relevance, diff_graph::send_diff_graph, utils::get_access_token},
db::{
hunk::{get_hunk_from_db, store_hunkmap_to_db},
repo::get_clone_url_clone_dir,
repo_config::save_repo_config_to_db,
review::{get_review_from_db, save_review_to_db},
},
utils::{
gitops::{commit_exists, generate_blame, generate_diff, get_excluded_files, git_pull, process_diffmap},
gitops::{commit_exists, generate_blame, generate_diff, get_excluded_files, git_pull, process_diffmap, StatItem},
hunk::{HunkMap, PrHunkItem},
repo_config::RepoConfig,
reqwest_client::get_client,
Expand Down Expand Up @@ -41,11 +41,24 @@ pub async fn process_review(message_data: &Vec<u8>) {
}
let access_token = access_token_opt.expect("Empty access_token_opt");
commit_check(&review, &access_token).await;
let hunkmap_opt = process_review_changes(&review).await;
send_hunkmap(&hunkmap_opt, &review, &repo_config, &access_token, &old_review_opt).await;
process_review_changes(&review, &repo_config, &access_token, &old_review_opt).await;
}

pub async fn send_hunkmap(hunkmap_opt: &Option<HunkMap>, review: &Review,
pub async fn process_review_changes(review: &Review, repo_config: &RepoConfig, access_token: &str, old_review_opt: &Option<Review>) {
log::info!("Processing changes in code...");
if let Some((excluded_files, smallfiles)) = get_included_and_excluded_files(review) {
let hunkmap_opt = calculate_hunkmap(review, &smallfiles).await;
send_hunkmap(&hunkmap_opt, &excluded_files, review, repo_config, access_token, old_review_opt).await;

if repo_config.diff_graph() {
send_diff_graph(review, &excluded_files, &smallfiles, access_token).await;
}
} else {
log::error!("Failed to get included and excluded files");
}
}
Comment on lines +49 to +58
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Return early when failing to get included and excluded files

In process_review_changes, after logging the error for failing to retrieve files, the function should return early to prevent further execution with invalid data, which could lead to unintended behavior.

Apply this diff:

         } else {
             log::error!("Failed to get included and excluded files");
+            return;
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if let Some((excluded_files, smallfiles)) = get_included_and_excluded_files(review) {
let hunkmap_opt = calculate_hunkmap(review, &smallfiles).await;
send_hunkmap(&hunkmap_opt, &excluded_files, review, repo_config, access_token, old_review_opt).await;
if repo_config.diff_graph() {
send_diff_graph(review, &excluded_files, &smallfiles, access_token).await;
}
} else {
log::error!("Failed to get included and excluded files");
}
if let Some((excluded_files, smallfiles)) = get_included_and_excluded_files(review) {
let hunkmap_opt = calculate_hunkmap(review, &smallfiles).await;
send_hunkmap(&hunkmap_opt, &excluded_files, review, repo_config, access_token, old_review_opt).await;
if repo_config.diff_graph() {
send_diff_graph(review, &excluded_files, &smallfiles, access_token).await;
}
} else {
log::error!("Failed to get included and excluded files");
return;
}


pub async fn send_hunkmap(hunkmap_opt: &Option<HunkMap>, excluded_files: &Vec<StatItem>, review: &Review,
repo_config: &RepoConfig, access_token: &str, old_review_opt: &Option<Review>) {
if hunkmap_opt.is_none() {
log::error!("[send_hunkmap] Empty hunkmap in send_hunkmap");
Expand All @@ -58,7 +71,7 @@ pub async fn send_hunkmap(hunkmap_opt: &Option<HunkMap>, review: &Review,
let hunkmap_async = hunkmap.clone();
let review_async = review.clone();
let mut repo_config_clone = repo_config.clone();
process_relevance(&hunkmap_async, &review_async,
process_relevance(&hunkmap_async, &excluded_files, &review_async,
&mut repo_config_clone, access_token, old_review_opt).await;
}

Expand All @@ -73,16 +86,20 @@ fn hunk_already_exists(review: &Review) -> bool {
log::debug!("[hunk_already_exists] Hunk already in db!");
return true;
}
pub async fn process_review_changes(review: &Review) -> Option<HunkMap>{
log::info!("Processing changes in code...");
let mut prvec = Vec::<PrHunkItem>::new();

fn get_included_and_excluded_files(review: &Review) -> Option<(Vec<StatItem>, Vec<StatItem>)> {
let fileopt = get_excluded_files(&review);
log::debug!("[process_review_changes] fileopt = {:?}", &fileopt);
if fileopt.is_none() {
log::error!("[process_review_changes] No files to review for PR {}", review.id());
return None;
}
let (_, smallfiles) = fileopt.expect("fileopt is empty");
let (excluded_files, smallfiles) = fileopt.expect("fileopt is empty");
return Some(( excluded_files, smallfiles));
}

async fn calculate_hunkmap(review: &Review, smallfiles: &Vec<StatItem>) -> Option<HunkMap> {
let mut prvec = Vec::<PrHunkItem>::new();
let diffmap = generate_diff(&review, &smallfiles);
log::debug!("[process_review_changes] diffmap = {:?}", &diffmap);
let linemap = process_diffmap(&diffmap);
Expand All @@ -109,6 +126,7 @@ pub async fn commit_check(review: &Review, access_token: &str) {
if !commit_exists(&review.base_head_commit(), &review.clone_dir())
|| !commit_exists(&review.pr_head_commit(), &review.clone_dir()) {
log::info!("Executing git pull on repo {}...", &review.repo_name());
thread::sleep(Duration::from_secs(1));
git_pull(review, access_token).await;
}
}
Expand Down Expand Up @@ -213,7 +231,7 @@ fn create_and_save_github_review_object(deserialized_data: &Value) -> Option<Rev
let repo_provider = ProviderEnum::Github.to_string().to_lowercase();
let clone_opt = get_clone_url_clone_dir(&repo_provider, &repo_owner, &repo_name);
if clone_opt.is_none() {
log::error!("[create_and_save_github_review_object] Unable to get clone url and directory for bitbucket review");
log::error!("[create_and_save_github_review_object] Unable to get clone url and directory for github review");
return None;
}
let (clone_url, clone_dir) = clone_opt.expect("Empty clone_opt");
Expand Down
4 changes: 1 addition & 3 deletions vibi-dpu/src/core/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ pub async fn process_trigger(message_data: &Vec<u8>) {
// commit_check
commit_check(&review, &access_token).await;
// process_review_changes
let hunkmap_opt = process_review_changes(&review).await;
// send_hunkmap
send_hunkmap(&hunkmap_opt, &review, &repo_config, &access_token, &None).await;
process_review_changes(&review, &repo_config, &access_token, &None).await;
}

fn parse_message_fields(msg: &Value) -> Option<TriggerReview> {
Expand Down
2 changes: 1 addition & 1 deletion vibi-dpu/src/db/review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn get_review_from_db(repo_name: &str, repo_owner: &str,
let review_res = serde_json::from_slice(&ivec);
if let Err(e) = review_res {
log::error!(
"[get_handles_from_db] Failed to deserialize review from json: {:?}",
"[get_review_from_db] Failed to deserialize review from json: {:?}",
e
);
return None;
Expand Down
Loading
Loading