Skip to content

Commit

Permalink
Merge pull request #191 from vibinex/tr/duplicate/comment
Browse files Browse the repository at this point in the history
Fix duplicate comment for github
  • Loading branch information
tapishr authored Oct 13, 2024
2 parents 44d25f4 + 4feef09 commit 2ffdd2b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion vibi-dpu/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vibi-dpu"
version = "2.0.2"
version = "2.0.3"
edition = "2021"
authors = ["Tapish Rathore <tapish@vibinex.com>"]
license = "GPL-3.0-or-later"
Expand Down
26 changes: 12 additions & 14 deletions vibi-dpu/src/core/relevance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,19 @@ pub async fn process_relevance(hunkmap: &HunkMap, excluded_files: &Vec<StatItem>
}
let relevance_vec = relevance_vec_opt.expect("Empty coverage_obj_opt");
if repo_config.comment() {
// create comment text
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
// TODO - add comment change check
if did_comment_change(&relevance_vec, &old_review_opt) {
if did_comment_change(&relevance_vec, &old_review_opt) {
// create comment text
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() {
log::info!("Inserting comment on repo {}...", review.repo_name());
bitbucket::comment::add_comment(&comment, review, &access_token).await;
}
if review.provider().to_string() == ProviderEnum::Github.to_string() {
log::info!("Inserting comment on repo {}...", review.repo_name());
bitbucket::comment::add_comment(&comment, review, &access_token).await;
} else { log::info!("No changes in author relevance, not adding comment...");}
}
if review.provider().to_string() == ProviderEnum::Github.to_string() {
log::info!("Inserting comment on repo {}...", review.repo_name());
github::comment::add_comment(&comment, review, &access_token).await;
}
github::comment::add_comment(&comment, review, &access_token).await;
} else { log::info!("No changes in author relevance, not adding comment...");}
}
}
if repo_config.auto_assign() {
log::info!("Auto assigning reviewers for repo {}...", review.repo_name());
Expand Down
11 changes: 6 additions & 5 deletions vibi-dpu/src/core/review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn parse_review(message_data: &Vec<u8>) -> (Option<(Review, RepoConfig)>, Option
let (review_opt, old_review_opt): (Option<Review>, Option<Review>) = if repo_provider == ProviderEnum::Bitbucket.to_string().to_lowercase() {
create_and_save_bitbucket_review_object(&deserialized_data)
} else if repo_provider == ProviderEnum::Github.to_string().to_lowercase() {
(create_and_save_github_review_object(&deserialized_data), None)
create_and_save_github_review_object(&deserialized_data)
} else {
(None, None)
};
Expand Down Expand Up @@ -224,18 +224,19 @@ fn create_and_save_bitbucket_review_object(deserialized_data: &Value) -> (Option
return (Some(review), old_review_opt);
}

fn create_and_save_github_review_object(deserialized_data: &Value) -> Option<Review> {
fn create_and_save_github_review_object(deserialized_data: &Value) -> (Option<Review>, Option<Review>) {
log::debug!("[create_and_save_github_review_object] deserialised_data {}", deserialized_data);
let repo_owner = deserialized_data["eventPayload"]["repository"]["owner"]["login"].to_string().trim_matches('"').to_string();
let repo_name = deserialized_data["eventPayload"]["repository"]["name"].to_string().trim_matches('"').to_string();
let repo_provider = ProviderEnum::Github.to_string().to_lowercase();
let pr_id = deserialized_data["eventPayload"]["pull_request"]["number"].to_string().trim_matches('"').to_string();
let old_review_opt = get_review_from_db(&repo_name, &repo_owner, &repo_provider, &pr_id);
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 github review");
return None;
return (None,old_review_opt);
}
let (clone_url, clone_dir) = clone_opt.expect("Empty clone_opt");
let pr_id = deserialized_data["eventPayload"]["pull_request"]["number"].to_string().trim_matches('"').to_string();
let review = Review::new(
deserialized_data["eventPayload"]["pull_request"]["base"]["sha"].to_string().replace("\"", ""),
deserialized_data["eventPayload"]["pull_request"]["head"]["sha"].to_string().replace("\"", ""),
Expand All @@ -251,5 +252,5 @@ fn create_and_save_github_review_object(deserialized_data: &Value) -> Option<Rev
);
log::debug!("[create_and_save_github_review_object] github review object = {:?}", &review);
save_review_to_db(&review);
return Some(review);
return (Some(review), old_review_opt);
}

0 comments on commit 2ffdd2b

Please sign in to comment.