Skip to content

Commit c1c8957

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents d836430 + 42cd85b commit c1c8957

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

pr_agent/git_providers/github_provider.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, pr_url: Optional[str] = None, incremental=IncrementalPR(False
3838
self.set_pr(pr_url)
3939
self.pr_commits = list(self.pr.get_commits())
4040
if self.incremental.is_incremental:
41-
self.file_set = dict()
41+
self.unreviewed_files_set = dict()
4242
self.get_incremental_commits()
4343
self.last_commit_id = self.pr_commits[-1]
4444
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):
6868
if commit.commit.message.startswith(f"Merge branch '{self._get_repo().default_branch}'"):
6969
get_logger().info(f"Skipping merge commit {commit.commit.message}")
7070
continue
71-
self.file_set.update({file.filename: file for file in commit.files})
71+
self.unreviewed_files_set.update({file.filename: file for file in commit.files})
7272
else:
73-
raise ValueError("No previous review found")
73+
get_logger().info("No previous review found, will review the entire PR")
74+
self.incremental.is_incremental = False
7475

7576
def get_commit_range(self):
7677
last_review_time = self.previous_review.created_at
@@ -99,8 +100,8 @@ def get_previous_review(self, *, full: bool, incremental: bool):
99100
return self.comments[index]
100101

101102
def get_files(self):
102-
if self.incremental.is_incremental and self.file_set:
103-
return self.file_set.values()
103+
if self.incremental.is_incremental and self.unreviewed_files_set:
104+
return self.unreviewed_files_set.values()
104105
try:
105106
git_files = context.get("git_files", None)
106107
if git_files:
@@ -146,10 +147,10 @@ def get_diff_files(self) -> list[FilePatchInfo]:
146147
new_file_content_str = self._get_pr_file_content(file, self.pr.head.sha) # communication with GitHub
147148
patch = file.patch
148149

149-
if self.incremental.is_incremental and self.file_set:
150+
if self.incremental.is_incremental and self.unreviewed_files_set:
150151
original_file_content_str = self._get_pr_file_content(file, self.incremental.last_seen_commit_sha)
151152
patch = load_large_diff(file.filename, new_file_content_str, original_file_content_str)
152-
self.file_set[file.filename] = patch
153+
self.unreviewed_files_set[file.filename] = patch
153154
else:
154155
original_file_content_str = self._get_pr_file_content(file, self.pr.base.sha)
155156
if not patch:

pr_agent/tools/pr_reviewer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async def run(self) -> None:
108108
'config': dict(get_settings().config)}
109109
get_logger().debug("Relevant configs", artifacts=relevant_configs)
110110

111-
if self.incremental.is_incremental and hasattr(self.git_provider, "file_set") and not self.git_provider.file_set:
111+
if self.incremental.is_incremental and hasattr(self.git_provider, "unreviewed_files_set") and not self.git_provider.unreviewed_files_set:
112112
get_logger().info(f"Incremental review is enabled for {self.pr_url} but there are no new files")
113113
previous_review_url = ""
114114
if hasattr(self.git_provider, "previous_review"):
@@ -324,6 +324,10 @@ def _can_run_incremental_review(self) -> bool:
324324
if self.is_auto and not self.incremental.first_new_commit_sha:
325325
get_logger().info(f"Incremental review is enabled for {self.pr_url} but there are no new commits")
326326
return False
327+
328+
if not hasattr(self.git_provider, "get_incremental_commits"):
329+
get_logger().info(f"Incremental review is not supported for {get_settings().config.git_provider}")
330+
return False
327331
# checking if there are enough commits to start the review
328332
num_new_commits = len(self.incremental.commits_range)
329333
num_commits_threshold = get_settings().pr_reviewer.minimal_commits_for_incremental_review

0 commit comments

Comments
 (0)