mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-05 05:10:38 +08:00
fix improve, update_changelog and review inline comment
This commit is contained in:
@ -6,7 +6,7 @@ from urllib.parse import urlparse
|
|||||||
import requests
|
import requests
|
||||||
from atlassian.bitbucket import Cloud
|
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 ..config_loader import get_settings
|
||||||
from .git_provider import FilePatchInfo
|
from .git_provider import FilePatchInfo
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ class BitbucketProvider:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def is_supported(self, capability: str) -> bool:
|
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 False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -122,7 +122,20 @@ class BitbucketProvider:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(f"Failed to remove temp comments, error: {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( {
|
payload = json.dumps( {
|
||||||
"content": {
|
"content": {
|
||||||
"raw": comment,
|
"raw": comment,
|
||||||
@ -144,7 +157,11 @@ class BitbucketProvider:
|
|||||||
|
|
||||||
def publish_inline_comments(self, comments: list[dict]):
|
def publish_inline_comments(self, comments: list[dict]):
|
||||||
for comment in comments:
|
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):
|
def get_title(self):
|
||||||
return self.pr.title
|
return self.pr.title
|
||||||
|
@ -71,7 +71,7 @@ class PRDescription:
|
|||||||
if get_settings().config.publish_output:
|
if get_settings().config.publish_output:
|
||||||
logging.info('Pushing answer...')
|
logging.info('Pushing answer...')
|
||||||
if get_settings().pr_description.publish_description_as_comment:
|
if get_settings().pr_description.publish_description_as_comment:
|
||||||
self.git_provider.publish_comment(markdown_text)
|
self.git_provider.publish_comment(pr_body)
|
||||||
else:
|
else:
|
||||||
self.git_provider.publish_description(pr_title, pr_body)
|
self.git_provider.publish_description(pr_title, pr_body)
|
||||||
if self.git_provider.is_supported("get_labels"):
|
if self.git_provider.is_supported("get_labels"):
|
||||||
|
@ -266,7 +266,10 @@ class PRReviewer:
|
|||||||
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)
|
||||||
|
|
||||||
if comments:
|
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]:
|
def _get_user_answers(self) -> Tuple[str, str]:
|
||||||
"""
|
"""
|
||||||
|
@ -46,7 +46,7 @@ class PRUpdateChangelog:
|
|||||||
get_settings().pr_update_changelog_prompt.user)
|
get_settings().pr_update_changelog_prompt.user)
|
||||||
|
|
||||||
async def run(self):
|
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...')
|
logging.info('Updating the changelog...')
|
||||||
if get_settings().config.publish_output:
|
if get_settings().config.publish_output:
|
||||||
|
Reference in New Issue
Block a user