Merge pull request #1151 from Codium-ai/publish_inline

Add 'original_suggestion' parameter to publish_inline_comment methods…
This commit is contained in:
Tal
2024-08-16 09:08:05 +03:00
committed by GitHub
11 changed files with 18 additions and 14 deletions

View File

@ -444,7 +444,7 @@ class AzureDevopsProvider(GitProvider):
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)])

View File

@ -331,7 +331,7 @@ class BitbucketProvider(GitProvider):
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": {

View File

@ -224,7 +224,7 @@ class BitbucketServerProvider(GitProvider):
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",

View File

@ -225,7 +225,7 @@ class CodeCommitProvider(GitProvider):
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")

View File

@ -376,7 +376,7 @@ class GerritProvider(GitProvider):
'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')

View File

@ -182,7 +182,7 @@ class GitProvider(ABC):
@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,

View File

@ -267,7 +267,7 @@ class GithubProvider(GitProvider):
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)])

View File

@ -211,12 +211,12 @@ class GitLabProvider(GitProvider):
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")
@ -230,7 +230,8 @@ class GitLabProvider(GitProvider):
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:
@ -326,7 +327,10 @@ class GitLabProvider(GitProvider):
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']

View File

@ -119,7 +119,7 @@ class LocalGitProvider(GitProvider):
# 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]):

View File

@ -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"

View File

@ -287,7 +287,7 @@ class PRReviewer:
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)