mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-05 13:20:39 +08:00
Refactor byte decoding in Bitbucket server provider using decode_if_bytes
function
This commit is contained in:
@ -5,6 +5,7 @@ from urllib.parse import quote_plus, urlparse
|
|||||||
from atlassian.bitbucket import Bitbucket
|
from atlassian.bitbucket import Bitbucket
|
||||||
from requests.exceptions import HTTPError
|
from requests.exceptions import HTTPError
|
||||||
|
|
||||||
|
from ..algo.git_patch_processing import decode_if_bytes
|
||||||
from ..algo.language_handler import is_valid_file
|
from ..algo.language_handler import is_valid_file
|
||||||
from ..algo.types import EDIT_TYPE, FilePatchInfo
|
from ..algo.types import EDIT_TYPE, FilePatchInfo
|
||||||
from ..algo.utils import (find_line_number_of_relevant_line_in_file,
|
from ..algo.utils import (find_line_number_of_relevant_line_in_file,
|
||||||
@ -201,25 +202,21 @@ class BitbucketServerProvider(GitProvider):
|
|||||||
case 'ADD':
|
case 'ADD':
|
||||||
edit_type = EDIT_TYPE.ADDED
|
edit_type = EDIT_TYPE.ADDED
|
||||||
new_file_content_str = self.get_file(file_path, head_sha)
|
new_file_content_str = self.get_file(file_path, head_sha)
|
||||||
if isinstance(new_file_content_str, (bytes, bytearray)):
|
new_file_content_str = decode_if_bytes(new_file_content_str)
|
||||||
new_file_content_str = new_file_content_str.decode("utf-8")
|
|
||||||
original_file_content_str = ""
|
original_file_content_str = ""
|
||||||
case 'DELETE':
|
case 'DELETE':
|
||||||
edit_type = EDIT_TYPE.DELETED
|
edit_type = EDIT_TYPE.DELETED
|
||||||
new_file_content_str = ""
|
new_file_content_str = ""
|
||||||
original_file_content_str = self.get_file(file_path, base_sha)
|
original_file_content_str = self.get_file(file_path, base_sha)
|
||||||
if isinstance(original_file_content_str, (bytes, bytearray)):
|
original_file_content_str = decode_if_bytes(original_file_content_str)
|
||||||
original_file_content_str = original_file_content_str.decode("utf-8")
|
|
||||||
case 'RENAME':
|
case 'RENAME':
|
||||||
edit_type = EDIT_TYPE.RENAMED
|
edit_type = EDIT_TYPE.RENAMED
|
||||||
case _:
|
case _:
|
||||||
edit_type = EDIT_TYPE.MODIFIED
|
edit_type = EDIT_TYPE.MODIFIED
|
||||||
original_file_content_str = self.get_file(file_path, base_sha)
|
original_file_content_str = self.get_file(file_path, base_sha)
|
||||||
if isinstance(original_file_content_str, (bytes, bytearray)):
|
original_file_content_str = decode_if_bytes(original_file_content_str)
|
||||||
original_file_content_str = original_file_content_str.decode("utf-8")
|
|
||||||
new_file_content_str = self.get_file(file_path, head_sha)
|
new_file_content_str = self.get_file(file_path, head_sha)
|
||||||
if isinstance(new_file_content_str, (bytes, bytearray)):
|
new_file_content_str = decode_if_bytes(new_file_content_str)
|
||||||
new_file_content_str = new_file_content_str.decode("utf-8")
|
|
||||||
|
|
||||||
patch = load_large_diff(file_path, new_file_content_str, original_file_content_str)
|
patch = load_large_diff(file_path, new_file_content_str, original_file_content_str)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user