|
5 | 5 | from atlassian.bitbucket import Bitbucket |
6 | 6 | from requests.exceptions import HTTPError |
7 | 7 |
|
| 8 | +from ..algo.git_patch_processing import decode_if_bytes |
8 | 9 | from ..algo.language_handler import is_valid_file |
9 | 10 | from ..algo.types import EDIT_TYPE, FilePatchInfo |
10 | 11 | from ..algo.utils import (find_line_number_of_relevant_line_in_file, |
@@ -201,25 +202,21 @@ def get_diff_files(self) -> list[FilePatchInfo]: |
201 | 202 | case 'ADD': |
202 | 203 | edit_type = EDIT_TYPE.ADDED |
203 | 204 | new_file_content_str = self.get_file(file_path, head_sha) |
204 | | - if isinstance(new_file_content_str, (bytes, bytearray)): |
205 | | - new_file_content_str = new_file_content_str.decode("utf-8") |
| 205 | + new_file_content_str = decode_if_bytes(new_file_content_str) |
206 | 206 | original_file_content_str = "" |
207 | 207 | case 'DELETE': |
208 | 208 | edit_type = EDIT_TYPE.DELETED |
209 | 209 | new_file_content_str = "" |
210 | 210 | original_file_content_str = self.get_file(file_path, base_sha) |
211 | | - if isinstance(original_file_content_str, (bytes, bytearray)): |
212 | | - original_file_content_str = original_file_content_str.decode("utf-8") |
| 211 | + original_file_content_str = decode_if_bytes(original_file_content_str) |
213 | 212 | case 'RENAME': |
214 | 213 | edit_type = EDIT_TYPE.RENAMED |
215 | 214 | case _: |
216 | 215 | edit_type = EDIT_TYPE.MODIFIED |
217 | 216 | original_file_content_str = self.get_file(file_path, base_sha) |
218 | | - if isinstance(original_file_content_str, (bytes, bytearray)): |
219 | | - original_file_content_str = original_file_content_str.decode("utf-8") |
| 217 | + original_file_content_str = decode_if_bytes(original_file_content_str) |
220 | 218 | new_file_content_str = self.get_file(file_path, head_sha) |
221 | | - if isinstance(new_file_content_str, (bytes, bytearray)): |
222 | | - new_file_content_str = new_file_content_str.decode("utf-8") |
| 219 | + new_file_content_str = decode_if_bytes(new_file_content_str) |
223 | 220 |
|
224 | 221 | patch = load_large_diff(file_path, new_file_content_str, original_file_content_str) |
225 | 222 |
|
@@ -330,10 +327,10 @@ def publish_inline_comments(self, comments: list[dict]): |
330 | 327 | for comment in comments: |
331 | 328 | if 'position' in comment: |
332 | 329 | self.publish_inline_comment(comment['body'], comment['position'], comment['path']) |
333 | | - elif 'start_line' in comment: # multi-line comment |
| 330 | + elif 'start_line' in comment: # multi-line comment |
334 | 331 | # note that bitbucket does not seem to support range - only a comment on a single line - https://community.developer.atlassian.com/t/api-post-endpoint-for-inline-pull-request-comments/60452 |
335 | 332 | self.publish_inline_comment(comment['body'], comment['start_line'], comment['path']) |
336 | | - elif 'line' in comment: # single-line comment |
| 333 | + elif 'line' in comment: # single-line comment |
337 | 334 | self.publish_inline_comment(comment['body'], comment['line'], comment['path']) |
338 | 335 | else: |
339 | 336 | get_logger().error(f"Could not publish inline comment: {comment}") |
|
0 commit comments