diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 6932d7bd..dede9850 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -60,7 +60,7 @@ def unique_strings(input_list: List[str]) -> List[str]: return unique_list -def convert_to_markdown(output_data: dict, gfm_supported: bool = True) -> str: +def convert_to_markdown(output_data: dict, gfm_supported: bool = True, incremental_review=None) -> str: """ Convert a dictionary of data into markdown format. Args: @@ -80,7 +80,11 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool = True) -> str: "Estimated effort to review [1-5]": "⏱️", } markdown_text = "" - markdown_text += f"## PR Review\n\n" + if not incremental_review: + markdown_text += f"## PR Review\n\n" + else: + markdown_text += f"## Incremental PR Review\n\n" + markdown_text += f"⏮️ Review for commits since previous PR-Agent review {incremental_review}.\n\n" if gfm_supported: markdown_text += "\n\n" # markdown_text += """""" diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index fab4fd5b..92983baf 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -38,6 +38,7 @@ class GithubProvider(GitProvider): self.set_pr(pr_url) self.pr_commits = list(self.pr.get_commits()) if self.incremental.is_incremental: + self.file_set = dict() self.get_incremental_commits() self.last_commit_id = self.pr_commits[-1] self.pr_url = self.get_pr_url() # pr_url for github actions can be as api.github.com, so we need to get the url from the pr object @@ -62,7 +63,7 @@ class GithubProvider(GitProvider): if self.previous_review: self.incremental.commits_range = self.get_commit_range() # Get all files changed during the commit range - self.file_set = dict() + for commit in self.incremental.commits_range: if commit.commit.message.startswith(f"Merge branch '{self._get_repo().default_branch}'"): get_logger().info(f"Skipping merge commit {commit.commit.message}") diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index 5fc82fda..4a9d5ca1 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -107,6 +107,17 @@ class PRReviewer: relevant_configs = {'pr_reviewer': dict(get_settings().pr_reviewer), 'config': dict(get_settings().config)} get_logger().debug("Relevant configs", artifacts=relevant_configs) + + if self.incremental.is_incremental and hasattr(self.git_provider, "file_set") and not self.git_provider.file_set: + get_logger().info(f"Incremental review is enabled for {self.pr_url} but there are no new files") + previous_review_url = "" + if hasattr(self.git_provider, "previous_review"): + previous_review_url = self.git_provider.previous_review.html_url + if get_settings().config.publish_output: + self.git_provider.publish_comment(f"Incremental Review Skipped\n" + f"No files were changed since the [previous PR Review]({previous_review_url})", is_temporary=True) + return None + if get_settings().config.publish_output: self.git_provider.publish_comment("Preparing review...", is_temporary=True) @@ -207,21 +218,15 @@ class PRReviewer: pass + incremental_review_markdown_text = None # Add incremental review section if self.incremental.is_incremental: last_commit_url = f"{self.git_provider.get_pr_url()}/commits/" \ f"{self.git_provider.incremental.first_new_commit_sha}" - last_commit_msg = self.incremental.commits_range[0].commit.message if self.incremental.commits_range else "" incremental_review_markdown_text = f"Starting from commit {last_commit_url}" - if last_commit_msg: - replacement = last_commit_msg.splitlines(keepends=False)[0].replace('_', r'\_') - incremental_review_markdown_text += f" \n_({replacement})_" - data = OrderedDict(data) - data.update({'Incremental PR Review': { - "⏮️ Review for commits since previous PR-Agent review": incremental_review_markdown_text}}) - data.move_to_end('Incremental PR Review', last=False) - markdown_text = convert_to_markdown(data, self.git_provider.is_supported("gfm_markdown")) + markdown_text = convert_to_markdown(data, self.git_provider.is_supported("gfm_markdown"), + incremental_review_markdown_text) # Add help text if gfm_markdown is supported if self.git_provider.is_supported("gfm_markdown") and get_settings().pr_reviewer.enable_help_text:
      Feedback