Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
mrT23 committed Mar 11, 2024
2 parents d836430 + 42cd85b commit c1c8957
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 8 additions & 7 deletions pr_agent/git_providers/github_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion pr_agent/tools/pr_reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c1c8957

Please sign in to comment.