@@ -199,7 +199,24 @@ def get_diff_files(self) -> list[FilePatchInfo]:
199199 if avoid_load :
200200 original_file_content_str = ""
201201 else :
202- original_file_content_str = self ._get_pr_file_content (file , self .pr .base .sha )
202+ # The base.sha will point to the current state of the base branch (including parallel merges), not the original base commit when the PR was created
203+ # We can fix this by finding the merge base commit between the PR head and base branches
204+ # Note that The pr.head.sha is actually correct as is - it points to the latest commit in your PR branch.
205+ # This SHA isn't affected by parallel merges to the base branch since it's specific to your PR's branch.
206+ repo = self .repo_obj
207+ pr = self .pr
208+ try :
209+ compare = repo .compare (pr .base .sha , pr .head .sha )
210+ merge_base_commit = compare .merge_base_commit
211+ except Exception as e :
212+ get_logger ().error (f"Failed to get merge base commit: { e } " )
213+ merge_base_commit = pr .base
214+ if merge_base_commit .sha != pr .base .sha :
215+ get_logger ().info (
216+ f"Using merge base commit { merge_base_commit .sha } instead of base commit "
217+ f"{ pr .base .sha } for { file .filename } " )
218+ original_file_content_str = self ._get_pr_file_content (file , merge_base_commit .sha )
219+
203220 if not patch :
204221 patch = load_large_diff (file .filename , new_file_content_str , original_file_content_str )
205222
@@ -283,8 +300,7 @@ def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_
283300 relevant_line_in_file ,
284301 absolute_position )
285302 if position == - 1 :
286- if get_settings ().config .verbosity_level >= 2 :
287- get_logger ().info (f"Could not find position for { relevant_file } { relevant_line_in_file } " )
303+ get_logger ().info (f"Could not find position for { relevant_file } { relevant_line_in_file } " )
288304 subject_type = "FILE"
289305 else :
290306 subject_type = "LINE"
@@ -296,20 +312,17 @@ def publish_inline_comments(self, comments: list[dict], disable_fallback: bool =
296312 # publish all comments in a single message
297313 self .pr .create_review (commit = self .last_commit_id , comments = comments )
298314 except Exception as e :
299- if get_settings ().config .verbosity_level >= 2 :
300- get_logger ().error (f"Failed to publish inline comments" )
315+ get_logger ().info (f"Initially failed to publish inline comments as committable" )
301316
302- if (getattr (e , "status" , None ) == 422
303- and get_settings ().github .publish_inline_comments_fallback_with_verification and not disable_fallback ):
317+ if (getattr (e , "status" , None ) == 422 and not disable_fallback ):
304318 pass # continue to try _publish_inline_comments_fallback_with_verification
305319 else :
306320 raise e # will end up with publishing the comments one by one
307321
308322 try :
309323 self ._publish_inline_comments_fallback_with_verification (comments )
310324 except Exception as e :
311- if get_settings ().config .verbosity_level >= 2 :
312- get_logger ().error (f"Failed to publish inline code comments fallback, error: { e } " )
325+ get_logger ().error (f"Failed to publish inline code comments fallback, error: { e } " )
313326 raise e
314327
315328 def _publish_inline_comments_fallback_with_verification (self , comments : list [dict ]):
@@ -334,11 +347,9 @@ def _publish_inline_comments_fallback_with_verification(self, comments: list[dic
334347 for comment in fixed_comments_as_one_liner :
335348 try :
336349 self .publish_inline_comments ([comment ], disable_fallback = True )
337- if get_settings ().config .verbosity_level >= 2 :
338- get_logger ().info (f"Published invalid comment as a single line comment: { comment } " )
350+ get_logger ().info (f"Published invalid comment as a single line comment: { comment } " )
339351 except :
340- if get_settings ().config .verbosity_level >= 2 :
341- get_logger ().error (f"Failed to publish invalid comment as a single line comment: { comment } " )
352+ get_logger ().error (f"Failed to publish invalid comment as a single line comment: { comment } " )
342353
343354 def _verify_code_comment (self , comment : dict ):
344355 is_verified = False
@@ -396,8 +407,7 @@ def _try_fix_invalid_inline_comments(self, invalid_comments: list[dict]) -> list
396407 if fixed_comment != comment :
397408 fixed_comments .append (fixed_comment )
398409 except Exception as e :
399- if get_settings ().config .verbosity_level >= 2 :
400- get_logger ().error (f"Failed to fix inline comment, error: { e } " )
410+ get_logger ().error (f"Failed to fix inline comment, error: { e } " )
401411 return fixed_comments
402412
403413 def publish_code_suggestions (self , code_suggestions : list ) -> bool :
@@ -412,16 +422,14 @@ def publish_code_suggestions(self, code_suggestions: list) -> bool:
412422 relevant_lines_end = suggestion ['relevant_lines_end' ]
413423
414424 if not relevant_lines_start or relevant_lines_start == - 1 :
415- if get_settings ().config .verbosity_level >= 2 :
416- get_logger ().exception (
417- f"Failed to publish code suggestion, relevant_lines_start is { relevant_lines_start } " )
425+ get_logger ().exception (
426+ f"Failed to publish code suggestion, relevant_lines_start is { relevant_lines_start } " )
418427 continue
419428
420429 if relevant_lines_end < relevant_lines_start :
421- if get_settings ().config .verbosity_level >= 2 :
422- get_logger ().exception (f"Failed to publish code suggestion, "
423- f"relevant_lines_end is { relevant_lines_end } and "
424- f"relevant_lines_start is { relevant_lines_start } " )
430+ get_logger ().exception (f"Failed to publish code suggestion, "
431+ f"relevant_lines_end is { relevant_lines_end } and "
432+ f"relevant_lines_start is { relevant_lines_start } " )
425433 continue
426434
427435 if relevant_lines_end > relevant_lines_start :
@@ -445,8 +453,7 @@ def publish_code_suggestions(self, code_suggestions: list) -> bool:
445453 self .publish_inline_comments (post_parameters_list )
446454 return True
447455 except Exception as e :
448- if get_settings ().config .verbosity_level >= 2 :
449- get_logger ().error (f"Failed to publish code suggestion, error: { e } " )
456+ get_logger ().error (f"Failed to publish code suggestion, error: { e } " )
450457 return False
451458
452459 def edit_comment (self , comment , body : str ):
@@ -505,6 +512,7 @@ def publish_file_comments(self, file_comments: list) -> bool:
505512 elif self .deployment_type == 'user' :
506513 same_comment_creator = self .github_user_id == existing_comment ['user' ]['login' ]
507514 if existing_comment ['subject_type' ] == 'file' and comment ['path' ] == existing_comment ['path' ] and same_comment_creator :
515+
508516 headers , data_patch = self .pr ._requester .requestJsonAndCheck (
509517 "PATCH" , f"{ self .base_url } /repos/{ self .repo } /pulls/comments/{ existing_comment ['id' ]} " , input = {"body" :comment ['body' ]}
510518 )
@@ -516,8 +524,7 @@ def publish_file_comments(self, file_comments: list) -> bool:
516524 )
517525 return True
518526 except Exception as e :
519- if get_settings ().config .verbosity_level >= 2 :
520- get_logger ().error (f"Failed to publish diffview file summary, error: { e } " )
527+ get_logger ().error (f"Failed to publish diffview file summary, error: { e } " )
521528 return False
522529
523530 def remove_initial_comment (self ):
@@ -805,8 +812,7 @@ def generate_link_to_relevant_line_number(self, suggestion) -> str:
805812 link = f"{ self .base_url_html } /{ self .repo } /pull/{ self .pr_num } /files#diff-{ sha_file } R{ absolute_position } "
806813 return link
807814 except Exception as e :
808- if get_settings ().config .verbosity_level >= 2 :
809- get_logger ().info (f"Failed adding line link, error: { e } " )
815+ get_logger ().info (f"Failed adding line link, error: { e } " )
810816
811817 return ""
812818
0 commit comments