Skip to content

Commit 4041c38

Browse files
fix(azure-devops): gate fallback returns False; treat fetch errors as fallback
- _can_run_incremental_review() now returns False (not True) when incremental.commits_range is None, satisfying compliance ID 6 and the test_can_run_returns_false_when_commits_range_none unit test. - PRReviewer.run() distinguishes "gate disabled incremental" (fall through to full review) from "gate said skip" (return early), so the previous fallback log line now produces an actual full review. - _get_incremental_commits() tracks had_errors so that transient Azure get_changes failures disable incremental and fall back to a full review instead of being silently skipped as "no new files". Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 63b58a6 commit 4041c38

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

pr_agent/git_providers/azuredevops_provider.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def _get_incremental_commits(self):
216216

217217
self.incremental.commits_range = self._get_commit_range()
218218
candidate_paths = []
219+
had_errors = False
219220
for commit in self.incremental.commits_range:
220221
if len(commit.parents) > 1:
221222
get_logger().info(f"Skipping merge commit {commit.sha}")
@@ -227,6 +228,7 @@ def _get_incremental_commits(self):
227228
commit_id=commit.commit_id,
228229
)
229230
except Exception as e:
231+
had_errors = True
230232
get_logger().warning(f"Failed to fetch changes for {commit.commit_id}: {e}")
231233
continue
232234
for change in (getattr(changes_obj, "changes", None) or []):
@@ -247,6 +249,11 @@ def _get_incremental_commits(self):
247249
for path in filtered:
248250
if is_valid_file(path):
249251
self.unreviewed_files_set[path] = path
252+
elif had_errors and self.incremental.commits_range:
253+
get_logger().warning(
254+
"Failed to fetch changes for incremental commits; falling back to full review."
255+
)
256+
self.incremental.is_incremental = False
250257

251258
def _get_commit_range(self):
252259
last_review_time = _to_naive_utc(getattr(self.previous_review, "created_at", None))

pr_agent/tools/pr_reviewer.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ async def run(self) -> None:
123123
get_logger().info(f"PR has no files: {self.pr_url}, skipping review")
124124
return None
125125

126-
if self.incremental.is_incremental and not self._can_run_incremental_review():
127-
return None
126+
if self.incremental.is_incremental:
127+
can_run = self._can_run_incremental_review()
128+
# If the gate disabled incremental (e.g., commits_range is None), fall through to full review.
129+
if not can_run and self.incremental.is_incremental:
130+
return None
128131

129132
# if isinstance(self.args, list) and self.args and self.args[0] == 'auto_approve':
130133
# get_logger().info(f'Auto approve flow PR: {self.pr_url} ...')
@@ -343,7 +346,7 @@ def _can_run_incremental_review(self) -> bool:
343346
f"falling back to full review."
344347
)
345348
self.incremental.is_incremental = False
346-
return True
349+
return False
347350
# checking if there are enough commits to start the review
348351
num_new_commits = len(self.incremental.commits_range)
349352
num_commits_threshold = get_settings().pr_reviewer.minimal_commits_for_incremental_review

0 commit comments

Comments
 (0)