mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-05 21:30:40 +08:00
further cleaned up code based on feedback
This commit is contained in:
@ -156,33 +156,33 @@ class BitbucketServerProvider(GitProvider):
|
|||||||
if self.diff_files:
|
if self.diff_files:
|
||||||
return self.diff_files
|
return self.diff_files
|
||||||
|
|
||||||
|
head_sha = self.pr.fromRef['latestCommit']
|
||||||
|
|
||||||
|
# if Bitbucket api version is >= 8.16 then use the merge-base api for 2-way diff calculation
|
||||||
|
if self.bitbucket_api_version is not None and self.bitbucket_api_version >= LooseVersion("8.16"):
|
||||||
|
try:
|
||||||
|
base_sha = self.bitbucket_client.get(self._get_merge_base())['id']
|
||||||
|
except Exception as e:
|
||||||
|
get_logger().error(f"Failed to get the best common ancestor for PR: {self.pr_url}, \nerror: {e}")
|
||||||
|
raise e
|
||||||
|
else:
|
||||||
source_commits_list = list(self.bitbucket_client.get_pull_requests_commits(
|
source_commits_list = list(self.bitbucket_client.get_pull_requests_commits(
|
||||||
self.workspace_slug,
|
self.workspace_slug,
|
||||||
self.repo_slug,
|
self.repo_slug,
|
||||||
self.pr_num
|
self.pr_num
|
||||||
))
|
))
|
||||||
|
# if Bitbucket api version is None or < 7.0 then do a simple diff with a guaranteed common ancestor
|
||||||
# defaults to basic diff functionality with a guaranteed common ancestor
|
base_sha = source_commits_list[-1]['parents'][0]['id']
|
||||||
base_sha, head_sha = source_commits_list[-1]['parents'][0]['id'], source_commits_list[0]['id']
|
# if Bitbucket api version is 7.0-8.15 then use 2-way diff functionality for the base_sha
|
||||||
|
|
||||||
# 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"):
|
if self.bitbucket_api_version is not None and self.bitbucket_api_version >= LooseVersion("7.0"):
|
||||||
# Bitbucket endpoint for getting merge-base is available as of 8.16
|
|
||||||
if self.bitbucket_api_version >= LooseVersion("8.16"):
|
|
||||||
try:
|
|
||||||
base_sha = self.bitbucket_client.get(self._get_best_common_ancestor())['id']
|
|
||||||
except Exception as e:
|
|
||||||
get_logger().error(f"Failed to get the best common ancestor for PR: {self.pr_url}, \nerror: {e}")
|
|
||||||
raise e
|
|
||||||
# for versions 7.0-8.15 try to calculate the merge-base on our own
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
destination_commits = list(
|
destination_commits = list(
|
||||||
self.bitbucket_client.get_commits(self.workspace_slug, self.repo_slug, base_sha,
|
self.bitbucket_client.get_commits(self.workspace_slug, self.repo_slug, base_sha,
|
||||||
self.pr.toRef['latestCommit']))
|
self.pr.toRef['latestCommit']))
|
||||||
base_sha = self.get_best_common_ancestor(source_commits_list, destination_commits, base_sha)
|
base_sha = self.get_best_common_ancestor(source_commits_list, destination_commits, base_sha)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().error(f"Failed to get the commit list for calculating best common ancestor for PR: {self.pr_url}, \nerror: {e}")
|
get_logger().error(
|
||||||
|
f"Failed to get the commit list for calculating best common ancestor for PR: {self.pr_url}, \nerror: {e}")
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
diff_files = []
|
diff_files = []
|
||||||
@ -452,5 +452,5 @@ class BitbucketServerProvider(GitProvider):
|
|||||||
def _get_pr_comments_path(self):
|
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"
|
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):
|
def _get_merge_base(self):
|
||||||
return f"rest/api/latest/projects/{self.workspace_slug}/repos/{self.repo_slug}/pull-requests/{self.pr_num}/merge-base"
|
return f"rest/api/latest/projects/{self.workspace_slug}/repos/{self.repo_slug}/pull-requests/{self.pr_num}/merge-base"
|
||||||
|
Reference in New Issue
Block a user