diff --git a/Usage.md b/Usage.md index ac077528..3253985d 100644 --- a/Usage.md +++ b/Usage.md @@ -211,8 +211,8 @@ The configuration parameter `push_commands` defines the list of tools that will [github_app] handle_push_trigger = true push_commands = [ - "/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true", - "/review --pr_reviewer.num_code_suggestions=0", + "/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true --pr_description.final_update_message=false", + "/review --pr_reviewer.num_code_suggestions=0 --pr_reviewer.final_update_message=false", ] ``` This means that when new code is pushed to the PR, the PR-Agent will run the `describe` and `review` tools, with the specified parameters. diff --git a/docs/REVIEW.md b/docs/REVIEW.md index 39783c48..37af9748 100644 --- a/docs/REVIEW.md +++ b/docs/REVIEW.md @@ -38,6 +38,8 @@ To edit [configurations](./../pr_agent/settings/configuration.toml#L19) related - `inline_code_comments`: if set to true, the tool will publish the code suggestions as comments on the code diff. Default is false. - `persistent_comment`: if set to true, the review comment will be persistent, meaning that every new review request will edit the previous one. Default is true. - `extra_instructions`: Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ...". +- `final_update_message`: if set to true, it will add a comment message after finishing calling `/review`, if a message already exits. Default is true. + #### Enable\\disable features - `require_focused_review`: if set to true, the tool will add a section - 'is the PR a focused one'. Default is false. - `require_score_review`: if set to true, the tool will add a section that scores the PR. Default is false. diff --git a/pr_agent/git_providers/bitbucket_provider.py b/pr_agent/git_providers/bitbucket_provider.py index 62ea46c7..103ea5cd 100644 --- a/pr_agent/git_providers/bitbucket_provider.py +++ b/pr_agent/git_providers/bitbucket_provider.py @@ -160,7 +160,11 @@ class BitbucketProvider(GitProvider): def get_comment_url(self, comment): return comment.data['links']['html']['href'] - def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: bool = True, name='review'): + def publish_persistent_comment(self, pr_comment: str, + initial_header: str, + update_header: bool = True, + name='review', + final_update_message=True): try: for comment in self.pr.comments(): body = comment.raw @@ -175,8 +179,9 @@ class BitbucketProvider(GitProvider): get_logger().info(f"Persistent mode - updating comment {comment_url} to latest {name} message") d = {"content": {"raw": pr_comment_updated}} response = comment._update_data(comment.put(None, data=d)) - self.publish_comment( - f"**[Persistent {name}]({comment_url})** updated to latest commit {latest_commit_url}") + if final_update_message: + self.publish_comment( + f"**[Persistent {name}]({comment_url})** updated to latest commit {latest_commit_url}") return except Exception as e: get_logger().exception(f"Failed to update persistent review, error: {e}") diff --git a/pr_agent/git_providers/git_provider.py b/pr_agent/git_providers/git_provider.py index 3ef86709..e8a78b4b 100644 --- a/pr_agent/git_providers/git_provider.py +++ b/pr_agent/git_providers/git_provider.py @@ -124,7 +124,11 @@ class GitProvider(ABC): def publish_comment(self, pr_comment: str, is_temporary: bool = False): pass - def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: bool, name='review'): + def publish_persistent_comment(self, pr_comment: str, + initial_header: str, + update_header: bool = True, + name='review', + final_update_message=True): self.publish_comment(pr_comment) @abstractmethod diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index c1bff0dc..22117af6 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -197,7 +197,11 @@ class GithubProvider(GitProvider): def get_comment_url(self, comment) -> str: return comment.html_url - def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: bool = True, name='review'): + def publish_persistent_comment(self, pr_comment: str, + initial_header: str, + update_header: bool = True, + name='review', + final_update_message=True): prev_comments = list(self.pr.get_issue_comments()) for comment in prev_comments: body = comment.body @@ -211,8 +215,9 @@ class GithubProvider(GitProvider): pr_comment_updated = pr_comment get_logger().info(f"Persistent mode- updating comment {comment_url} to latest review message") response = comment.edit(pr_comment_updated) - self.publish_comment( - f"**[Persistent {name}]({comment_url})** updated to latest commit {latest_commit_url}") + if final_update_message: + self.publish_comment( + f"**[Persistent {name}]({comment_url})** updated to latest commit {latest_commit_url}") return self.publish_comment(pr_comment) diff --git a/pr_agent/git_providers/gitlab_provider.py b/pr_agent/git_providers/gitlab_provider.py index d0e8d575..8d2e97c8 100644 --- a/pr_agent/git_providers/gitlab_provider.py +++ b/pr_agent/git_providers/gitlab_provider.py @@ -151,7 +151,11 @@ class GitLabProvider(GitProvider): def get_comment_url(self, comment): return f"{self.mr.web_url}#note_{comment.id}" - def publish_persistent_comment(self, pr_comment: str, initial_header: str, update_header: bool = True, name='review'): + def publish_persistent_comment(self, pr_comment: str, + initial_header: str, + update_header: bool = True, + name='review', + final_update_message=True): try: for comment in self.mr.notes.list(get_all=True)[::-1]: if comment.body.startswith(initial_header): @@ -164,8 +168,9 @@ class GitLabProvider(GitProvider): pr_comment_updated = pr_comment get_logger().info(f"Persistent mode - updating comment {comment_url} to latest {name} message") response = self.mr.notes.update(comment.id, {'body': pr_comment_updated}) - self.publish_comment( - f"**[Persistent {name}]({comment_url})** updated to latest commit {latest_commit_url}") + if final_update_message: + self.publish_comment( + f"**[Persistent {name}]({comment_url})** updated to latest commit {latest_commit_url}") return except Exception as e: get_logger().exception(f"Failed to update persistent review, error: {e}") diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 0f2dab3c..243b12ca 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -36,6 +36,7 @@ ask_and_reflect=false #automatic_review=true persistent_comment=true extra_instructions = "" +final_update_message = true # review labels enable_review_labels_security=true enable_review_labels_effort=true diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index f73e20f2..39eb904e 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -121,9 +121,11 @@ class PRReviewer: if get_settings().config.publish_output: # publish the review if get_settings().pr_reviewer.persistent_comment and not self.incremental.is_incremental: + final_update_message = get_settings().pr_reviewer.final_update_message self.git_provider.publish_persistent_comment(pr_review, initial_header="## PR Review", - update_header=True) + update_header=True, + final_update_message=final_update_message, ) else: self.git_provider.publish_comment(pr_review)