Skip to content

Commit

Permalink
Merge pull request #1151 from Codium-ai/publish_inline
Browse files Browse the repository at this point in the history
Add 'original_suggestion' parameter to publish_inline_comment methods…
  • Loading branch information
mrT23 authored Aug 16, 2024
2 parents 402a388 + 4a71ec9 commit 8108118
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pr_agent/git_providers/azuredevops_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def remove_initial_comment(self):
except Exception as 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)])


Expand Down
2 changes: 1 addition & 1 deletion pr_agent/git_providers/bitbucket_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_
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)
payload = json.dumps( {
"content": {
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/git_providers/bitbucket_server_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_
path = relevant_file.strip()
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 = {
"text": comment,
"severity": "NORMAL",
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/git_providers/codecommit_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def remove_initial_comment(self):
def remove_comment(self, comment):
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
raise NotImplementedError("CodeCommit provider does not support publishing inline comments yet")

Expand Down
2 changes: 1 addition & 1 deletion pr_agent/git_providers/gerrit_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def publish_inline_comments(self, comments: list[dict]):
'provider')

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(
'Publishing inline comments is not implemented for the gerrit '
'provider')
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/git_providers/git_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def publish_persistent_comment_full(self, pr_comment: str,


@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

def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str,
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/git_providers/github_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def publish_comment(self, pr_comment: str, is_temporary: bool = False):
self.pr.comments_list.append(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)
self.publish_inline_comments([self.create_inline_comment(body, relevant_file, relevant_line_in_file)])

Expand Down
12 changes: 8 additions & 4 deletions pr_agent/git_providers/gitlab_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ def reply_to_comment_from_comment_id(self, comment_id: int, body: str):
discussion = self.mr.discussions.get(comment_id)
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)
edit_type, found, source_line_no, target_file, target_line_no = self.search_line(relevant_file,
relevant_line_in_file)
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):
raise NotImplementedError("Gitlab provider does not support creating inline comments yet")
Expand All @@ -230,7 +230,8 @@ def get_comment_body_from_comment_id(self, comment_id: int):

def send_inline_comment(self, body: str, edit_type: str, found: bool, relevant_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:
get_logger().info(f"Could not find position for {relevant_file} {relevant_line_in_file}")
else:
Expand Down Expand Up @@ -326,7 +327,10 @@ def get_relevant_diff(self, relevant_file: str, relevant_line_in_file: str) -> O
def publish_code_suggestions(self, code_suggestions: list) -> bool:
for suggestion in code_suggestions:
try:
original_suggestion = suggestion['original_suggestion']
if suggestion and 'original_suggestion' in suggestion:
original_suggestion = suggestion['original_suggestion']
else:
original_suggestion = suggestion
body = suggestion['body']
relevant_file = suggestion['relevant_file']
relevant_lines_start = suggestion['relevant_lines_start']
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/git_providers/local_git_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def publish_comment(self, pr_comment: str, is_temporary: bool = False):
# Write the string to the file
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')

def publish_inline_comments(self, comments: list[dict]):
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/settings/configuration.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[config]
# models
model="gpt-4-turbo-2024-04-09"
model_turbo="gpt-4o"
model_turbo="gpt-4o-2024-08-06"
fallback_models=["gpt-4-0125-preview"]
# CLI
git_provider="github"
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/tools/pr_reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def _publish_inline_code_comments(self) -> None:
if comment:
comments.append(comment)
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:
self.git_provider.publish_inline_comments(comments)
Expand Down

0 comments on commit 8108118

Please sign in to comment.