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

Chrome extension author display name fix #29

Merged
merged 23 commits into from
Oct 26, 2023
Merged

Chrome extension author display name fix #29

merged 23 commits into from
Oct 26, 2023

Conversation

tapishr
Copy link
Member

@tapishr tapishr commented Oct 26, 2023

Please check the action items covered in the PR -

  • Build is running
  • Manual QA

Summary by CodeRabbit

  • Refactor: Enhanced the reviewer addition process in the codebase by simplifying the user handling logic, improving the clarity and modularity of the code.
  • New Feature: Introduced a function to retrieve author information directly from a commit in a Bitbucket repository, providing more accurate and efficient data retrieval.
  • Refactor: Updated the code handling process to improve error management and data extraction, enhancing the reliability and readability of the code.
  • Refactor: Simplified the code structure by removing unused imports and parameters, and introducing helper functions, making the code easier to maintain and understand.
  • New Feature: Added new fields to the BlameItem and LineItem structures to store commit information, providing more comprehensive data for each item.

@tapishr tapishr self-assigned this Oct 26, 2023
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 26, 2023

Walkthrough

The pull request introduces significant changes to improve the modularity and readability of the code. It modifies the handling of user and commit data by passing objects instead of keys or IDs, and refactors several functions for better error handling and clarity. The changes also include the addition of new fields to the BlameItem and LineItem structs and the introduction of helper functions to extract author and timestamp information.

Changes

File Path Summary
vibi-dpu/src/bitbucket/reviewer.rs The add_reviewers and add_user_to_reviewers functions are modified to accept BitbucketUser objects instead of user keys. The logic for adding users to the reviewers list is simplified.
vibi-dpu/src/bitbucket/user.rs Introduces a new function author_from_commit to retrieve author information from a commit, replacing the existing get_commit_bb function.
vibi-dpu/src/core/coverage.rs Updates import statements, calls author_from_commit to get blame authors, improves error handling, and modifies the add_reviewers function to accept BitbucketUser objects.
vibi-dpu/src/utils/gitops.rs Removes unused imports, modifies function signatures, and adds helper functions to extract author and timestamp information.
vibi-dpu/src/utils/hunk.rs and vibi-dpu/src/utils/lineitem.rs Adds a new commit field to the BlameItem and LineItem structs, respectively, and modifies related methods.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 98cbf40 and a5d403c.
Files selected for processing (6)
  • vibi-dpu/src/bitbucket/reviewer.rs (1} hunks)
  • vibi-dpu/src/bitbucket/user.rs (3} hunks)
  • vibi-dpu/src/core/coverage.rs (2} hunks)
  • vibi-dpu/src/utils/gitops.rs (6} hunks)
  • vibi-dpu/src/utils/hunk.rs (3} hunks)
  • vibi-dpu/src/utils/lineitem.rs (2} hunks)
Files skipped from review due to trivial changes (2)
  • vibi-dpu/src/utils/gitops.rs
  • vibi-dpu/src/utils/lineitem.rs
Additional comments: 10
vibi-dpu/src/bitbucket/user.rs (3)
  • 6-6: The import of User, Provider, and ProviderEnum is new in this hunk. Ensure that these are used in the code that follows this hunk. Unused imports can lead to unnecessary code clutter.

  • 21-23: The function author_from_commit is a new addition and replaces the old get_commit_bb function. The new function returns an Option<BitbucketUser> instead of Option<LineItem>. Ensure that this change is reflected in all places where this function is called.

  • 43-51: The error handling in this hunk is improved compared to the old hunk. The new code checks if the deserialization of the author is successful and returns None if it fails. This is a good practice as it prevents the program from panicking at runtime due to unexpected data.

vibi-dpu/src/bitbucket/reviewer.rs (2)
  • 13-24: The function add_reviewers has been refactored to accept a WorkspaceUser object directly instead of a user_key. This change eliminates the need to fetch user data from the database using a key, which can improve performance. However, ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 26-33: The function add_user_to_reviewers has also been refactored to accept a WorkspaceUser object directly. This change simplifies the function by removing the need to handle potential errors when fetching user data from the database. However, the function now assumes that the WorkspaceUser object is valid and contains the necessary user data. Ensure that this assumption holds true in all cases where this function is called.

