Skip to content

Commit

Permalink
skip incremental review if no file changed since last review
Browse files Browse the repository at this point in the history
  • Loading branch information
hussam789 committed Mar 10, 2024
1 parent ff2346e commit 003c490
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pr_agent/git_providers/github_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +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.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 All @@ -62,7 +63,7 @@ def get_incremental_commits(self):
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}")
Expand Down
13 changes: 9 additions & 4 deletions pr_agent/tools/pr_reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ async def run(self) -> None:
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")
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\nNo 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)

Expand Down Expand Up @@ -212,11 +221,7 @@ def _prepare_pr_review(self) -> str:
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})_"

markdown_text = convert_to_markdown(data, self.git_provider.is_supported("gfm_markdown"),
incremental_review_markdown_text)
Expand Down

0 comments on commit 003c490

Please sign in to comment.