mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-03 04:10:49 +08:00
Merge branch 'Codium-ai:main' into main
This commit is contained in:
@ -15,6 +15,12 @@ from ..log import get_logger
|
||||
from .git_provider import GitProvider
|
||||
|
||||
|
||||
def _gef_filename(diff):
|
||||
if diff.new.path:
|
||||
return diff.new.path
|
||||
return diff.old.path
|
||||
|
||||
|
||||
class BitbucketProvider(GitProvider):
|
||||
def __init__(
|
||||
self, pr_url: Optional[str] = None, incremental: Optional[bool] = False
|
||||
@ -40,6 +46,7 @@ class BitbucketProvider(GitProvider):
|
||||
self.temp_comments = []
|
||||
self.incremental = incremental
|
||||
self.diff_files = None
|
||||
self.git_files = None
|
||||
if pr_url:
|
||||
self.set_pr(pr_url)
|
||||
self.bitbucket_comment_api_url = self.pr._BitbucketBase__data["links"]["comments"]["href"]
|
||||
@ -123,7 +130,18 @@ class BitbucketProvider(GitProvider):
|
||||
self.pr = self._get_pr()
|
||||
|
||||
def get_files(self):
|
||||
return [diff.new.path for diff in self.pr.diffstat()]
|
||||
try:
|
||||
git_files = context.get("git_files", None)
|
||||
if git_files:
|
||||
return git_files
|
||||
self.git_files = [_gef_filename(diff) for diff in self.pr.diffstat()]
|
||||
context["git_files"] = self.git_files
|
||||
return self.git_files
|
||||
except Exception:
|
||||
if not self.git_files:
|
||||
self.git_files = [_gef_filename(diff) for diff in self.pr.diffstat()]
|
||||
return self.git_files
|
||||
|
||||
|
||||
def get_diff_files(self) -> list[FilePatchInfo]:
|
||||
if self.diff_files:
|
||||
@ -172,14 +190,18 @@ class BitbucketProvider(GitProvider):
|
||||
diff_split_lines[5].startswith("@@"))):
|
||||
diff_split[i] = "\n".join(diff_split_lines[4:])
|
||||
else:
|
||||
get_logger().error(f"Error - failed to remove the bitbucket header from diff {i}")
|
||||
break
|
||||
if diffs[i].data.get('lines_added', 0) == 0 and diffs[i].data.get('lines_removed', 0) == 0:
|
||||
diff_split[i] = ""
|
||||
else:
|
||||
get_logger().error(f"Error - failed to remove the bitbucket header from diff {i}")
|
||||
break
|
||||
|
||||
invalid_files_names = []
|
||||
diff_files = []
|
||||
for index, diff in enumerate(diffs):
|
||||
if not is_valid_file(diff.new.path):
|
||||
invalid_files_names.append(diff.new.path)
|
||||
file_path = _gef_filename(diff)
|
||||
if not is_valid_file(file_path):
|
||||
invalid_files_names.append(file_path)
|
||||
continue
|
||||
|
||||
try:
|
||||
@ -200,7 +222,7 @@ class BitbucketProvider(GitProvider):
|
||||
original_file_content_str,
|
||||
new_file_content_str,
|
||||
diff_split[index],
|
||||
diff.new.path,
|
||||
file_path,
|
||||
)
|
||||
|
||||
if diff.data['status'] == 'added':
|
||||
|
Reference in New Issue
Block a user