vibi-dpu/src/utils/hunk.rs (3)
  • 29-30: The addition of the commit field to the BlameItem struct is a good move for storing commit information. However, the #[serde(skip_serializing)] attribute will prevent this field from being serialized. If this is the intended behavior, then it's fine. But if you want to serialize this field, you should remove this attribute.

  • 41-49: The new method of BlameItem has been updated to include the commit parameter. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 74-76: The getter method for the commit field has been correctly implemented.

---suggestion---
There is no setter method for the commit field. If you need to change the commit field after a BlameItem has been created, you should add a setter method for it. Here's how you can do it:

pub fn set_commit(&mut self, commit: String) {
    self.commit = commit;
}
vibi-dpu/src/core/coverage.rs (2)
  • 3-3: The import of user::BitbucketUser and user::author_from_commit has been added. Ensure that these new imports are used in the code and are not left unused.

  • 28-55: The logic for adding reviewers has been significantly changed. Instead of directly using the author of the blame, the commit of the blame is used to get the author information using the author_from_commit function. This author information is then used to get the workspace user from the database. If the workspace user is not found, the blame is skipped. If the workspace user is found, the first user in the users list of the workspace user is used as the actual blame user. The UUID of the actual blame user is then used to check if the user is already in the author set. If the user is not in the author set, the user is added to the author set and the add_reviewers function is called with the workspace user.

This change improves the accuracy of the reviewer assignment by ensuring that the author of the blame is a valid workspace user. However, it also introduces additional complexity and potential performance overhead due to the additional database query and the use of the author_from_commit function. Consider optimizing this logic if performance becomes an issue.

Also, the code assumes that the first user in the users list of the workspace user is the actual blame user. This may not always be the case. Consider improving the logic to accurately determine the actual blame user.

- add_reviewers(blame.author(), review, &access_token).await;
+ 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());
+     continue;
+ }
+ let blame_author = blame_author_opt.expect("Empty blame_author_opt");
+ let user_key = blame_author.uuid().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 blame_users: Vec<BitbucketUser> = blame_user.users().iter().cloned().collect();
+ let actual_blame_user = blame_users[0].to_owned();
+ let author_uuid = actual_blame_user.uuid();
+ if author_set.contains(author_uuid) {
+     continue;
+ }
+ author_set.insert(author_uuid.to_string());
+ add_reviewers(&blame_user, review, &access_token).await;

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a5d403c and e684411.
Files selected for processing (1)
  • vibi-dpu/src/core/coverage.rs (2} hunks)
Additional comments: 1
vibi-dpu/src/core/coverage.rs (1)
  • 3-3: The import statement has been updated to include new functions author_from_commit and BitbucketUser struct from user.rs and user::BitbucketUser respectively. This change is in line with the PR summary which mentions the introduction of a new function author_from_commit and the use of BitbucketUser struct.

Comment on lines 28 to 67
add_comment(&comment, review, &access_token).await;
}
if repo_config.auto_assign() {
// add reviewers
println!("Adding reviewers...");
let mut author_set: HashSet<String> = HashSet::new();
author_set.insert(prhunk.author().to_string());
for blame in prhunk.blamevec() {
if author_set.contains(blame.author()) {
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());
continue;
}
author_set.insert(blame.author().to_string());
let author_id = blame.author();
add_reviewers(blame.author(), review, &access_token).await;
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();
if author_set.contains(author_uuid) {
continue;
}
author_set.insert(author_uuid.to_string());
add_reviewers(&blame_user, 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.

The logic for adding reviewers has been significantly updated. Instead of directly using the author's ID from the blame, the new code fetches the author's information from the commit using the author_from_commit function. It then retrieves the workspace user from the database using the author's display name. If the workspace user is found, it checks if the user's UUID matches the blame author's UUID. If it doesn't, it uses the first user from the workspace user's users list. The UUID of the selected user is then added to the author_set and the user is added as a reviewer.

This change improves the accuracy of the reviewer assignment by ensuring that the correct user is added as a reviewer based on the blame information. However, it also introduces additional complexity and potential points of failure. For example, if the workspace user is not found in the database or if the user's users list is empty, the code will skip adding the user as a reviewer and print an error message. This could potentially lead to missing reviewers if the database is not up-to-date or if there are issues with the user data.

Consider adding a fallback mechanism to handle these cases, such as using the original author's ID if the workspace user is not found or if the users list is empty. This would ensure that a reviewer is always added, even if the optimal user cannot be determined.

+                    if blame_user_opt.is_none() {
+                        eprintln!("[process_coverage] no user found in db for blame author: {:?}", blame_author);
+                        // Fallback to using the original author's ID
+                        author_set.insert(blame_author.uuid().to_string());
+                        continue;
+                    }
Committable suggestion (Beta)
Suggested change
add_comment(&comment, review, &access_token).await;
}
if repo_config.auto_assign() {
// add reviewers
println!("Adding reviewers...");
let mut author_set: HashSet<String> = HashSet::new();
author_set.insert(prhunk.author().to_string());
for blame in prhunk.blamevec() {
if author_set.contains(blame.author()) {
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());
continue;
}
author_set.insert(blame.author().to_string());
let author_id = blame.author();
add_reviewers(blame.author(), review, &access_token).await;
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();
if author_set.contains(author_uuid) {
continue;
}
author_set.insert(author_uuid.to_string());
add_reviewers(&blame_user, review, &access_token).await;
if blame_user_opt.is_none() {
eprintln!("[process_coverage] no user found in db for blame author: {:?}", blame_author);
// Fallback to using the original author's ID
author_set.insert(blame_author.uuid().to_string());
continue;
}

Comment on lines 34 to 62
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());
continue;
}
author_set.insert(blame.author().to_string());
let author_id = blame.author();
add_reviewers(blame.author(), review, &access_token).await;
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();
Copy link
Member

