Merge pull request #119 from zmeir/zmeir-code_suggestions_single_api_call

Optimize Code Suggestions API Calls
This commit is contained in:
Ori Kotek
2023-07-23 17:30:37 +03:00
committed by GitHub

View File

@ -152,10 +152,8 @@ class GithubProvider(GitProvider):
def publish_code_suggestions(self, code_suggestions: list): def publish_code_suggestions(self, code_suggestions: list):
""" """
Publishes code suggestions as comments on the PR. Publishes code suggestions as comments on the PR.
In practice current APU enables to send only one code suggestion per comment. Might change in the future.
""" """
post_parameters_list = [] post_parameters_list = []
import github.PullRequestComment
for suggestion in code_suggestions: for suggestion in code_suggestions:
body = suggestion['body'] body = suggestion['body']
relevant_file = suggestion['relevant_file'] relevant_file = suggestion['relevant_file']
@ -178,7 +176,6 @@ class GithubProvider(GitProvider):
if relevant_lines_end > relevant_lines_start: if relevant_lines_end > relevant_lines_start:
post_parameters = { post_parameters = {
"body": body, "body": body,
"commit_id": self.last_commit_id._identity,
"path": relevant_file, "path": relevant_file,
"line": relevant_lines_end, "line": relevant_lines_end,
"start_line": relevant_lines_start, "start_line": relevant_lines_start,
@ -187,19 +184,14 @@ class GithubProvider(GitProvider):
else: # API is different for single line comments else: # API is different for single line comments
post_parameters = { post_parameters = {
"body": body, "body": body,
"commit_id": self.last_commit_id._identity,
"path": relevant_file, "path": relevant_file,
"line": relevant_lines_start, "line": relevant_lines_start,
"side": "RIGHT", "side": "RIGHT",
} }
post_parameters_list.append(post_parameters)
try: try:
headers, data = self.pr._requester.requestJsonAndCheck( self.pr.create_review(commit=self.last_commit_id, comments=post_parameters_list)
"POST", f"{self.pr.url}/comments", input=post_parameters
)
github.PullRequestComment.PullRequestComment(
self.pr._requester, headers, data, completed=True
)
return True return True
except Exception as e: except Exception as e:
if settings.config.verbosity_level >= 2: if settings.config.verbosity_level >= 2: