Skip to content

Commit

Permalink
remove db lookup for bitbucket commit user
Browse files Browse the repository at this point in the history
  • Loading branch information
tapishr committed Oct 26, 2023
1 parent e684411 commit 6b522bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 34 deletions.
14 changes: 5 additions & 9 deletions vibi-dpu/src/bitbucket/reviewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::utils::user::BitbucketUser;

use super::{config::{bitbucket_base_url, get_client, prepare_headers}};

pub async fn add_reviewers(user: &WorkspaceUser, review: &Review, access_token: &str) {
pub async fn add_reviewers(user: &BitbucketUser, review: &Review, access_token: &str) {
let url = prepare_get_prinfo_url(review.repo_owner(), review.repo_name(), review.id());
let get_response = get_pr_info(&url, access_token).await;
let reviewers_opt = add_user_to_reviewers(get_response, user).await;
Expand All @@ -23,7 +23,7 @@ pub async fn add_reviewers(user: &WorkspaceUser, review: &Review, access_token:
put_reviewers(&url, access_token, &put_payload).await;
}

async fn add_user_to_reviewers(response_res: Option<Response>, user_from_db: &WorkspaceUser) -> Option<(Vec<BitbucketUser>, Value)> {
async fn add_user_to_reviewers(response_res: Option<Response>, user_from_db: &BitbucketUser) -> Option<(Vec<BitbucketUser>, Value)> {
let reviewers_opt = parse_reviewers_from_prinfo(response_res).await;
if reviewers_opt.is_none() {
eprintln!("Unable to parse and add reviewers");
Expand All @@ -32,13 +32,9 @@ async fn add_user_to_reviewers(response_res: Option<Response>, user_from_db: &Wo
let (mut reviewers, get_response_json) = reviewers_opt.expect("Empty reviewers_opt");
println!("reviewers = {:?}", reviewers);
println!("user_from_db = {:?}", &user_from_db);
// For each user in user_from_db.users()...
for user in user_from_db.users().iter() {
// If the reviewers vector doesn't contain the user...
if !reviewers.contains(user) {
// Add the user to reviewers
reviewers.push(user.clone());
}
if !reviewers.contains(user_from_db) {
// Add the user to reviewers
reviewers.push(user_from_db.clone());
}
println!("Updated reviewers = {:?}", reviewers);
return Some((reviewers, get_response_json));
Expand Down
29 changes: 4 additions & 25 deletions vibi-dpu/src/core/coverage.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::{HashMap, HashSet};

use crate::{utils::{hunk::{HunkMap, PrHunkItem}, user::BitbucketUser}, db::user::{get_workspace_user_from_db}, bitbucket::{user::author_from_commit, comment::add_comment, reviewer::add_reviewers}};
use crate::{utils::{hunk::{HunkMap, PrHunkItem}, user::{BitbucketUser, WorkspaceUser}}, db::user::{get_workspace_user_from_db}, bitbucket::{user::author_from_commit, comment::add_comment, reviewer::add_reviewers}};
use crate::utils::review::Review;
use crate::utils::repo_config::RepoConfig;
use crate::bitbucket::auth::get_access_token_review;
Expand Down Expand Up @@ -34,37 +34,16 @@ pub async fn process_coverage(hunkmap: &HunkMap, review: &Review, repo_config: &
let blame_author_opt = author_from_commit(blame.commit(),
hunkmap.repo_name(), hunkmap.repo_owner()).await;
if blame_author_opt.is_none() {
eprintln!("[process_coverage] Unable to get blame author for commit: {}", &blame.commit());
eprintln!("[process_coverage] Unable to get blame author from bb for commit: {}", &blame.commit());
continue;
}
let blame_author = blame_author_opt.expect("Empty blame_author_opt");
let user_key = blame_author.display_name().to_string();
let blame_user_opt = get_workspace_user_from_db(&user_key);
if blame_user_opt.is_none() {
eprintln!("[process_coverage] no user found in db for blame author: {:?}", blame_author);
continue;
}
let blame_user = blame_user_opt.expect("Empty blame user");
let bb_blame_user_opt = blame_user.users().iter().find(|user| user.uuid() == blame_author.uuid());
let bb_blame_user: BitbucketUser;
if bb_blame_user_opt.is_none() {
let bb_users: Vec<BitbucketUser> = blame_user.users().iter().cloned().collect();
let user_opt = bb_users.get(0);
if user_opt.is_none() {
eprintln!("[process_coverage] Empty Bitbucket Workspace User: {:?}", &blame_user);
continue;
}
bb_blame_user = user_opt.expect("Empty user_opt").to_owned();
}
else {
bb_blame_user = bb_blame_user_opt.expect("Empty bb_blame_user_opt").to_owned();
}
let author_uuid = bb_blame_user.uuid();
let author_uuid = blame_author.uuid();
if author_set.contains(author_uuid) {
continue;
}
add_reviewers(&blame_author, review, &access_token).await;
author_set.insert(author_uuid.to_string());
add_reviewers(&blame_user, review, &access_token).await;
}
}
}
Expand Down

0 comments on commit 6b522bc

Please sign in to comment.