fix improve, update_changelog and review inline comment

This commit is contained in:
sarbjitgrewal
2023-08-24 11:52:20 +05:30
parent b1a2e3e323
commit 67ff50583a
4 changed files with 27 additions and 7 deletions

View File

@ -6,7 +6,7 @@ from urllib.parse import urlparse
import requests
from atlassian.bitbucket import Cloud
from ..algo.pr_processing import clip_tokens
from ..algo.pr_processing import clip_tokens, find_line_number_of_relevant_line_in_file
from ..config_loader import get_settings
from .git_provider import FilePatchInfo
@ -87,7 +87,7 @@ class BitbucketProvider:
return False
def is_supported(self, capability: str) -> bool:
if capability in ['get_issue_comments', 'create_inline_comment', 'publish_inline_comments', 'get_labels']:
if capability in ['get_issue_comments', 'publish_inline_comments', 'get_labels']:
return False
return True
@ -122,7 +122,20 @@ class BitbucketProvider:
except Exception as e:
logging.exception(f"Failed to remove temp comments, error: {e}")
def publish_inline_comment(self, comment: str, from_line: int, to_line: int, file: str):
# funtion to create_inline_comment
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
position, absolute_position = find_line_number_of_relevant_line_in_file(self.get_diff_files(), relevant_file.strip('`'), relevant_line_in_file)
if position == -1:
if get_settings().config.verbosity_level >= 2:
logging.info(f"Could not find position for {relevant_file} {relevant_line_in_file}")
subject_type = "FILE"
else:
subject_type = "LINE"
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):
payload = json.dumps( {
"content": {
"raw": comment,
@ -144,7 +157,11 @@ class BitbucketProvider:
def publish_inline_comments(self, comments: list[dict]):
for comment in comments:
self.publish_inline_comment(comment['body'], comment['start_line'], comment['line'], comment['path'])
self.publish_inline_comment(comment['body'], comment['start_line'], comment['path'])
def publish_bitbucket_inline_comments(self, comments: list[dict]):
for comment in comments:
self.publish_inline_comment(comment['body'],comment['position'], comment['path'])
def get_title(self):
return self.pr.title

View File

@ -71,7 +71,7 @@ class PRDescription:
if get_settings().config.publish_output:
logging.info('Pushing answer...')
if get_settings().pr_description.publish_description_as_comment:
self.git_provider.publish_comment(markdown_text)
self.git_provider.publish_comment(pr_body)
else:
self.git_provider.publish_description(pr_title, pr_body)
if self.git_provider.is_supported("get_labels"):

View File

@ -266,7 +266,10 @@ class PRReviewer:
self.git_provider.publish_inline_comment(content, relevant_file, relevant_line_in_file)
if comments:
self.git_provider.publish_inline_comments(comments)
if get_settings().config.git_provider == 'bitbucket':
self.git_provider.publish_bitbucket_inline_comments(comments)
else:
self.git_provider.publish_inline_comments(comments)
def _get_user_answers(self) -> Tuple[str, str]:
"""

View File

@ -46,7 +46,7 @@ class PRUpdateChangelog:
get_settings().pr_update_changelog_prompt.user)
async def run(self):
assert type(self.git_provider) == GithubProvider, "Currently only Github is supported"
# assert type(self.git_provider) == GithubProvider, "Currently only Github is supported"
logging.info('Updating the changelog...')
if get_settings().config.publish_output: