diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index 92983baf4..2f928f82e 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -38,7 +38,7 @@ def __init__(self, pr_url: Optional[str] = None, incremental=IncrementalPR(False self.set_pr(pr_url) self.pr_commits = list(self.pr.get_commits()) if self.incremental.is_incremental: - self.file_set = dict() + self.unreviewed_files_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 @@ -68,9 +68,10 @@ def get_incremental_commits(self): if commit.commit.message.startswith(f"Merge branch '{self._get_repo().default_branch}'"): get_logger().info(f"Skipping merge commit {commit.commit.message}") continue - self.file_set.update({file.filename: file for file in commit.files}) + self.unreviewed_files_set.update({file.filename: file for file in commit.files}) else: - raise ValueError("No previous review found") + get_logger().info("No previous review found, will review the entire PR") + self.incremental.is_incremental = False def get_commit_range(self): last_review_time = self.previous_review.created_at @@ -99,8 +100,8 @@ def get_previous_review(self, *, full: bool, incremental: bool): return self.comments[index] def get_files(self): - if self.incremental.is_incremental and self.file_set: - return self.file_set.values() + if self.incremental.is_incremental and self.unreviewed_files_set: + return self.unreviewed_files_set.values() try: git_files = context.get("git_files", None) if git_files: @@ -146,10 +147,10 @@ def get_diff_files(self) -> list[FilePatchInfo]: new_file_content_str = self._get_pr_file_content(file, self.pr.head.sha) # communication with GitHub patch = file.patch - if self.incremental.is_incremental and self.file_set: + if self.incremental.is_incremental and self.unreviewed_files_set: original_file_content_str = self._get_pr_file_content(file, self.incremental.last_seen_commit_sha) patch = load_large_diff(file.filename, new_file_content_str, original_file_content_str) - self.file_set[file.filename] = patch + self.unreviewed_files_set[file.filename] = patch else: original_file_content_str = self._get_pr_file_content(file, self.pr.base.sha) if not patch: diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index ff0c65828..854e351c6 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -108,7 +108,7 @@ async def run(self) -> None: '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: + if self.incremental.is_incremental and hasattr(self.git_provider, "unreviewed_files_set") and not self.git_provider.unreviewed_files_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"): @@ -324,6 +324,10 @@ def _can_run_incremental_review(self) -> bool: if self.is_auto and not self.incremental.first_new_commit_sha: get_logger().info(f"Incremental review is enabled for {self.pr_url} but there are no new commits") return False + + if not hasattr(self.git_provider, "get_incremental_commits"): + get_logger().info(f"Incremental review is not supported for {get_settings().config.git_provider}") + return False # checking if there are enough commits to start the review num_new_commits = len(self.incremental.commits_range) num_commits_threshold = get_settings().pr_reviewer.minimal_commits_for_incremental_review