Choose a reason for hiding this comment

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

This whole thing should have been a separate function.

vibi-dpu/src/core/coverage.rs Outdated Show resolved Hide resolved
vibi-dpu/src/core/coverage.rs Outdated Show resolved Hide resolved
vibi-dpu/src/utils/gitops.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e684411 and 6b9b692.
Files selected for processing (1)
  • vibi-dpu/src/utils/gitops.rs (6} hunks)
Files skipped from review due to trivial changes (1)
  • vibi-dpu/src/utils/gitops.rs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6b9b692 and 18448eb.
Files selected for processing (2)
  • vibi-dpu/src/bitbucket/reviewer.rs (1} hunks)
  • vibi-dpu/src/core/coverage.rs (2} hunks)
Files skipped from review due to trivial changes (1)
  • vibi-dpu/src/bitbucket/reviewer.rs
Additional comments: 1
vibi-dpu/src/core/coverage.rs (1)
  • 3-3: The import statement has been updated to include new modules and functions. The author_from_commit function from bitbucket::user and BitbucketUser and WorkspaceUser from utils::user are new additions. Ensure these new imports are used appropriately in the code.

vibi-dpu/src/core/coverage.rs Show resolved Hide resolved
bitbucket/reviewer: renamed multiple variables & functions to make more readable.
@sonarcloud
Copy link

sonarcloud bot commented Oct 26, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 18448eb and 9392585.
Files selected for processing (1)
  • vibi-dpu/src/bitbucket/reviewer.rs (6} hunks)
Additional comments: 5
vibi-dpu/src/bitbucket/reviewer.rs (5)
  • 9-20: The function add_reviewers has been refactored to take a BitbucketUser and Review directly instead of fetching them from the database using a key. This change improves the function's modularity and makes it easier to test, as it no longer depends on the state of the database. However, ensure that the BitbucketUser and Review passed to this function are always valid and up-to-date.

  • 22-34: The function get_updated_reviewers_vec has been refactored to take a BitbucketUser directly instead of fetching it from the database using a key. This change improves the function's modularity and makes it easier to test, as it no longer depends on the state of the database. However, ensure that the BitbucketUser passed to this function is always valid and up-to-date.

  • 54-80: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [61-88]

The function parse_reviewers_from_prinfo has been refactored to improve error handling. Instead of using expect to unwrap the result of pr_info_response.json::<Value>().await, which could panic if the result is an error, it now checks if the result is an error and returns None if it is. This change makes the function more robust and less likely to cause the program to crash.

  • 109-115: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [91-113]

The function put_reviewers has been slightly refactored. The change is minor and doesn't affect the function's behavior. The function still checks if the put_body_opt is None and returns early if it is, preventing an unnecessary PUT request. The function then sends a PUT request to update the reviewers of a pull request and prints the response for debugging purposes.

  • 131-137: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [134-144]

The function prepare_get_prinfo_url constructs the URL for retrieving pull request information. The function has not been changed in this pull request.

@avikalpg avikalpg merged commit 53f3ff2 into main Oct 26, 2023
3 checks passed
@avikalpg avikalpg deleted the tr/testAuthorFix branch October 26, 2023 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants