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

Fix duplicate comment for github #191

Merged
merged 3 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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...");}
tapishr marked this conversation as resolved.
Show resolved Hide resolved
}
}
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);
}
Loading