From 51e1278cd73b8396daf7e2d44a5191d5236aec58 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 28 Nov 2023 18:29:35 +0200 Subject: [PATCH] feat: Enhance inline comment publishing in Bitbucket provider and add logging for no suggestions in pr_code_suggestions.py --- pr_agent/git_providers/bitbucket_provider.py | 10 +++++++++- pr_agent/tools/pr_code_suggestions.py | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pr_agent/git_providers/bitbucket_provider.py b/pr_agent/git_providers/bitbucket_provider.py index d13a708c..386577a2 100644 --- a/pr_agent/git_providers/bitbucket_provider.py +++ b/pr_agent/git_providers/bitbucket_provider.py @@ -254,7 +254,15 @@ class BitbucketProvider(GitProvider): def publish_inline_comments(self, comments: list[dict]): for comment in comments: - self.publish_inline_comment(comment['body'], comment['position'], comment['path']) + if 'position' in comment: + self.publish_inline_comment(comment['body'], comment['position'], comment['path']) + elif 'start_line' in comment: # multi-line comment + # note that bitbucket does not seem to support range - only a comment on a single line - https://community.developer.atlassian.com/t/api-post-endpoint-for-inline-pull-request-comments/60452 + self.publish_inline_comment(comment['body'], comment['start_line'], comment['path']) + elif 'line' in comment: # single-line comment + self.publish_inline_comment(comment['body'], comment['line'], comment['path']) + else: + get_logger().error(f"Could not publish inline comment {comment}") def get_title(self): return self.pr.title diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index a65659d3..f095d94a 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -119,6 +119,7 @@ class PRCodeSuggestions: code_suggestions = [] if not data['Code suggestions']: + get_logger().info('No suggestions found to improve this PR.') return self.git_provider.publish_comment('No suggestions found to improve this PR.') for d in data['Code suggestions']: