mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 04:40:38 +08:00
Add 'original_suggestion' parameter to publish_inline_comment methods across git providers for enhanced inline comment handling
This commit is contained in:
@ -444,7 +444,7 @@ class AzureDevopsProvider(GitProvider):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().exception(f"Failed to remove temp comments, error: {e}")
|
get_logger().exception(f"Failed to remove temp comments, error: {e}")
|
||||||
|
|
||||||
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
|
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str, original_suggestion=None):
|
||||||
self.publish_inline_comments([self.create_inline_comment(body, relevant_file, relevant_line_in_file)])
|
self.publish_inline_comments([self.create_inline_comment(body, relevant_file, relevant_line_in_file)])
|
||||||
|
|
||||||
|
|
||||||
|
@ -331,7 +331,7 @@ class BitbucketProvider(GitProvider):
|
|||||||
return dict(body=body, path=path, position=absolute_position) if subject_type == "LINE" else {}
|
return dict(body=body, path=path, position=absolute_position) if subject_type == "LINE" else {}
|
||||||
|
|
||||||
|
|
||||||
def publish_inline_comment(self, comment: str, from_line: int, file: str):
|
def publish_inline_comment(self, comment: str, from_line: int, file: str, original_suggestion=None):
|
||||||
comment = self.limit_output_characters(comment, self.max_comment_length)
|
comment = self.limit_output_characters(comment, self.max_comment_length)
|
||||||
payload = json.dumps( {
|
payload = json.dumps( {
|
||||||
"content": {
|
"content": {
|
||||||
|
@ -224,7 +224,7 @@ class BitbucketServerProvider(GitProvider):
|
|||||||
path = relevant_file.strip()
|
path = relevant_file.strip()
|
||||||
return dict(body=body, path=path, position=absolute_position) if subject_type == "LINE" else {}
|
return dict(body=body, path=path, position=absolute_position) if subject_type == "LINE" else {}
|
||||||
|
|
||||||
def publish_inline_comment(self, comment: str, from_line: int, file: str):
|
def publish_inline_comment(self, comment: str, from_line: int, file: str, original_suggestion=None):
|
||||||
payload = {
|
payload = {
|
||||||
"text": comment,
|
"text": comment,
|
||||||
"severity": "NORMAL",
|
"severity": "NORMAL",
|
||||||
|
@ -225,7 +225,7 @@ class CodeCommitProvider(GitProvider):
|
|||||||
def remove_comment(self, comment):
|
def remove_comment(self, comment):
|
||||||
return "" # not implemented yet
|
return "" # not implemented yet
|
||||||
|
|
||||||
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
|
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str, original_suggestion=None):
|
||||||
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/post_comment_for_compared_commit.html
|
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/post_comment_for_compared_commit.html
|
||||||
raise NotImplementedError("CodeCommit provider does not support publishing inline comments yet")
|
raise NotImplementedError("CodeCommit provider does not support publishing inline comments yet")
|
||||||
|
|
||||||
|
@ -376,7 +376,7 @@ class GerritProvider(GitProvider):
|
|||||||
'provider')
|
'provider')
|
||||||
|
|
||||||
def publish_inline_comment(self, body: str, relevant_file: str,
|
def publish_inline_comment(self, body: str, relevant_file: str,
|
||||||
relevant_line_in_file: str):
|
relevant_line_in_file: str, original_suggestion=None):
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
'Publishing inline comments is not implemented for the gerrit '
|
'Publishing inline comments is not implemented for the gerrit '
|
||||||
'provider')
|
'provider')
|
||||||
|
@ -182,7 +182,7 @@ class GitProvider(ABC):
|
|||||||
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
|
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str, original_suggestion=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str,
|
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str,
|
||||||
|
@ -267,7 +267,7 @@ class GithubProvider(GitProvider):
|
|||||||
self.pr.comments_list.append(response)
|
self.pr.comments_list.append(response)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
|
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str, original_suggestion=None):
|
||||||
body = self.limit_output_characters(body, self.max_comment_chars)
|
body = self.limit_output_characters(body, self.max_comment_chars)
|
||||||
self.publish_inline_comments([self.create_inline_comment(body, relevant_file, relevant_line_in_file)])
|
self.publish_inline_comments([self.create_inline_comment(body, relevant_file, relevant_line_in_file)])
|
||||||
|
|
||||||
|
@ -211,12 +211,12 @@ class GitLabProvider(GitProvider):
|
|||||||
discussion = self.mr.discussions.get(comment_id)
|
discussion = self.mr.discussions.get(comment_id)
|
||||||
discussion.notes.create({'body': body})
|
discussion.notes.create({'body': body})
|
||||||
|
|
||||||
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
|
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str, original_suggestion=None):
|
||||||
body = self.limit_output_characters(body, self.max_comment_chars)
|
body = self.limit_output_characters(body, self.max_comment_chars)
|
||||||
edit_type, found, source_line_no, target_file, target_line_no = self.search_line(relevant_file,
|
edit_type, found, source_line_no, target_file, target_line_no = self.search_line(relevant_file,
|
||||||
relevant_line_in_file)
|
relevant_line_in_file)
|
||||||
self.send_inline_comment(body, edit_type, found, relevant_file, relevant_line_in_file, source_line_no,
|
self.send_inline_comment(body, edit_type, found, relevant_file, relevant_line_in_file, source_line_no,
|
||||||
target_file, target_line_no)
|
target_file, target_line_no, original_suggestion)
|
||||||
|
|
||||||
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str, absolute_position: int = None):
|
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str, absolute_position: int = None):
|
||||||
raise NotImplementedError("Gitlab provider does not support creating inline comments yet")
|
raise NotImplementedError("Gitlab provider does not support creating inline comments yet")
|
||||||
@ -230,7 +230,8 @@ class GitLabProvider(GitProvider):
|
|||||||
|
|
||||||
def send_inline_comment(self, body: str, edit_type: str, found: bool, relevant_file: str,
|
def send_inline_comment(self, body: str, edit_type: str, found: bool, relevant_file: str,
|
||||||
relevant_line_in_file: str,
|
relevant_line_in_file: str,
|
||||||
source_line_no: int, target_file: str, target_line_no: int, original_suggestion) -> None:
|
source_line_no: int, target_file: str, target_line_no: int,
|
||||||
|
original_suggestion=None) -> None:
|
||||||
if not found:
|
if not found:
|
||||||
get_logger().info(f"Could not find position for {relevant_file} {relevant_line_in_file}")
|
get_logger().info(f"Could not find position for {relevant_file} {relevant_line_in_file}")
|
||||||
else:
|
else:
|
||||||
@ -326,7 +327,10 @@ class GitLabProvider(GitProvider):
|
|||||||
def publish_code_suggestions(self, code_suggestions: list) -> bool:
|
def publish_code_suggestions(self, code_suggestions: list) -> bool:
|
||||||
for suggestion in code_suggestions:
|
for suggestion in code_suggestions:
|
||||||
try:
|
try:
|
||||||
|
if 'original_suggestion' in suggestion:
|
||||||
original_suggestion = suggestion['original_suggestion']
|
original_suggestion = suggestion['original_suggestion']
|
||||||
|
else:
|
||||||
|
original_suggestion = suggestion
|
||||||
body = suggestion['body']
|
body = suggestion['body']
|
||||||
relevant_file = suggestion['relevant_file']
|
relevant_file = suggestion['relevant_file']
|
||||||
relevant_lines_start = suggestion['relevant_lines_start']
|
relevant_lines_start = suggestion['relevant_lines_start']
|
||||||
|
@ -119,7 +119,7 @@ class LocalGitProvider(GitProvider):
|
|||||||
# Write the string to the file
|
# Write the string to the file
|
||||||
file.write(pr_comment)
|
file.write(pr_comment)
|
||||||
|
|
||||||
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
|
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str, original_suggestion=None):
|
||||||
raise NotImplementedError('Publishing inline comments is not implemented for the local git provider')
|
raise NotImplementedError('Publishing inline comments is not implemented for the local git provider')
|
||||||
|
|
||||||
def publish_inline_comments(self, comments: list[dict]):
|
def publish_inline_comments(self, comments: list[dict]):
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[config]
|
[config]
|
||||||
# models
|
# models
|
||||||
model="gpt-4-turbo-2024-04-09"
|
model="gpt-4-turbo-2024-04-09"
|
||||||
model_turbo="gpt-4o"
|
model_turbo="gpt-4o-2024-08-06"
|
||||||
fallback_models=["gpt-4-0125-preview"]
|
fallback_models=["gpt-4-0125-preview"]
|
||||||
# CLI
|
# CLI
|
||||||
git_provider="github"
|
git_provider="github"
|
||||||
|
@ -287,7 +287,7 @@ class PRReviewer:
|
|||||||
if comment:
|
if comment:
|
||||||
comments.append(comment)
|
comments.append(comment)
|
||||||
else:
|
else:
|
||||||
self.git_provider.publish_inline_comment(content, relevant_file, relevant_line_in_file)
|
self.git_provider.publish_inline_comment(content, relevant_file, relevant_line_in_file, suggestion)
|
||||||
|
|
||||||
if comments:
|
if comments:
|
||||||
self.git_provider.publish_inline_comments(comments)
|
self.git_provider.publish_inline_comments(comments)
|
||||||
|
Reference in New Issue
Block a user