-
Notifications
You must be signed in to change notification settings - Fork 572
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
Bugfix/bb 2 way diff fix #1172
Bugfix/bb 2 way diff fix #1172
Conversation
PR Reviewer Guide 🔍
|
PR Code Suggestions ✨Latest suggestions up to cf14e45
Previous suggestions✅ Suggestions up to commit 2a9e3ee
|
@MaxHoecker In other words, is it backward (and forward) compatible ? |
@mrT23 |
@MaxHoecker I dont know. @MarkRx are you interested in reviewing this PR ? |
9176c0d
to
ec5c00d
Compare
Added a config to allow the legacy 3-way diff. Although I think it's unlikely anyone using this and bitbucket server is using Bitbucket Server 6.0 or older, so I defaulted to the new diff calculation method. |
ec5c00d
to
0442cdc
Compare
Looks like there is an API endpoint you can call to get the base line commit for a 2-way diff. It may be better to use that to match what BB is doing. If the API client doesn't expose the endpoint you can call it manually like I did here. As for supporting a 3-way diff unfortunately BB forces the 2-way diff from version 7+. Given that Enterprises should be keeping up to date in theory support for 6 with a 3-way diff is not necessary. |
Unfortunately that endpoint is not available in my Bitbucket API version. I'll add a check for the api version and use a different strategy depending on api version though |
…egy depending on API version, and expanded unit test cases
7539917
to
29c5075
Compare
Changes pushed, @MarkRx please review when you get the chance 😄 |
@@ -407,3 +451,6 @@ def get_pr_labels(self, update=False): | |||
|
|||
def _get_pr_comments_path(self): | |||
return f"rest/api/latest/projects/{self.workspace_slug}/repos/{self.repo_slug}/pull-requests/{self.pr_num}/comments" | |||
|
|||
def _get_best_common_ancestor(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method name is confusing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
completely agree, will fix
base_sha, head_sha = source_commits_list[-1]['parents'][0]['id'], source_commits_list[0]['id'] | ||
|
||
# if Bitbucket api version is greater than or equal to 7.0 then use 2-way diff functionality for the base_sha | ||
if self.bitbucket_api_version is not None and self.bitbucket_api_version >= LooseVersion("7.0"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it may be more clear to split this into 3 cases:
<7
<8.16
8.16+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I don't think this block can be cleanly split into 3 cases like that based on the shared logic between certain cases. I do think I can cut out a call to get the source_commits_list for the >8.16 condition though so I'll at least add that
ok, thanks for the contribution |
@CodiumAI-Agent /improve |
User description
Fixes #1131
Gets the 2-way file diff between the merging branch head and the best common ancestor
PR Type
Bug fix, Enhancement
Description
BitbucketServerProvider
class to find the best common ancestor (merge base) between branchesget_diff_files
method to use the correct base commit for diff calculationbitbucket_client
in the constructorChanges walkthrough 📝
bitbucket_server_provider.py
Improve BitbucketServerProvider diff calculation
pr_agent/git_providers/bitbucket_server_provider.py
bitbucket_client
parameter to the constructorget_best_common_ancestor
method to find the merge baseget_diff_files
to use the best common ancestor for diffcalculation
test_bitbucket_provider.py
Add comprehensive tests for BitbucketServerProvider
tests/unittest/test_bitbucket_provider.py
TestBitbucketServerProvider
get_diff_files
method